debian 与 centos, apache 与 nginx。问题不重要,重要的是解决的过程 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yangxiu
V2EX    服务器

debian 与 centos, apache 与 nginx。问题不重要,重要的是解决的过程

  •  
  •   yangxiu 2016-03-25 21:02:08 +08:00 3420 次点击
    这是一个建于 3563 天前的主题,其中的信息可能已经有所发展或是发生改变。

    抱歉,ssh的字符有空格,复制进来排版会乱掉,编辑了几次也不行,先凑合看吧,我再改改。 受人所托,要做一个比较正式的网站,可自己以前折腾都是 debian + lighttpd + php-fastcgi + sqlite 这样的奇葩组合,肯定不能这么用。

    首先是系统,一直都是 debian 而且也没有什么不稳定的情况,但 centos 在很多人口中似乎都是:红帽亲儿子,企业,稳定。于是便纠结应该用自己熟悉的 debian 还是换到口碑似乎更好的 centos 。

    第二是 web 服务器,自己用 lighttpd 只是为了低资源占用,普遍用的应该都是 apache 和 nginx 吧,但用法也有好多种。 单 apache ,并发弱 但 mod-php 性能好,资源占用高。 单 nginx ,并发强 但 php-fpm 会有 502 ,资源占用低。 nginx 反代 apache ,前端 nginx 抗并发,后端 apache 处理 php ,似乎是最佳方案。

    开始动手测试,测试是在虚拟机下进行的,两台虚拟机都是 512M 内存,系统是 debian 8 和 centos 7 ,都用默认源,都用 apt/yum 安装。

    ------------------------------apache 部分------------------------------ Centos------------------------------------------------------------ Server version: Apache/2.4.6 (CentOS) Server built: Nov 19 2015 21:43:13 Debian------------------------------------------------------------ Server version: Apache/2.4.10 (Debian) Server built: Nov 28 2015 14:05:48 从版本号上看,是 debian 中的 apache 较新,但是有听到一种说法, centos 中的包都有 backport ,虽然版本号旧,但软件不旧,具体不知如何考证。

    ------------------------------php 部分------------------------------ Centos------------------------------------------------------------ PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies Debian------------------------------------------------------------ PHP 5.6.17-0+deb8u1 (cli) (built: Jan 13 2016 09:10:12) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies 从版本号上看,是 debian 中的 php 较新。 但是安装 php-gd 的时候, centos 中是 bundle 版, debian 中是 dev 版, dev 字面上应该是开发版。明明用的是 debian 的 stable 源,为什么会是开发版?

    ------------------------------mysql 部分------------------------------ Centos------------------------------------------------------------ mysql Ver 15.1 Distrib 5.5.44-MariaDB, for Linux (x86_64) using readline 5.1 Debian------------------------------------------------------------ mysql Ver 14.14 Distrib 5.5.47, for debian-linux-gnu (x86_64) using readline 6.3 数据库这里就不能看版本号了,因为 centos 用 yum 安装 mysql 会自动安装 mariadb 。

    debian 和 centos 下分别安装 Discuz x3.2 后进行压力测试,放个雅黑探针用于观测系统负载。 ------------------------------压力测试------------------------------ 使用 apache 的压力测试工具, ab -c 100 -n 100 http://127.0.0.1/forum.php ,之后逐步增加。 Centos------------------------------------------------------------ Server Software: Apache/2.4.6 Server Hostname: 127.0.0.1 Server Port: 80

    Document Path: /forum.php Document Length: 12872 bytes

    Concurrency Level: 100 Time taken for tests: 3.589 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 1359500 bytes HTML transferred: 1287200 bytes Requests per second: 27.86 [#/sec] (mean) Time per request: 3589.014 [ms] (mean) Time per request: 35.890 [ms] (mean, across all concurrent requests) Transfer rate: 369.92 [Kbytes/sec] received

    Connection Times (ms) min mean[+/-sd] median max Connect: 1 1 0.3 1 2 Processing: 74 1974 996.3 1995 3513 Waiting: 71 1974 996.3 1995 3513 Total: 74 1975 996.0 1997 3514

    Percentage of the requests served within a certain time (ms) 50% 1997 66% 2560 75% 2925 80% 3046 90% 3374 95% 3484 98% 3494 99% 3514 100% 3514 (longest request)

    Debian------------------------------------------------------------ Server Software: Apache/2.4.10 Server Hostname: 127.0.0.1 Server Port: 80

    Document Path: /forum.php Document Length: 12872 bytes

    Concurrency Level: 100 Time taken for tests: 1.215 seconds Complete requests: 100 Failed requests: 0 Total transferred: 1367400 bytes HTML transferred: 1287200 bytes Requests per second: 82.30 [#/sec] (mean) Time per request: 1215.040 [ms] (mean) Time per request: 12.150 [ms] (mean, across all concurrent requests) Transfer rate: 1099.02 [Kbytes/sec] received

    Connection Times (ms) min mean[+/-sd] median max Connect: 3 25 4.0 26 27 Processing: 149 705 315.9 706 1187 Waiting: 134 694 316.7 705 1186 Total: 170 730 317.1 732 1212

    Percentage of the requests served within a certain time (ms) 50% 732 66% 917 75% 1010 80% 1055 90% 1161 95% 1205 98% 1211 99% 1212 100% 1212 (longest request)

    分别测试三次,取最好结果。 测试结果是 debian 的更好,但内存已经满了。 centos 则已经开始使用 swap 了。 系统负载方面也是 debian 更低,但微乎其微,至少和内存方面的差距比起来是这样。 测试结束后内存占用率回落也是 debian 更快, centos 回落速度慢是不是受 swap 硬盘速度的影响不得而知。 centos 是 mariadb 而 debian 是 mysql ,不知道这是不是也是个影响因素。

    接下来测试 nginx+apache 和 单 nginx ,在 debian 虚拟机下快照还原后重新安装 nginx+apache------------------------------------------------------------ 结果忘了保存,压力测试结果比单 apache 更好,资源占用比单 apache 更低。

    单 nginx------------------------------------------------------------ Server Software: nginx/1.6.2 Server Hostname: 127.0.0.1 Server Port: 80

    Document Path: /forum.php Document Length: 12871 bytes

    Concurrency Level: 100 Time taken for tests: 1.024 seconds Complete requests: 100 Failed requests: 0 Total transferred: 1363960 bytes HTML transferred: 1287100 bytes Requests per second: 97.66 [#/sec] (mean) Time per request: 1023.960 [ms] (mean) Time per request: 10.240 [ms] (mean, across all concurrent requests) Transfer rate: 1300.82 [Kbytes/sec] received

    Connection Times (ms) min mean[+/-sd] median max Connect: 9 28 3.4 28 32 Processing: 56 519 288.0 503 991 Waiting: 45 514 287.2 501 991 Total: 73 547 290.2 531 1023

    Percentage of the requests served within a certain time (ms) 50% 531 66% 720 75% 819 80% 866 90% 964 95% 1011 98% 1016 99% 1023 100% 1023 (longest request) 测试结果最好,压力测试最好,资源占用最低 而且在压力测试参数增加后, nginx 的测试结果更好了,有点不解。

    现在决定用 debian + nginx + php-fpm + mysql 这个组合了,但也留下几个疑问: 为什么那么多人说 centos 要比 debian 稳定? centos 中的软件真的会依靠 backport 做到版本号老,但软件不旧吗? 为什么那么多人推荐 nginx 反代 apache 这种组合?因为后端运算集中的应用下 apache 更为强大?因为 nginx 使用 php-fpm 会出现 502 ? 为什么 debian 的 stable 源中的 php-gd 会是 dev 版?因为这个 dev 版已经经过测试足够稳定了? mariadb 能否取代 mysql ?把 mysql 换成 mariadb 是否更好?我对 mariadb 完全陌生,看来得多学习学习了:) 为什么压力测试时,单 nginx 压力越高,反而表现越好了? 有没有比 debian + nginx + php-fpm + mysql 这个组合更好的方案?似乎问题又回到了原点。。。

    第 1 条附言    2016-03-25 22:27:04 +08:00

    重新编辑发一遍

    受人所托,要做一个比较正式的网站,可自己以前折腾都是 debian + lighttpd + php-fastcgi + sqlite 这样的奇葩组合,肯定不能这么用。

    首先是系统,一直都是 debian 而且也没有什么不稳定的情况,但 centos 在很多人口中似乎都是:红帽亲儿子,企业,稳定。于是便纠结应该用自己熟悉的 debian 还是换到口碑似乎更好的 centos 。

    第二是 web 服务器,自己用 lighttpd 只是为了低资源占用,普遍用的应该都是 apache 和 nginx 吧,但用法也有好多种。
    单 apache ,并发弱 但 mod-php 性能好,资源占用高。
    单 nginx ,并发强 但 php-fpm 会有 502 ,资源占用低。
    nginx 反代 apache ,前端 nginx 抗并发,后端 apache 处理 php ,似乎是最佳方案。

    开始动手测试,测试是在虚拟机下进行的,两台虚拟机都是 512M 内存,系统是 debian 8 和 centos 7 ,都用默认源,都用 apt/yum 安装。

    apache 部分

    Centos

    Server version: Apache/2.4.6 (CentOS) Server built: Nov 19 2015 21:43:13

    Debian

    Server version: Apache/2.4.10 (Debian) Server built: Nov 28 2015 14:05:48

    从版本号上看,是 debian 中的 apache 较新,但是有听到一种说法, centos 中的包都有 backport ,虽然版本号旧,但软件不旧,具体不知如何考证。

    php 部分

    Centos

    PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

    Debian

    PHP 5.6.17-0+deb8u1 (cli) (built: Jan 13 2016 09:10:12)
    Copyright (c) 1997-2015 The PHP Group
    Zend Engine v26.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

    从版本号上看,是 debian 中的 php 较新。
    但是安装 php-gd 的时候, centos 中是 bundle 版, debian 中是 dev 版, dev 字面上应该是开发版。明明用的是 debian 的 stable 源,为什么会是开发版?

    mysql 部分

    Centos

    mysql Ver 15.1 Distrib 5.5.44-MariaDB, for Linux (x86_64) using readline 5.1

    Debian

    mysql Ver 14.14 Distrib 5.5.47, for debian-linux-gnu (x86_64) using readline 6.3

    数据库这里就不能看版本号了,因为 centos 用 yum 安装 mysql 会自动安装 mariadb 。

    debian 和 centos 下分别安装 Discuz x3.2 后进行压力测试,放个雅黑探针用于观测系统负载。

    压力测试部分

    使用 apache 的压力测试工具, ab -c 100 -n 100 http://127.0.0.1/forum.php ,之后逐步增加。

    Centos

    Server Software: Apache/2.4.6
    Server Hostname: 127.0.0.1
    Server Port: 80

    Document Path: /forum.php
    Document Length: 12872 bytes

    Concurrency Level: 100

    第 2 条附言    2016-03-25 22:28:31 +08:00
    Time taken for tests: 3.589 seconds
    Complete requests: 100
    Failed requests: 0
    Write errors: 0
    Total transferred: 1359500 bytes
    HTML transferred: 1287200 bytes
    Requests per second: 27.86 [#/sec] (mean)
    Time per request: 3589.014 [ms] (mean)
    Time per request: 35.890 [ms] (mean, across all concurrent requests)
    Transfer rate: 369.92 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 1 1 0.3 1 2
    Processing: 74 1974 996.3 1995 3513
    Waiting: 71 1974 996.3 1995 3513
    Total: 74 1975 996.0 1997 3514

    Percentage of the requests served within a certain time (ms)
    50% 1997
    66% 2560
    75% 2925
    80% 3046
    90% 3374
    95% 3484
    98% 3494
    99% 3514
    100% 3514 (longest request)

    ## Debian
    Server Software: Apache/2.4.10
    Server Hostname: 127.0.0.1
    Server Port: 80

    Document Path: /forum.php
    Document Length: 12872 bytes

    Concurrency Level: 100
    Time taken for tests: 1.215 seconds
    Complete requests: 100
    Failed requests: 0
    Total transferred: 1367400 bytes
    HTML transferred: 1287200 bytes
    Requests per second: 82.30 [#/sec] (mean)
    Time per request: 1215.040 [ms] (mean)
    Time per request: 12.150 [ms] (mean, across all concurrent requests)
    Transfer rate: 1099.02 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 3 25 4.0 26 27
    Processing: 149 705 315.9 706 1187
    Waiting: 134 694 316.7 705 1186
    Total: 170 730 317.1 732 1212

    Percentage of the requests served within a certain time (ms)
    50% 732
    66% 917
    75% 1010
    80% 1055
    90% 1161
    95% 1205
    98% 1211
    99% 1212
    100% 1212 (longest request)
    第 3 条附言    2016-03-25 22:29:09 +08:00
    分别测试三次,取最好结果。
    测试结果是 debian 的更好,但内存已经满了。 centos 则已经开始使用 swap 了。
    系统负载方面也是 debian 更低,但微乎其微,至少和内存方面的差距比起来是这样。
    测试结束后内存占用率回落也是 debian 更快, centos 回落速度慢是不是受 swap 硬盘速度的影响不得而知。 centos 是 mariadb 而 debian 是 mysql ,不知道这是不是也是个影响因素。

    # 接下来测试 nginx+apache 和 单 nginx ,在 debian 虚拟机下快照还原后重新安装
    ## nginx+apache
    结果忘了保存,压力测试结果比单 apache 更好,资源占用比单 apache 更低。

    ## 单 nginx
    Server Software: nginx/1.6.2
    Server Hostname: 127.0.0.1
    Server Port: 80

    Document Path: /forum.php
    Document Length: 12871 bytes

    Concurrency Level: 100
    Time taken for tests: 1.024 seconds
    Complete requests: 100
    Failed requests: 0
    Total transferred: 1363960 bytes
    HTML transferred: 1287100 bytes
    Requests per second: 97.66 [#/sec] (mean)
    Time per request: 1023.960 [ms] (mean)
    Time per request: 10.240 [ms] (mean, across all concurrent requests)
    Transfer rate: 1300.82 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 9 28 3.4 28 32
    Processing: 56 519 288.0 503 991
    Waiting: 45 514 287.2 501 991
    Total: 73 547 290.2 531 1023

    Percentage of the requests served within a certain time (ms)
    50% 531
    66% 720
    75% 819
    80% 866
    90% 964
    95% 1011
    98% 1016
    99% 1023
    100% 1023 (longest request)
    测试结果最好,压力测试最好,资源占用最低
    而且在压力测试参数增加后, nginx 的测试结果更好了,有点不解。

    # 结果
    现在决定用 debian + nginx + php-fpm + mysql 这个组合了,但也留下几个疑问:
    为什么那么多人说 centos 要比 debian 稳定? centos 中的软件真的会依靠 backport 做到版本号老,但软件不旧吗?
    为什么那么多人推荐 nginx 反代 apache 这种组合?因为后端运算集中的应用下 apache 更为强大?因为 nginx 使用 php-fpm 会出现 502 ?
    为什么 debian 的 stable 源中的 php-gd 会是 dev 版?因为这个 dev 版已经经过测试足够稳定了?
    mariadb 能否取代 mysql ?把 mysql 换成 mariadb 是否更好?我对 mariadb 完全陌生,看来得多学习学习了:)
    为什么压力测试时,单 nginx 压力越高,反而表现越好了?
    有没有比 debian + nginx + php-fpm + mysql 这个组合更好的方案?似乎问题又回到了原点。。。
    8 条回复    2016-03-25 23:03:49 +08:00
    Andy1999
        1
    Andy1999  
       2016-03-25 21:03:55 +08:00   1
    Apache 请在 2U4G 的服务器上用
    UnisandK
        2
    UnisandK  
       2016-03-25 21:10:33 +08:00   1
    正规发行版应该都是稳定的
    apache 把线程调度器当包调度器在用,所以高并发情况下性能会急剧下降
    mariadb 是 mysql 的分支,你可以把它当 mysql 用,装完命令都是 mysql ,没变化的
    yangxiu
        3
    yangxiu  
    OP
       2016-03-25 21:18:52 +08:00
    @Andy1999
    这边是自己测试,电脑不好虚拟机开不了大内存。正式的服务器是 E3-1230V2 和 4G 内存,而且是独立服务器
    yangxiu
        4
    yangxiu  
    OP
       2016-03-25 21:23:29 +08:00
    @UnisandK
    测试的结果是 debian 性能好一些,我自己也是一直 debian 的。
    就是无法理解为什么那么多人说 centos 比 debian 稳定,没有那么多人说我就会坚持 debian 的。但是既然有人说了,就会忍不住去尝试,去证实。
    just1
        5
    just1  
       2016-03-25 21:53:17 +08:00 via Android
    其实发帖可以选择 markdown ,```就不会换行了
    Remember
        6
    Remember  
       2016-03-25 22:05:09 +08:00
    不买服务的话, centos 不比 debian 更有优势。
    yangxiu
        7
    yangxiu  
    OP
       2016-03-25 22:33:18 +08:00
    @just1
    用 markdown 编辑重发了
    然后超过字数要分段发,后两个附言忘了选 markdown 了
    yangxiu
        8
    yangxiu  
    OP
       2016-03-25 23:03:49 +08:00
    @Andy1999
    @UnisandK
    @just1
    @Remember
    已经修改好重新发了一份,各位移步到 http://www.v2ex.com/t/266404
    谢谢各位回答帮助:)
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2550 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 30ms UTC 04:43 PVG 12:43 LAX 20:43 JFK 23:43
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86