LNMP动静分离,负载均衡及高可用搭建

文章目录

    • 一、架构图
    • 二、搭建nginx服务
      • 1、yum安装nginx
      • 2、优化配置文件
      • 3、搭建博客服务
      • 4、启动服务,并将博客应用复制到php,配置文件复制到nginx2
    • 三、搭建PHP服务器
    • 四、搭建MySQL服务器
    • 五、搭建负载均衡服务器
    • 六、搭建代理服务器
    • 七、实现代理服务器高可用
        • 1、lb1安装keepalived服务
        • 2、lb2安装nginx服务和keepalived
        • 3、验证飘移地址
    • 八、压力测试
      • 1、ab测试
        • 1、进行160个并发访问,发出10000个请求
        • 2、进行1000个并发访问,发出1000000个请求
      • 2、webbench测试
        • 1、模拟300个并发连接持续60s
        • 2、模拟5000个并发连接持续60s


一、架构图

LNMP动静分离,负载均衡及高可用搭建_第1张图片

主机名 IP地址 作用
nginx1 192.168.1.10 提供nginx服务
php 192.168.1.20 web服务
mysql 192.168.1.30 数据库
nginx2 192.168.1.40 提供nginx负载均衡
lb2 192.168.1.50 反向代理、高可用
lb2 192.168.1.60 反向代理、高可用

二、搭建nginx服务

1、yum安装nginx

[root@nginx1 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@nginx1 ~]# yum -y install nginx
[root@nginx1 ~]# systemctl start nginx
[root@nginx1 ~]# systemctl enable nginx

2、优化配置文件

