LNMP架构

一.LNMP基本架构

1.L(linux)N(nginx)M(mysql)P(php)
    Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
    Mysql是一个小型关系型数据库管理系统。
    PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这里写图片描述

2.编译顺序
    Mysql ->php ->nginx
    由于编译的时候比较浪费磁盘内存,所以把虚拟机的内存尽量放大,使得编译的时候提升速度,我这里的虚拟机大小为3G

这里写图片描述

二.优点

作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。
作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。

三.实现mysql,php,nginx的源码编译

1.mysql #注意版本问题

[[email protected] ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y   #cmake是编译器
[[email protected] ~]#  yum install gcc gcc-c++ ncurses-devel bison  -y   #软件包依赖性 
[[email protected] ~]# tar zxf mysql-boost-5.7.17.tar.gz 
[[email protected] ~]# cd mysql-5.7.17/
[[email protected] mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql # 安装目录-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data #数据库存放目录-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock #Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 #安装 myisam 存储引擎-DWITH_INNOBASE_STORAGE_ENGINE=1  #安装 innodb 存储引擎
-DDEFAULT_CHARSET=utf8              #使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci   #校验字符
 -DEXTRA_CHARSETS=all          #安装所有扩展字符集
-DWITH_BOOST=boost/boost_1_59_0/   
重新编译时,需要清除旧的对象文件和缓存信息   (rm -f CmakeCache.txt)
[[email protected] mysql-5.7.17]# make
[[email protected] mysql-5.7.17]# make  install 
[[email protected] mysql-5.7.17]# cd /usr/local/lnmp/mysql/
[[email protected] mysql]# ls
        bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files
[[email protected] mysql]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# cp my-default.cnf /etc/my.cnf #根据主机内存复制 mysql 配置文件
cp: overwrite `/etc/my.cnf'? y
[[email protected] mysql]# vim /etc/my.cnf 

这里写图片描述

[[email protected] mysql]# cd support-files/
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]# cd ..

#在真机中可以看到mysql的默认uid和gid都是27

这里写图片描述

[[email protected] mysql]# groupadd -g 27 mysql
[[email protected] mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql   #添加mysql用户,-u,指定用户uid,-g,指定用户组,-d,指定用户家目录,-M,禁止自主创建用户家目录
[[email protected] mysql]# pwd
/usr/local/lnmp/mysql
[[email protected] mysql]# chown -R mysql.mysql  /usr/local/lnmp/mysql   #修改用户名和组名
[[email protected] mysql]# ll
total 56
drwxr-xr-x  2 mysql mysql  4096 Aug  5 23:19 bin
-rw-r--r--  1 mysql mysql 17987 Nov 28  2016 COPYING
drwxr-xr-x  2 mysql mysql  4096 Aug  5 23:18 docs
drwxr-xr-x  3 mysql mysql  4096 Aug  5 23:18 include
drwxr-xr-x  4 mysql mysql  4096 Aug  5 23:19 lib
drwxr-xr-x  4 mysql mysql  4096 Aug  5 23:18 man
drwxr-xr-x 10 mysql mysql  4096 Aug  5 23:20 mysql-test
-rw-r--r--  1 mysql mysql  2478 Nov 28  2016 README
drwxr-xr-x 28 mysql mysql  4096 Aug  5 23:20 share
drwxr-xr-x  2 mysql mysql  4096 Aug  5 23:20 support-files
[[email protected] mysql]# vim .bash_profile   #设置环境变量,方便登陆

[[email protected] mysql]# source /root/.bash_profile     #检测语法
[[email protected] mysql]# mysql   #输入mysql,然后按tab键,可以加载出来,说明,文件已经生效
mysql                       mysqld_multi                mysql_secure_installation
mysqladmin                  mysqld_safe                 mysqlshow
mysqlbinlog                 mysqldump                   mysqlslap
mysqlcheck                  mysqldumpslow               mysql_ssl_rsa_setup
mysql_client_test           mysql_embedded              mysqltest
mysql_client_test_embedded  mysqlimport                 mysqltest_embedded
mysql_config                mysql_install_db            mysql_tzinfo_to_sql
mysql_config_editor         mysql_plugin                mysql_upgrade
mysqld                      mysqlpump                   mysqlxtest
[[email protected] mysql]# mysqld --initialize --user=mysql    #初始化,生成临时登陆密码

这里写图片描述

[[email protected] mysql]# chown root.mysql /usr/local/lnmp/mysql -R 
[[email protected] mysql]# chown mysql /usr/local/lnmp/mysql/data -R 
[[email protected] mysql]# ll
total 60
drwxr-xr-x  2 root  mysql  4096 Aug  5 23:19 bin
-rw-r--r--  1 root  mysql 17987 Nov 28  2016 COPYING
drwxr-x---  5 mysql mysql  4096 Aug  6 00:42 data   #data的用户必须是mysql
drwxr-xr-x  2 root  mysql  4096 Aug  5 23:18 docs
drwxr-xr-x  3 root  mysql  4096 Aug  5 23:18 include
drwxr-xr-x  4 root  mysql  4096 Aug  5 23:19 lib
drwxr-xr-x  4 root  mysql  4096 Aug  5 23:18 man
drwxr-xr-x 10 root  mysql  4096 Aug  5 23:20 mysql-test
-rw-r--r--  1 root  mysql  2478 Nov 28  2016 README
drwxr-xr-x 28 root  mysql  4096 Aug  5 23:20 share
drwxr-xr-x  2 root  mysql  4096 Aug  5 23:20 support-files
[[email protected] mysql]# /etc/init.d/mysqld start 
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server5.err'.
. SUCCESS! 

[[email protected] mysql]# mysql_secure_installation  #初始化环境,设置密码

Securing the MySQL server deployment.

Enter password for user root:    #用自动化生成的初始密码登陆

The existing password for the user account root has expired. Please set a new password.

New password:   #设置新密码

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?   

Press y|Y for Yes, any other key for No:   #是否检测密码强度,(回车表示默认no)
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :   #是否更改root用户密码

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  #是否删除匿名用户 
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #是否远程禁止root登录 
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  #是否删除测试数据库并访问它 
         - Dropping test database...
        Success.

         - Removing privileges on test database...
        Success.

        Reloading the privilege tables will ensure that all changes
        made so far will take effect immediately.

        Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y  #现在重新加载特权表 
        Success.

        All done! 
#登陆成功说明mysql搭建成功

这里写图片描述

2.php

#此安装包自行获取
[[email protected] ~]# tar jxf php-5.6.35.tar.bz2 
[[email protected] ~]# yum install re2c-0.13.5-1.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm -y
#下载php的依赖性安装包
[[email protected] ~]# yum install gmp-devel zlib-devel libxml2-devel curl-devel net-snmp-devel -y
[[email protected] ~]# cd php-5.6.35
#开始进行源码编译,选择自己需要的模块进行编译
[[email protected] php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx  --with-mcrypt --with-mhash
[[email protected] php-5.6.35]# make   &&  make install 
[[email protected] php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[[email protected] php-5.6.35]# cd /usr/local/lnmp/php/etc/
[[email protected] etc]# ls
php-fpm.conf.default  php.ini
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# ls
php-fpm.conf  php-fpm.conf.default  php.ini
[[email protected] etc]# vim php.ini  #更改时区
    936 date.timezone =Asia/shanghai    
[[email protected] etc]# vim php-fpm.conf    

这里写图片描述

[[email protected] etc]# id nginx   #没有nginx用户,nginx是我们在源码编译是设定的默认用户,但是还要手动建立,只有用户创建了才能起来服务
        id: nginx: No such user
[[email protected] etc]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx
[[email protected] fpm]# /etc/init.d/php-fpm start
    Starting php-fpm  done

#如果出现以下报错
[[email protected] fpm]# /etc/init.d/php-fpm start
Starting php-fpm [06-Aug-2018 02:08:50] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
[06-Aug-2018 02:08:50] ERROR: FPM initialization failed
 Failed
解决方案:
<1>查看/usr/local/lnmp/php/etc/php-fpm.conf此配置文件是否有错误,注意,文件里不能写以#开头的注释
<2>[[email protected] etc]# netstat -lntup | grep php   #查看php进程,有进程,就杀死进程
    tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      2490/php-fpm       
<3>killall php-fpm   #杀死进程


[[email protected] etc]# netstat -antlp   #查看php服务端口显示
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      902/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      979/master          
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      2600/php-fpm        
tcp        0      0 172.25.254.5:22             172.25.254.78:57057         ESTABLISHED 1370/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      902/sshd            
tcp        0      0 ::1:25                      :::*                        LISTEN      979/master          
tcp        0      0 :::3036                     :::*                        LISTEN      19804/mysqld        


3.Nginx
[[email protected] ~]# tar zxf nginx-1.10.1.tar.gz
[[email protected] ~]# cd nginx-1.10.1
[[email protected] nginx-1.10.1]# vim src/core/nginx.h
    14 define NGINX_VER          "nginx"     #改名字

这里写图片描述

[[email protected] nginx-1.10.1]# vim auto/cc/gcc 

这里写图片描述

[[email protected] nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --without-http_ssi_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio   #根据报错下载相应的软件,解决依赖性

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

[[email protected] nginx-1.10.1]# yum install pcre-devel -y
[[email protected] nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --without-http_ssi_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio  #再次编译
[[email protected] nginx-1.10.1]#  make && make install
[[email protected] nginx-1.10.1]#  cd /usr/local/lnmp/nginx/conf/
[[email protected] conf]# ls
[[email protected] conf]# vim nginx.conf
 12 events {
 13     worker_connections  65535;
 14 }

 43         location / {
 44             root   html;
 45             index  index.php index.html index.htm;   #把index.php 设置为默认发布目录,如果不改可能会出现403的访问禁止报错
 46         }
    #把php与nginx建立联系
 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 70             include        fastcgi.conf;
 71         }
 72 

[[email protected] conf]# vim /etc/security/limits.conf 

 51 nginx      -     nofile   65536
[[email protected] conf]# vim /root/.bash_profile 
 10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin
[[email protected] conf]# source /root/.bash_profile 
[[email protected] conf]# nginx
[[email protected] conf]# nginx -t
    nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful

[[email protected] conf]# netstat -antlp

这里写图片描述

[[email protected] conf]# cd /usr/local/lnmp/nginx/html/
[[email protected] html]# ls
50x.html  index.html
[[email protected] html]# vim index.php
<?php
phpinfo()
?>
访问测试

这里写图片描述

4.论坛搭建

[[email protected] conf]# yum install unzip -y
[[email protected] ~]# unzip  Discuz_X3.2_SC_UTF8.zip  -d /usr/local/lnmp/nginx/html
[[email protected] ~]# cd  /usr/local/lnmp/nginx/html
[[email protected] html]# ls
50x.html  index.html  index.php  readme  upload  utility
[[email protected] html]# ls
50x.html  index.html  index.php  readme  upload  utility
[[email protected] html]#  mv upload/ bbs
#访问:

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

#修复红叉
[[email protected] conf]# cd /usr/local/lnmp/nginx/html/bbs/
[[email protected] bbs]# chmod 777 config/ data/ uc_server/ uc_client/  -R
#刷新页面

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

#解决上述错误

[[email protected] etc]# ls
php-fpm.conf  php-fpm.conf.default  php.ini
[[email protected] etc]# vim php.ini 
1013 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
1162 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
1221 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
[[email protected] etc]# /etc/init.d/php-fpm  reload
Reload service php-fpm  done
[[email protected] etc]# cd /usr/local/lnmp/mysql/
[[email protected] mysql]# ls
bin  COPYING  data  docs  include  lib  man  mysql-test  README  share  support-files
[[email protected] mysql]# chmod 755 data/
[[email protected] mysql]# /etc/init.d/mysqld   start
Starting MySQL SUCCESS! 

这里写图片描述
这里写图片描述
这里写图片描述

5.添加memcache缓存模块(给php增添缓存):

Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。

[[email protected] ~]# tar zxf memcache-2.2.5.tgz 
[[email protected] ~]# cd memcache-2.2.5
[[email protected] memcache-2.2.5]# phpize   #phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
-bash: phpize: command not found
[[email protected] mysql]# vim /root/.bash_profile

这里写图片描述

[[email protected]ver5 mysql]# source /root/.bash_profile
[[email protected] memcache-2.2.5]# phpize
    Configuring for:
    PHP Api Version:         20131106
    Zend Module Api No:      20131226
    Zend Extension Api No:   220131226
[[email protected] memcache-2.2.5]# ./configure
[[email protected] memcache-2.2.5]# make && make install
[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
[[email protected] no-debug-non-zts-20131226]# ls
memcache.so  opcache.a  opcache.so
[[email protected] no-debug-non-zts-20131226]# pwd
/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226

[[email protected] no-debug-non-zts-20131226]# php -m | grep memcache
[[email protected] no-debug-non-zts-20131226]# cd /usr/local/lnmp/php/etc/
[[email protected] etc]# vim php.ini 

这里写图片描述

[[email protected] etc]# /etc/init.d/php-fpm reload
    Reload service php-fpm  done
[[email protected] etc]# php -m | grep memcache
    memcache
[[email protected] etc]#  yum install memcached -y
[[email protected] etc]#  /etc/init.d/memcached start
    Starting memcached:                                        [  OK  ]
[[email protected] etc]#  netstat -antlp
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      7787/memcached      
[[email protected] etc]# cd
[[email protected] ~]# cd memcache-2.2.5
[[email protected] memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/
[[email protected]    memcache-2.2.5]#  cd /usr/local/lnmp/nginx/html/
[[email protected] html]# vim memcache.php   #对网页进行加密
     22 define('ADMIN_USERNAME','memcache');    // Admin Username
     23 define('ADMIN_PASSWORD','westos');      // Admin Password  #改密码
     24 define('DATE_FORMAT','Y/m/d H:i:s');
     25 define('GRAPH_SIZE',200);
     26 define('MAX_ITEM_DUMP',50);
     27 
     28 $MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array  #改用户
     29 #$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array  #这行注释掉
#浏览器访问

这里写图片描述
这里写图片描述
这里写图片描述

#外压测试(看看加入缓存之后有没有起到加速的作用):
[[email protected] ~]# ab -c 10 -n 1000 http://172.25.254.5/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.254.5 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx
Server Hostname:        172.25.254.5
Server Port:            80

Document Path:          /index.php
Document Length:        84848 bytes

Concurrency Level:      10
Time taken for tests:   2.135 seconds
Complete requests:      1000
Failed requests:        660
   (Connect: 0, Receive: 0, Length: 660, Exceptions: 0)
Write errors:           0
Total transferred:      84975535 bytes
HTML transferred:       84819535 bytes
Requests per second:    468.45 [#/sec] (mean)   #
Time per request:       21.347 [ms] (mean)
Time per request:       2.135 [ms] (mean, across all concurrent requests)
Transfer rate:          38873.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.7      0      12
Processing:     8   21   5.2     20      54
Waiting:        4   19   4.8     19      51
Total:          9   21   5.1     20      54

Percentage of the requests served within a certain time (ms)
  50%     20
  66%     21
  75%     21
  80%     22
  90%     28
  95%     33
  98%     37
  99%     40
 100%     54 (longest request)
[[email protected] ~]# ab -c 10 -n 1000 http://172.25.254.5/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.254.5 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx
Server Hostname:        172.25.254.5
Server Port:            80

Document Path:          /example.php
Document Length:        123 bytes

Concurrency Level:      10
Time taken for tests:   0.827 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      279000 bytes
HTML transferred:       123000 bytes
Requests per second:    1209.34 [#/sec] (mean)   #速度显然比上面的快
Time per request:       8.269 [ms] (mean)
Time per request:       0.827 [ms] (mean, across all concurrent requests)
Transfer rate:          329.50 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.1      0       7
Processing:     1    8   3.1      7      30
Waiting:        1    8   3.0      7      29
Total:          2    8   3.0      7      30

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      8
  75%      9
  80%     10
  90%     12
  95%     14
  98%     17
  99%     18
 100%     30 (longest request)
6.缓存前移( php ---> nginx ),加快访问速度

[[email protected] html]# cd
[[email protected] ~]# nginx -s stop
[[email protected] ~]#  tar zxf openresty-1.13.6.1.tar.gz 
[[email protected] ~]# cd openresty-1.13.6.1
[[email protected] openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty --with-http_ssl_module --with-http_stub_status_module --user=nginx --with-threads --with-file-aio
[[email protected] memcache-2.2.5]# make && make install
[[email protected] memcache-2.2.5]# vim /usr/local/lnmp/openresty/nginx/conf/nginx.conf
     17 http {
     18     include       mime.types;
     19     default_type  application/octet-stream;
     20     upstream  memcache{
     21        server localhost:11211;
     22        keepalive  512;
     23        }
     47         location / {
     48             root   html;
     49             index  index.php index.html index.htm;
     50         }
     51         location /memc {
     52         internal;
     53             memc_connect_timeout 100ms;
     54             memc_send_timeout 100ms;
     55             memc_read_timeout 100ms;
     56             set $memc_key $query_string;
     57             set $memc_exptime 300;
     58             memc_pass memcache;
     59         }

     78        location ~ \.php$ {
     79            set    $key  $uri$args;
     80            srcache_fetch GET  /memc   $key;
     81            srcache_store PUT  /memc   $key;
     82            root           html;
     83            fastcgi_pass   127.0.0.1:9000;
     84            fastcgi_index  index.php;
     85          # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     86            include        fastcgi.conf;
     87        }



[[email protected] memcache-2.2.5]# /usr/local/lnmp/openresty/nginx/sbin/nginx -t
    nginx: the configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf test is successful
[[email protected] memcache-2.2.5]#  /usr/local/lnmp/openresty/nginx/sbin/nginx 
[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/openresty/nginx/html
[[email protected] html]# pwd
    /usr/local/lnmp/openresty/nginx/html
[[email protected] html]# cp /usr/local/lnmp/nginx/html/example.php    .
[[email protected] html]# cp /usr/local/lnmp/nginx/html/memcache.php   .
#测试:

这里写图片描述
这里写图片描述
这里写图片描述

[[email protected]78 ~]# ab -c 10 -n 1000 http://172.25.254.5/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.254.5 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        openresty/1.13.6.1
Server Hostname:        172.25.254.5
Server Port:            80

Document Path:          /index.php
Document Length:        16 bytes

Concurrency Level:      10
Time taken for tests:   0.436 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      192000 bytes
HTML transferred:       16000 bytes
Requests per second:    2292.69 [#/sec] (mean)
Time per request:       4.362 [ms] (mean)
Time per request:       0.436 [ms] (mean, across all concurrent requests)
Transfer rate:          429.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.1      0       9
Processing:     1    4   2.1      3      16
Waiting:        1    4   2.1      3      16
Total:          1    4   2.2      4      16

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      4
  80%      5
  90%      6
  95%     10
  98%     12
  99%     13
 100%     16 (longest request)
[[email protected] ~]# ab -c 10 -n 1000 http://172.25.254.5/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.254.5 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        openresty/1.13.6.1
Server Hostname:        172.25.254.5
Server Port:            80

Document Path:          /example.php
Document Length:        123 bytes

Concurrency Level:      10
Time taken for tests:   0.184 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      313000 bytes
HTML transferred:       123000 bytes
Requests per second:    5433.31 [#/sec] (mean)
Time per request:       1.841 [ms] (mean)
Time per request:       0.184 [ms] (mean, across all concurrent requests)
Transfer rate:          1660.77 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.1      0      10
Processing:     0    1   1.5      1      10
Waiting:        0    1   1.5      1      10
Total:          1    2   1.9      1      12

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      2
  80%      2
  90%      2
  95%      5
  98%     10
  99%     11
 100%     12 (longest request)
原文链接:加载失败,请重新获取