Skip to content

Commit b153f3f

Browse files
committed
update docs
1 parent 95b19c0 commit b153f3f

File tree

2 files changed

+68
-33
lines changed

2 files changed

+68
-33
lines changed

docs/Nginx/nginx-parameter-config.md

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
## 高并发系统内核优化
2-
+ [Socket优化](#Socket)
3-
+ Nginx
4-
+ 系统内核
5-
+ [文件优化](#file)
6-
+ Nginx
7-
+ 系统内核
8-
+ [配置文件优化](#config-file)
9-
+ Nginx配置文件
10-
+ 内核配置文件
11-
+ PHP7配置文件
12-
+ PHP-FPM配置文件
13-
### <a name="Socket"/> Socket优化
14-
#### Nginx
15-
+ 子进程允许打开的连接数:`worker_connections`
16-
#### 系统内核
17-
+ [内核参数的优化](http://blog.csdn.net/moxiaomomo/article/details/19442737)
1+
# 高并发系统内核优化
2+
---
3+
## [Socket优化](#Socket)
4+
5+
* Nginx
6+
7+
* 系统内核
8+
9+
## [文件优化](#file)
10+
11+
* Nginx
12+
13+
* 系统内核
14+
15+
## [配置文件优化](#config-file)
16+
17+
* Nginx配置文件
18+
19+
* 内核配置文件
20+
21+
* PHP7配置文件
22+
23+
* PHP-FPM配置文件
24+
25+
# <a name="Socket"/> Socket优化
26+
## Nginx
27+
28+
#### 子进程允许打开的连接数:
29+
30+
```bash
31+
worker_connections
32+
```
33+
## 系统内核
34+
#### [内核参数的优化](http://blog.csdn.net/moxiaomomo/article/details/19442737)
35+
1836
+ 实践优化配置
1937
+ 编辑: `vim /etc/sysctl.conf`
2038
+ 配置结果
@@ -34,11 +52,16 @@
3452
net.ipv4.tcp_keepalive_time = 30
3553
```
3654
+ 执行命令使之生效:`/sbin/sysctl -p`
37-
### <a name="file"/> 文件优化
38-
#### Nginx
39-
+ 指当一个nginx进程打开的最多文件描述符数目:`worker_rlimit_nofile 100000;`
40-
#### 系统内核
55+
# <a name="file"/> 文件优化
56+
57+
## Nginx
58+
59+
* 指当一个nginx进程打开的最多文件描述符数目:`worker_rlimit_nofile 100000;`
60+
61+
## 系统内核
62+
4163
+ 系统限制其最大进程数:`ulimit -n`
64+
4265
+ 编辑文件:`/etc/security/limits.conf`
4366

4467
```conf
@@ -48,7 +71,8 @@
4871
* soft nofile 65535
4972
* hard nofile 65535
5073
```
51-
### <a name="config-file"/> 配置文件优化
74+
## <a name="config-file"/> 配置文件优化
75+
5276
+ Nginx配置文件
5377

5478
```lua
@@ -215,7 +239,8 @@
215239
net.ipv4.tcp_keepalive_time = 30
216240
net.ipv4.ip_local_port_range = 1024 65000
217241
```
218-
#### PHP.ini配置文件优化(PHP7)
242+
## PHP.ini配置文件优化(PHP7)
243+
219244
+ 启用Zend Opcache,php.ini配置文件中加入
220245

221246
```bash
@@ -248,7 +273,9 @@
248273
│   └── vendor
249274
```
250275
+ 使用新的编译器,使用新一点的编译器, 推荐GCC 4.8以上, 因为只有GCC 4.8以上PHP才会开启Global Register for opline and execute_data支持, 这个会带来5%左右的性能提升
276+
251277
+ 开启HugePages,然后开启Opcache的huge_code_pages
278+
252279
+ 系统中开启HugePages
253280

254281
```bash
@@ -266,9 +293,13 @@
266293
Hugepagesize: 2048 kB
267294
```
268295
+ 然后在php.ini中加入,`opcache.huge_code_pages=1`
269-
+ 开启Opcache File Cache,`opcache.file_cache=/tmp`
270-
+ 启用Zend Opcache
271-
#### PHP-FPM优化
296+
297+
+ 开启Opcache File Cache,`opcache.file_cache=/tmp`
298+
299+
+ 启用Zend Opcache
300+
+
301+
## PHP-FPM优化
302+
272303
+ 结构
273304

274305
```bash
@@ -378,7 +409,8 @@
378409
```
379410

380411
+ 以下命令将帮助我们确定每个(PHP-FPM)子进程使用的内存:
381-
> RSS列显示PHP-FPM进程的未交换的物理内存使用量,单位为千字节
412+
413+
> RSS列显示PHP-FPM进程的未交换的物理内存使用量,单位为千字节
382414
> 平均每个PHP-FPM进程在我的机器上占用大约75MB的RAM
383415

384416
```php
@@ -392,6 +424,7 @@
392424
```
393425

394426
+ 在我的情况下是56MB,服务器有16GB的RAM,所以:
427+
395428
>我留下了一些记忆,让系统呼吸。在计算内存使用情况时,您需要考虑计算机上运行的任何其他服务。
396429

397430
```php
@@ -417,9 +450,11 @@
417450
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
418451
```
419452

420-
+ HELP
421-
+ [php-fpm - 启动参数及重要配置详解](http://www.4wei.cn/archives/1002061)
422-
+ [php-fpm backlog参数潜在问题](http://blog.csdn.net/willas/article/details/11634825)
423-
+ [Adjusting child processes for PHP-FPM (Nginx)](https://myshell.co.uk/blog/2012/07/adjusting-child-processes-for-php-fpm-nginx/)
424-
+ [Nginx的worker_processes优化](http://blog.chinaunix.net/uid-26000296-id-3987521.html)
453+
## HELP
454+
455+
+ [php-fpm - 启动参数及重要配置详解](http://www.4wei.cn/archives/1002061)
456+
+ [php-fpm backlog参数潜在问题](http://blog.csdn.net/willas/article/details/11634825)
457+
+ [Adjusting child processes for PHP-FPM (Nginx)](https://myshell.co.uk/blog/2012/07/adjusting-child-processes-for-php-fpm-nginx/)
458+
459+
+ [Nginx的worker_processes优化](http://blog.chinaunix.net/uid-26000296-id-3987521.html)
425460

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
theme: jekyll-theme-time-machine
1+
theme: jekyll-theme-cayman

0 commit comments

Comments
 (0)