[root@nginx1 ~]# vim /etc/nginx/nginx.conf
user  nginx;
worker_processes  4;
worker_cpu_affinity 01 10 01 10;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    client_max_body_size 10m;    #允许客户端请求的最大单文件字节数
    client_body_buffer_size 128k;    #缓冲区代理缓冲用户端请求的最大字节数
    proxy_connect_timeout 75;    #nginx跟后端服务器连接超时时间(代理连接超时)
    proxy_send_timeout 75;    #后端服务器数据回传时间(代理发送超时)
    proxy_read_timeout 75;    #连接成功后,后端服务器响应时间(代理接收超时)
    proxy_buffer_size 4k;    #设置代理服务器(nginx)保存用户头信息的缓冲区大小
    proxy_buffers 4 32k;    #proxy_buffers缓冲区
    proxy_busy_buffers_size 64k;    #高负荷下缓冲大小
    proxy_temp_file_write_size 64k;    #设定缓存文件夹大小
    proxy_buffering on;    #代理时开启或关闭缓冲后端服务器的响应
    proxy_temp_path /etc/nginx/proxy_temp;
    proxy_cache_path /etc/nginx/proxy_cache levels=1:2 keys_zone=my-cache:100m inactive=600m max_size=2g;
    server_tokens off;    #隐藏nginx的版本号
    sendfile        on;    #开启高效文件传输模式
    tcp_nopush     on;    #防止网路阻塞
    client_header_buffer_size 4k;    #客户端请求头部的缓冲区大小
    open_file_cache max=102400 inactive=20s;    #打开文件指定缓存经过20s后文件没被请求后删除缓存
    open_file_cache_valid 30s;    #检查一次缓存的有效信息
    open_file_cache_min_uses 1;    #有一个文件在 inactive 时间内一次没被使用,它将被移除
    client_header_timeout 15;    #设置请求头的超时时间
    client_body_timeout 15;    #设置请求体的超时时间
    reset_timedout_connection on;    #关闭不响应的客户端连接
    send_timeout 15;    #响应客户端超时时间
    keepalive_timeout  65;    #客户端连接保持会话超时时间

    fastcgi_connect_timeout 600;    #指定连接到后端 FastCGI 的超时时间
    fastcgi_send_timeout 600;    #向 FastCGI 传送请求的超时时间
    fastcgi_read_timeout 600;    #指定接收 FastCGI 应答的超时时间
    fastcgi_buffer_size 64k;    #指定读取 FastCGI 应答第一部分需要用多大的缓冲区
    fastcgi_buffers 4 64k;    #指定本地需要缓冲 FastCGI 的应答请求的空间大小
    fastcgi_busy_buffers_size 128k;    #建议设置为 fastcgi_buffers 的两倍
    fastcgi_temp_file_write_size 128k;    #在写入 fastcgi_temp_path 时将用多大的数据块,默认两倍
    fastcgi_temp_path /etc/nginx/nginx_tmp;    #缓存临时目录
    fastcgi_intercept_errors on;    #允许nginx 使用 error_page 处理错误信息
    fastcgi_cache_path  /etc/nginx/fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128m inactive=1d max_size=10g;    #astcgi_cache 缓存目录

    gzip  on;
    gzip_comp_level 6;    #gzip压缩比
    gzip_http_version 1.1;    #识别http协议的版本
    gzip_proxied  any;    #Nginx作为反向代理的时候启用,any–无条件启用压缩
    gzip_min_length 1k;    #设置允许压缩的页面最小字节数
    gzip_buffers 16 8k;    #设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流
    gzip_types  text/htm;    #匹配mime类型进行压缩
    gzip_vary on;    #不管浏览器支不支持都进行压缩
    include /etc/nginx/conf.d/*.conf;
}

3、搭建博客服务

[root@nginx1 ~]# mkdir /blog
[root@nginx1 ~]# cd /blog/
[root@nginx1 blog]# unzip wordpress-4.9.4-zh_CN.zip
[root@nginx1 blog]# chmod -R 777 wordpress
[root@nginx1 ~]# vim /etc/nginx/conf.d/blog.conf
server {
        listen 80;
        server_name blog.benet.com;
        root /blog/wordpress;
        index index.php index.html;

        location ~\.php$ {
                root /blog/wordpress;
                fastcgi_pass 192.168.1.20:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

                fastcgi_cache cache_fastcgi;   #开启 FastCGI 缓存并为其指定一个名称
                fastcgi_cache_valid 200 302 1h;   #指定应答代码的缓存时间(200和302应答缓存一小时)
                fastcgi_cache_valid 301 1d;   #将 301 应答缓存一天
                fastcgi_cache_valid any 1m;   #将其他应答缓存为 1 分钟
                fastcgi_cache_min_uses 1;   #设置经过1次请求的相同 URL 将被缓存
                fastcgi_cache_use_stale error timeout invalid_header http_500;
                fastcgi_cache_key http://$host$request_uri;   #设置web缓存的Key值
        }
        location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ {   #expires 缓存调优
            expires 30d;
            #log_not_found off;
            access_log off;
        }
        location ~* \.(js|css)$ {
            expires 7d;
            log_not_found off;
            access_log off;
        }
        location ~* ^.+\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {   #防盗链
            valid_referers none blocked www.benet.com benet.com;
            if ($invalid_referer) {
            #return 302 http://www.benet.com/img/nolink.jpg;
            return 404;
            break;
            }
            access_log off;
        }
}

4、启动服务,并将博客应用复制到php,配置文件复制到nginx2

[root@nginx1 ~]# systemctl restart nginx
[root@nginx1 ~]# scp -rp /etc/nginx/*  [email protected]:/etc/nginx
[root@nginx1 ~]# scp -rp /blog [email protected]:/
[root@nginx1 ~]# nginx -t
[root@nginx1 ~]# systemctl enable nginx

三、搭建PHP服务器

[root@php ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@php ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@php ~]# yum makecache fast
[root@php ~]# yum -y install php72w php72w-cli php72w-common php72w-devel \php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm \
> php72w-mysqlnd php72w-opcache
[root@php ~]# systemctl start php-fpm
[root@php ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@php ~]# vim /etc/php-fpm.d/www.conf
listen = 192.168.1.20:9000
listen.allowed_clients = 127.0.0.1,192.168.1.10,192.168.1.40,192.168.1.254   #允许访问主机ip
[root@php ~]# systemctl restart php-fpm

四、搭建MySQL服务器

[root@mysql ~]# mkdir -p /server/soft
[root@mysql ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql ~]# mv mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz /server/soft/
[root@mysql ~]# yum -y remove mariadb-libs.x86_64
[root@mysql ~]# yum -y install libaio-devel
[root@mysql ~]# cd /server/soft/
[root@mysql soft]# tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 
[root@mysql soft]# ln -s /server/soft/mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
[root@mysql soft]# useradd -s /sbin/nologin mysql
[root@mysql soft]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@mysql soft]# source /etc/profile
[root@mysql soft]# mkdir -p /data/mysql/data
[root@mysql soft]# chown -R mysql.mysql /usr/local/mysql/
[root@mysql soft]# chown -R mysql.mysql /data
[root@mysql soft]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
[root@mysql soft]# cat >/etc/my.cnf <
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
EOF
[root@mysql soft]# cat >/etc/systemd/system/mysqld.service <
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
[root@mysql soft]# systemctl start mysqld
[root@mysql soft]# mysql_secure_installation
[root@mysql ~]# mysql -uroot -p123456
mysql> create database blog;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on blog.* to lisi@'192.168.1.%' identified by '123.com';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye

五、搭建负载均衡服务器

[root@nginx2 ~]# vim /etc/yum.repos.d/nginx.repo
[root@nginx2 ~]# yum -y install nginx
[root@nginx2 ~]# systemctl restart nginx
[root@nginx2 ~]# systemctl enable nginx
[root@localhost ~]# vim /etc/nginx/conf.d/lb1.conf 
upstream webcluster {
        server 192.168.1.10:80;
        server 192.168.1.40:80;
}
server {
        listen 80;
        server_name blog.benet.com;

        location / {
                proxy_pass      http://webcluster;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

六、搭建代理服务器

[root@lb1 ~]# vim /etc/yum.repos.d/nginx.repo
[root@lb1 ~]# yum -y install nginx
[root@nginx1 ~]# scp -rp /etc/nginx/nginx.conf  [email protected]:/etc/nginx/nginx.conf
[root@nginx1 ~]# scp -rp /etc/nginx/nginx.conf  [email protected]:/etc/nginx/nginx.conf
[root@lb1 ~]# vim /etc/nginx/conf.d/lb1.conf
upstream webcluster {
        server 192.168.1.10:80;
        server 192.168.1.40:80;
}
server {
        listen 80;
        server_name blog.benet.com;

        location / {
                proxy_pass  http://webcluster;
                include nginx_params;
         }
}
[root@lb1 ~]# vim /etc/nginx/nginx_params
proxy_set_header Host $http_host;   #允许重新定义或者添加发往后端服务器的请求头
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   #可以获取用户真实IP

proxy_connect_timeout 30;   #nginx 跟后端服务器连接超时时间
proxy_send_timeout 60;   #后端服务器数据回传时间
proxy_read_timeout 60;   #定义从后端服务器读取响应的超时

proxy_buffering on;   #代理的时候,开启缓冲后端服务器的响应
proxy_buffer_size 32k;   #设置缓冲区的大小为32K
proxy_buffers 4 128k;   #为每个连接设置缓冲区的数量为4,每块缓冲区的大小为128K
[root@lb1 ~]# systemctl start nginx

七、实现代理服务器高可用

1、lb1安装keepalived服务

[root@lb1 ~]# yum -y install keepalived
[root@lb1 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   router_id lb1   #路由id号
}

vrrp_instance VI_1 {
    state MASTER     #状态:MASTER主
    interface ens33
    virtual_router_id 51
    priority 100   #优先级小
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.254	#虚拟路由ip,公共ip
    }
}
[root@lb1 ~]# systemctl start keepalived
[root@lb1 ~]# scp -rp /etc/nginx/*  [email protected]:/etc/nginx

2、lb2安装nginx服务和keepalived

[root@lb2 ~]# vim /etc/yum.repos.d/nginx.repo
[root@lb2 ~]# yum -y install nginx
[root@lb2 ~]# yum -y install keepalived
[root@lb2 ~]# mv /etc/nginx/conf.d/lb1.conf /etc/nginx/conf.d/lb2.conf 
[root@lb2 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   router_id lb2
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.254
    }
}
[root@lb2 ~]# systemctl start nginx
[root@lb2 ~]# systemctl start keepalived

3、验证飘移地址

[root@lb1 ~]# ip a show dev ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:88:26:30 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.50/24 brd 192.168.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.1.254/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::c13d:1021:3463:e652/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::7b62:b4f3:e4e4:d24c/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::47b0:c0f7:8abb:d142/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
[root@lb2 ~]# ip a show dev ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:dc:b1:e9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.60/24 brd 192.168.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::c13d:1021:3463:e652/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::7b62:b4f3:e4e4:d24c/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::47b0:c0f7:8abb:d142/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever

八、压力测试

1、ab测试

1、进行160个并发访问,发出10000个请求

[root@lb1 ~]# ab -c 160 -n 10000 http://blog.benet.com/index.html
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 blog.benet.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx
Server Hostname:        blog.benet.com
Server Port:            80

Document Path:          /index.html
Document Length:        146 bytes

Concurrency Level:      160
Time taken for tests:   1.552 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Non-2xx responses:      10000
Total transferred:      2890000 bytes
HTML transferred:       1460000 bytes
Requests per second:    6441.86 [#/sec] (mean)
Time per request:       24.838 [ms] (mean)
Time per request:       0.155 [ms] (mean, across all concurrent requests)
Transfer rate:          1818.06 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    6  35.1      4    1014
Processing:     4   18  12.7     16     227
Waiting:        1   16  11.9     14     223
Total:          6   25  37.5     21    1039

Percentage of the requests served within a certain time (ms)
  50%     21
  66%     26
  75%     28
  80%     29
  90%     34
  95%     43
  98%     71
  99%     86
 100%   1039 (longest request)

2、进行1000个并发访问,发出1000000个请求

[root@lb1 ~]# ab -c 1000 -n 1000000 http://blog.benet.com/index.html
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 blog.benet.com (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests


Server Software:        nginx
Server Hostname:        blog.benet.com
Server Port:            80

Document Path:          /index.html
Document Length:        146 bytes

Concurrency Level:      1000
Time taken for tests:   169.644 seconds
Complete requests:      1000000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000000
Total transferred:      289000000 bytes
HTML transferred:       146000000 bytes
Requests per second:    5894.71 [#/sec] (mean)
Time per request:       169.644 [ms] (mean)
Time per request:       0.170 [ms] (mean, across all concurrent requests)
Transfer rate:          1663.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  127 430.7     12   63127
Processing:     3   42  48.5     30    2015
Waiting:        1   37  47.3     25    2004
Total:          5  169 437.0     44   63176

Percentage of the requests served within a certain time (ms)
  50%     44
  66%     56
  75%     69
  80%     82
  90%    258
  95%   1056
  98%   1113
  99%   1260
 100%  63176 (longest request)
 [root@localhost ~]# top
top - 22:58:19 up  3:52,  3 users,  load average: 0.81, 0.23, 0.11
Tasks: 113 total,   2 running, 111 sleeping,   0 stopped,   0 zombie
%Cpu0  :  6.6 us, 31.5 sy,  0.0 ni, 61.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  3.7 us, 15.8 sy,  0.0 ni, 46.5 id,  0.0 wa,  0.0 hi, 34.1 si,  0.0 st
KiB Mem :  1863252 total,  1240008 free,   120596 used,   502648 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1550180 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                    
 31295 root      20   0  281228   3248    968 S  22.6  0.2   0:10.92 nginx                                                                                                                                      
 31297 root      20   0  281180   3260   1060 S  22.6  0.2   0:10.91 nginx                                                                                                                                      
 31296 root      20   0  281048   2988   1056 S  15.9  0.2   0:07.40 nginx                                                                                                                                      
 31298 root      20   0  280916   2996   1036 S  15.9  0.2   0:07.39 nginx          
[root@localhost ~]# top
top - 22:58:31 up  2:28,  2 users,  load average: 1.52, 0.44, 0.19
Tasks: 111 total,   5 running, 106 sleeping,   0 stopped,   0 zombie
%Cpu0  :  8.1 us, 28.2 sy,  0.0 ni, 63.4 id,  0.0 wa,  0.0 hi,  0.4 si,  0.0 st
%Cpu1  :  3.6 us, 14.9 sy,  0.0 ni, 45.5 id,  0.0 wa,  0.0 hi, 36.0 si,  0.0 st
KiB Mem :  1863252 total,  1232120 free,   123276 used,   507856 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1544800 avail Mem 
   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                  
 31782 root      20   0  280432   2632    976 S  21.9  0.1   0:13.91 nginx                                                                                                                                    
 31784 root      20   0  280432   2692   1036 R  21.9  0.1   0:13.87 nginx                                                                                                                                 
 31785 root      20   0  281016   2996    988 R  16.9  0.2   0:09.72 nginx                                                                                                                                      
 31783 root      20   0  281044   2996    960 R  16.6  0.2   0:09.70 nginx                                                                                                                                      
    14 root      20   0       0      0      0 R  10.3  0.0   0:06.80 ksoftirqd/1  

2、webbench测试

1、模拟300个并发连接持续60s

[root@lb1 ~]# webbench -c 300 -t 60 http://blog.benet.com/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://blog.benet.com/index.html
300 clients, running 60 sec.

Speed=405924 pages/min, 1955195 bytes/sec.
Requests: 405924 susceed, 0 failed.
[root@localhost ~]# top
top - 23:09:54 up  4:04,  3 users,  load average: 0.89, 0.54, 0.35
Tasks: 113 total,   4 running, 109 sleeping,   0 stopped,   0 zombie
%Cpu(s):  9.1 us, 31.9 sy,  0.0 ni, 34.0 id,  0.0 wa,  0.0 hi, 25.0 si,  0.0 st
%Node0 :  9.3 us, 31.9 sy,  0.0 ni, 34.0 id,  0.0 wa,  0.0 hi, 24.8 si,  0.0 st
KiB Mem :  1863252 total,  1013728 free,   120636 used,   728888 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1547000 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                    
 31297 root      20   0  281180   3260   1060 R  32.2  0.2   1:06.54 nginx                                                                                                                                      
 31295 root      20   0  281228   3248    968 R  31.9  0.2   1:06.43 nginx                                                                                                                                      
 31296 root      20   0  281048   2988   1056 R  24.3  0.2   0:48.36 nginx                                                                                                                                      
 31298 root      20   0  280916   2996   1036 S  23.6  0.2   0:48.18 nginx     
 [root@localhost ~]# top
top - 23:10:09 up  2:40,  2 users,  load average: 1.66, 0.79, 0.47
Tasks: 111 total,   5 running, 106 sleeping,   0 stopped,   0 zombie
%Cpu0  : 13.1 us, 42.2 sy,  0.0 ni, 44.3 id,  0.0 wa,  0.0 hi,  0.4 si,  0.0 st
%Cpu1  :  6.8 us, 19.4 sy,  0.0 ni, 25.5 id,  0.0 wa,  0.0 hi, 48.2 si,  0.0 st
KiB Mem :  1863252 total,  1003164 free,   123860 used,   736228 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1541224 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                    
 31784 root      20   0  280432   2692   1036 R  31.3  0.1   1:10.83 nginx                                                                                                                                      
 31782 root      20   0  280432   2632    976 R  30.7  0.1   1:10.77 nginx                                                                                                                                      
 31783 root      20   0  281044   2996    960 S  25.0  0.2   0:52.58 nginx                                                                                                                                      
 31785 root      20   0  281016   2996    988 R  24.0  0.2   0:52.68 nginx     

2、模拟5000个并发连接持续60s

[root@lb1 ~]# webbench -c 5000 -t 60 http://blog.benet.com/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://blog.benet.com/index.html
5000 clients, running 60 sec.

Speed=956522 pages/min, 4599838 bytes/sec.
Requests: 956512 susceed, 10 failed.
[root@localhost ~]# top
top - 23:15:06 up  4:09,  3 users,  load average: 0.65, 0.93, 0.62
Tasks: 114 total,   5 running, 109 sleeping,   0 stopped,   0 zombie
%Cpu(s):  8.6 us, 31.5 sy,  0.0 ni, 36.8 id,  0.0 wa,  0.0 hi, 23.1 si,  0.0 st
KiB Mem :  1863252 total,   796524 free,   120420 used,   946308 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1544416 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                    
 31295 root      20   0  281228   3248    968 R  30.9  0.2   2:07.21 nginx                                                                                                                                      
 31297 root      20   0  281180   3260   1060 R  30.2  0.2   2:07.58 nginx                                                                                                                                      
 31296 root      20   0  281048   2988   1056 R  23.3  0.2   1:34.33 nginx                                                                                                                                      
 31298 root      20   0  280916   2996   1036 R  22.6  0.2   1:34.18 nginx                
 [root@localhost ~]# top
top - 23:15:34 up  2:45,  2 users,  load average: 1.12, 1.21, 0.80
Tasks: 112 total,   8 running, 104 sleeping,   0 stopped,   0 zombie
%Cpu0  : 13.9 us, 41.6 sy,  0.0 ni, 44.1 id,  0.0 wa,  0.0 hi,  0.4 si,  0.0 st
%Cpu1  :  6.0 us, 22.5 sy,  0.0 ni, 23.2 id,  0.0 wa,  0.0 hi, 48.2 si,  0.0 st
KiB Mem :  1863252 total,   771432 free,   123768 used,   968052 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1538088 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                    
 31782 root      20   0  280432   2632    976 R  31.2  0.1   2:15.77 nginx                                                                                                                                      
 31784 root      20   0  280432   2692   1036 R  31.2  0.1   2:16.02 nginx                                                                                                                                      
 31783 root      20   0  281044   2996    960 R  25.2  0.2   1:42.50 nginx                                                                                                                                      
 31785 root      20   0  281016   2996    988 R  25.2  0.2   1:42.55 nginx      
                                                                                                                     
 31784 root      20   0  280432   2692   1036 R  31.2  0.1   2:16.02 nginx                                                                                                                                      
 31783 root      20   0  281044   2996    960 R  25.2  0.2   1:42.50 nginx                                                                                                                                      
 31785 root      20   0  281016   2996    988 R  25.2  0.2   1:42.55 nginx      

你可能感兴趣的:(nginx,mysql,linux)