-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
218 lines (218 loc) · 17.2 KB
/
atom.xml
File metadata and controls
218 lines (218 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://duxiaodou.github.io</id>
<title>杜小豆的编程小道</title>
<updated>2019-06-13T10:01:27.601Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="https://duxiaodou.github.io"/>
<link rel="self" href="https://duxiaodou.github.io/atom.xml"/>
<subtitle>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;生命,宇宙,以及一切的答案<br/>
Answer to Life, the Universe, and Everything</subtitle>
<logo>https://duxiaodou.github.io/images/avatar.png</logo>
<icon>https://duxiaodou.github.io/favicon.ico</icon>
<rights>All rights reserved 2019, 杜小豆的编程小道</rights>
<entry>
<title type="html"><![CDATA[常见数据类型的结构图(ASCII)]]></title>
<id>https://duxiaodou.github.io/post/chang-jian-shu-ju-jie-gou-de-ascii-tu</id>
<link href="https://duxiaodou.github.io/post/chang-jian-shu-ju-jie-gou-de-ascii-tu">
</link>
<updated>2019-06-13T09:56:35.000Z</updated>
<content type="html"><![CDATA[<h1 id="链表">链表</h1>
<h2 id="单链表">单链表</h2>
<pre><code> +--------------+---+
| data | * |
+--------------+-┼-+
|
|
|
+--------V-----+---+
| data | * |
+--------------+-┼-+
|
|
|
+--------V-----+---+
| data | Ø |
+--------------+---+
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Nginx高级指南]]></title>
<id>https://duxiaodou.github.io/post/nginx-gao-ji-zhi-nan</id>
<link href="https://duxiaodou.github.io/post/nginx-gao-ji-zhi-nan">
</link>
<updated>2019-06-05T07:19:59.000Z</updated>
<summary type="html"><![CDATA[<p>Nginx高级指南</p>
]]></summary>
<content type="html"><![CDATA[<p>Nginx高级指南</p>
<!-- more -->
<h1 id="模块">模块</h1>
<p>Nginx的模块扩展了Nginx的能力,其模块分为3种:</p>
<ul>
<li>Nginx开发的模块</li>
<li>经由Nginx认证的社区开发模块</li>
<li>社区开发的模块</li>
</ul>
<h2 id="安装模块">安装模块</h2>
<p>通过系统的包管理器或者按照安装指南安装即可。</p>
<h2 id="启用模块">启用模块</h2>
<p>在 <em>nginx.conf</em> 配置文件的main上下文中,使用 <em>load_module modules/<模块名>.so;</em> 加载指令即可。</p>
<h1 id="配置">配置</h1>
<h2 id="测试配置文件">测试配置文件</h2>
<p><code>nginx -t</code></p>
<h2 id="特定功能的配置文件">特定功能的配置文件</h2>
<p>为了使得配置易于维护,可以将特定功能的配置文件存放于 <em>/etc/nginx/conf.d</em> 目录,然后在<em>nginx.conf</em> 中用指令<em>include</em> 来引用这些配置的内容。</p>
<h2 id="上下文">上下文</h2>
<p>顶级指令(<strong>上下文</strong>)将不同类型的指令组合在一起:</p>
<ul>
<li>events:通用连接处理</li>
<li>http: HTTP流量</li>
<li>mail: 邮件流量</li>
<li>stream: TCP和UDP流量</li>
</ul>
<h2 id="虚拟服务器">虚拟服务器</h2>
<p>在每一个流量处理的上下文中,你可以包含一个或多个<em>server</em>块来定义<strong>虚拟服务器</strong>,来控制处理请求。<strong>server</strong>中可以包含的指令因你的流量类型而有所不同。</p>
<p>对于http流量,每个<em>server</em>指令控制特定域名或IP的资源请求的处理,<em>server</em>上下文可包含一个或多个<em>location</em>来定义如何处理指定的URI集。</p>
<p>对于mail和tcp/udp流量(邮件和流上下文),服务器指令分别控制到达特定TCP端口或UNIX套接字的流量的处理。</p>
<h2 id="继承">继承</h2>
<p>子上下文继承父上下文中包含的指令设置,可以通过将指令包含在子上下文中重写从父上下文继承的设置。</p>
<h1 id="负载均衡">负载均衡</h1>
<h2 id="将http流量代理到一组服务">将HTTP流量代理到一组服务</h2>
<p>首先用指令 <em>upstream</em> 定义组,该指令位于http上下文内。</p>
<p>组中的服务器用指令 <em>server</em> 定义。</p>
<p>要将请求传递给服务器组,为这些协议指定 <em>proxy_pass</em> 或 <em>fastcgi_pass</em> 、<em>memcached_pass</em>、<em>scgi_pass</em>、<em>uwsgi_pass</em>指令。</p>
<p><em>upstream</em> 块没有指定负载均衡算法,所以Nginx使用默认算法循环调度。</p>
<h2 id="选择负载均衡算法">选择负载均衡算法</h2>
<p>Nginx支持4种负载均衡算法,Nginx Plus增添了2种。</p>
<p>1.Round Robin(循环):请求在服务器之间均匀分布,可指定服务器权重。该算法默认在未指定任何负载均衡算法时,默认启用。</p>
<p>2.Least Connections(最少连接):向活动连接数最少的服务器发起请求,使用<em>least_conn</em>指令,同样考虑服务器权重。</p>
<p>3.IP Hash(IP哈希):请求发送到哪个服务器是根据客户端的IP地址确定的,使用<em>ip_hash</em>指令,在这种情况下,要么使用IPV4的前3个8位字节,要么使用整个IPV6地址来计算哈希值。这个负载均衡算法确保来自同一地址的请求到达同一服务器,除非该服务器不可用。</p>
<p>如果其中一台服务器要暂时从负载均衡的循环中删除,它可以用down参数进行标记,以便保留客户端IP地址的当前哈希。发送给该服务器的请求会自动发送到组中的下一台服务器。</p>
<p>4.Generic Hash(通用哈希):请求发送到哪个服务器由用户定义的键决定,键可以是文本字符串、变量或它们的组合,使用<em>hash</em>指令。例如,键可以是成对的源IP地址和端口,或者是本例中的URI。</p>
<p>可选参数<em>consistent</em>支持ketama 一致哈希负载均衡,基于用户定义的哈希键值,请求均匀分布在所有upsteam服务器上。如果将upsteam服务器添加或从upsteam组删除,则只重新映射几个键,从而在负载平衡缓存服务器或其他累积状态的应用程序的情况下,最大限度地减少缓存未命中。</p>
<p>5.Least Time(最短时间)(Nginx Plus可用):使用<em>least_time</em>指令,对于每个请求,Nginx选择平均延迟最低和活动连接数最少的服务器,其中最低平均延迟是根据<em>last_time</em>指令的下列参数计算的:</p>
<ul>
<li>header:从服务器接收第一个字节的时间</li>
<li>last_byte:从服务器接收完整响应的时间</li>
<li>last_byte inflight:考虑到不完整到请求,从服务器接收完整响应的时间</li>
</ul>
<p>6.Random(随机):使用<em>random</em>指令,每个请求会被传递给一个随机选择的服务器。如果指定了2个参数,首先,Nginx考虑到服务器权重,随机选择2台服务器,然后使用指定的方法选择其中一台服务器:</p>
<ul>
<li>least_conn:活动连接的最少数量</li>
<li>least_time=header(Nginx Plus):从服务器接收响应报头的最短平均时间 ($upstream_header_time)</li>
<li>least_time=last_byte(Nginx Plus): 从服务器接收完整响应的最小平均时间 ($upstream_response_time)</li>
</ul>
<h2 id="服务器权重">服务器权重</h2>
<p>默认情况下,Nginx使用循环方法根据服务器的权重在组中的服务器之间分配请求。<em>server</em>指令的<em>weight</em>参数设置服务器的权重,其值默认为1。</p>
<p><em>backup</em>服务器不会接收请求,除非另外的服务器都不可用。使用服务器权重,请求按照权重的比例分配给服务器。</p>
<h2 id="服务器慢启动">服务器慢启动</h2>
<p>服务器慢启动可以防止最近恢复的服务器被连接压垮,这可能会超时并导致服务器再次被标记为故障。</p>
<p>在Nginx Plus中,慢启动允许upstream服务器在恢复或可用后将其权重从0逐渐恢复到它的正常值,这可以通过服务器指令的<em>slow_start</em>参数来完成,Nginx将在指定时间后将服务器连接数增加到最大值。</p>
<p>注意,如果一个组中只有一台服务器,服务器指令的<em>max_fails</em>、<em>fail_timeout</em>、<em>slow_start</em>参数将被忽略,并且该服务器永远不会被视为不可用。</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Nginx入门指南]]></title>
<id>https://duxiaodou.github.io/post/nginx-ru-men-zhi-nan</id>
<link href="https://duxiaodou.github.io/post/nginx-ru-men-zhi-nan">
</link>
<updated>2019-06-05T06:52:06.000Z</updated>
<summary type="html"><![CDATA[<p>Nginx入门指南</p>
]]></summary>
<content type="html"><![CDATA[<p>Nginx入门指南</p>
<!-- more -->
<p><a href="https://nginx.org/en/docs/beginners_guide.html">Nginx - Beginner’s Guide</a></p>
<h1 id="基础">基础</h1>
<p>Nginx的配置文件是 <em>nginx.conf</em>,默认位于 <em>/usr/local/nginx.conf</em>、<em>/etc/nginx</em>或者 <em>/usr/local/etc/nginx</em>。</p>
<h2 id="启动-控制">启动 && 控制</h2>
<p>通过执行nginx来启动,启动后通过<code>nginx -s 信号</code>来控制。信号包括以下:</p>
<ul>
<li>stop 快速停止</li>
<li>quit 优雅停止(等待工作进程完成当前请求后再停止)</li>
<li>reload 重现加载配置文件(更改nginx的配置后不会立即生效,需要使用reload命令或者等待重新运行nginx)</li>
<li>reopen 重新打开日志文件</li>
</ul>
<p>应用新的配置信息时,主进程检查配置的有效性,然后并尝试应用。完成后,主进程允许新的工作进程,并且发送消息给旧的工作进程让其关闭。否则,主进程将回滚改动并依据旧的配置进行工作。</p>
<p>旧的工作进程收到关闭命令后,不再接受新的连接,并继续服务当前请求,待所有请求都服务完后,旧的工作进程退出。</p>
<p>也可通过<strong>kill</strong>将信号发送给<strong>Nginx</strong>进程。</p>
<h2 id="配置文件结构">配置文件结构</h2>
<p><strong>Nginx</strong>由配置文件中指定的指令控制的模块组成,指令分为<strong>简单指令</strong>和<strong>块指令</strong>。简单指令由
<code>名称 参数;</code>构成,块指令的的结构与简单指令类似,但是它以<code>{}</code>结束。</p>
<p>如果一个<strong>块指令</strong>在大括号中可以有其他指令,那么它被称为<strong>上下文</strong>。</p>
<p>没有放置在任何上下文之中的指令被认为是放在<strong>main</strong>上下文中,<strong>events</strong>和<strong>http</strong>指令在<strong>main</strong>上下文中,<strong>server</strong>在<strong>http</strong>中,<strong>location</strong>在<strong>server</strong>中。</p>
<p><strong>#</strong> 之后的内容即为注释。</p>
<h2 id="服务静态内容">服务静态内容</h2>
<p>配置文件可以包含多个<strong>server</strong>块,不同的<strong>server</strong>通过监听的端口和<strong>sever</strong>名称来区分。一旦<strong>Nginx</strong>决定了哪一个<strong>server</strong>处理请求,它根据<strong>server</strong>内的<strong>location</strong>指令参数测试<strong>uri</strong>。</p>
<p>对于匹配的请求,<strong>uri</strong>被添加到根指令中指定的路径。如果有多个匹配的<strong>location</strong>块,优先选择前缀最长的那个。</p>
<h2 id="日志">日志</h2>
<p><strong>Nginx</strong>的日志文件默认位于 <em>/usr/local/nginx/logs</em> 或者 <em>/var/log/nginx</em>,包含了<em>access.log</em>和<em>error.log</em>。</p>
<h2 id="设置简单的代理服务器">设置简单的代理服务器</h2>
<p>代理服务器,这意味着服务器接收请求,将请求传递给代理服务器,从请求中检索响应,并将其发送给客户端。</p>
<p>代理指令是<strong>proxy_pass</strong>。</p>
<p><strong>Nginx</strong>选择一个<strong>location</strong>为请求服务时,首先检查指定前缀的l<strong>ocation</strong>指令,并优先选择前缀最长的<strong>location</strong>,之后再检测正则表达式。如果匹配到了正则表达式,<strong>Nginx</strong>选择它的<strong>location</strong>,否则,选择之前记住的<strong>location</strong>。</p>
<h2 id="设置fastcgi代理">设置FastCGI代理</h2>
<p><strong>Nginx</strong>可用于将请求路由到<strong>FastCGI</strong>服务器。</p>
<p><strong>FastCGI</strong>指令是<strong>fastcgi_pass</strong>,<strong>fastcgi_param</strong>指令用于设置传递给<strong>FastCGI</strong>服务器的参数。</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[一个开发者的Mac工具箱]]></title>
<id>https://duxiaodou.github.io/post/developer-mac-app</id>
<link href="https://duxiaodou.github.io/post/developer-mac-app">
</link>
<updated>2019-05-31T09:40:08.000Z</updated>
<summary type="html"><![CDATA[<p>Mac应用推荐</p>
]]></summary>
<content type="html"><![CDATA[<p>Mac应用推荐</p>
<!-- more -->
<h1 id="软件管理">软件管理</h1>
<h2 id="homebrew">Homebrew</h2>
<p><img src="https://duxiaodou.github.io/post-images/1559296171286.png" alt=""></p>
<blockquote>
<p>Homebrew — The missing package manager for macOS</p>
</blockquote>
<p><strong>Homebrew</strong>是命令行版本的软件管家,通过几个简单的命令,你就可以轻松完成软件的搜索、安装、升级以及卸载。</p>
<h3 id="安装homebrew">安装Homebrew</h3>
<p><code>/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code></p>
<h3 id="使用">使用</h3>
<p><strong>Homebrew</strong>针对软件的用法是:<code>brew 动作 [软件名]</code></p>
<p>其中<strong>动作</strong>包含了<strong>搜索</strong>(search) 、<strong>查看</strong>(info) 、<strong>安装</strong>(install / tap) 、<strong>更新</strong>(upgrade) 、<strong>卸载</strong>(uninstall / remove / rm) 、<strong>列举</strong>(list) 。</p>
<p><strong>Homebrew</strong>中的软件分为<strong>普通软件</strong>与<strong>cask软件</strong>,<strong>cask软件</strong>通常指<strong>macOS</strong>上的app、字体、插件或者其他不开源的软件。<strong>普通软件</strong>使用普通的<code>brew</code>命令即可,<strong>cask软件</strong>则需要使用<code>brew cask</code> 命令。</p>
<h4 id="搜索">搜索</h4>
<p><code>brew search 软件名</code></p>
<p>搜索结果中的<strong>Formulae</strong>部分为<strong>普通软件</strong>,<strong>Casks</strong>部分为<strong>cask软件</strong>。</p>
<p>已安装的软件名称后面会有<code>✔</code>标识。</p>
<h4 id="查看">查看</h4>
<p><code>brew info 软件名</code></p>
<p>查看软件信息时,会优先选择<strong>普通软件</strong>,若<strong>普通软件</strong>不存在,则会自动选择<strong>cask软件</strong>。</p>
<p>也可以通过<code>brew cask info 软件名</code>命令显式查看<strong>cask软件</strong>的信息。</p>
<h4 id="安装">安装</h4>
<p><code>brew install 软件名</code> 安装<strong>普通软件</strong>。</p>
<p><code>brew cask install 软件名</code> 安装<strong>cask软件</strong>。</p>
<p><code>brew tap 用户/仓库 [url]</code> 向<code>Horebrew</code>软件源中添加更多仓库,默认假设仓库来自<strong>Github</strong>。</p>
<h4 id="更新">更新</h4>
<p><code>brew update</code> 更新<strong>普通软件</strong>与<strong>Homebrew</strong>本身。</p>
<p><code>brew upgrade 软件名</code> 更新指定的软件。</p>
<h4 id="卸载">卸载</h4>
<p><code>brew uninstall 软件名</code></p>
<p>除了<strong>uninstall</strong> ,也可以使用<strong>remove</strong>或<strong>rm</strong>。</p>
<h4 id="列举">列举</h4>
<p><code>brew list</code></p>
<p>此命令会列举出所有通过<strong>Homebrew</strong>安装的软件,可以配合<strong>管道</strong>与<strong>grep</strong>命令来检测是否通过<strong>Homebrew</strong>安装了某软件。</p>
<h3 id="服务">服务</h3>
<p><strong>Homebrew</strong>使用macOS的<strong>launchctl(1)</strong> 守护进程管理器来管理后台服务</p>
<p><strong>Homebrew</strong>针对服务的用法是:<code>brew services 动作 [服务名 | --all]</code></p>
<p>选项<code>--all</code>表示动作应用于所有服务。</p>
<p>其中<strong>动作</strong>包含了<strong>启动</strong>(start / run) 、<strong>重启</strong>(restart) 、<strong>停止</strong>(install / tap) 、<strong>列举</strong>(list) 。</p>
<h4 id="启动">启动</h4>
<p><code>brew services run 服务名</code> 或<code>brew services start 服务名</code> 均能启动后台服务,两者的区别在于,<code>start</code>会注册该后台服务以在登录时启动或引导,而<code>run</code>则不会。</p>
<h4 id="重启">重启</h4>
<p><code>brew services restart 服务名</code> ,停止并启动服务,并注册该后台服务以在登录时启动或引导。</p>
<h4 id="停止">停止</h4>
<p><code>brew services stop 服务名</code> ,停止服务,并将其从登录时的启动或引导注销。</p>
<h4 id="列举-2">列举</h4>
<p><code>brew services list <服务名></code> ,列举全部或者某个服务。</p>
]]></content>
</entry>
</feed>