安装部署LNMP/大并发nginx优化/php性能加速 实战

安装部署LNMP及Nginx优化、PHP加速进行压力测试

部署LNMP环境:


主机


IP


主机名


Centos7.2


192.168.5.128


www.benet.com

部署步骤如下:

使用yum仓库安装Nginx依赖包

yum -y install  gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel

创建Nginx用户 组解压Nginx软件包

编译安装Nginx

./configure --prefix=/usr/local/nginx1.10 --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx && make &&make install

修改配置文件 全部配置文件内容如下:

user nginx nginx;

worker_processes  4;

worker_cpu_affinity 0001 0010 0100 1000;

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {

use epoll;

worker_connections  65535;

multi_accept on;

}

http {

include       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  logs/access.log  main;

sendfile        on;

tcp_nopush     on;

keepalive_timeout  65;

tcp_nodelay on;

client_header_buffer_size 4k;

open_file_cache max=102400 inactive=20s;

open_file_cache_valid 30s;

open_file_cache_min_uses 1;

client_header_timeout 15;

client_body_timeout 15;

reset_timedout_connection on;

send_timeout 15;

server_tokens off;

client_max_body_size 10m;

fastcgi_connect_timeout     600;

fastcgi_send_timeout 600;

fastcgi_read_timeout 600;

fastcgi_buffer_size 64k;

fastcgi_buffers     4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

fastcgi_temp_path /usr/local/nginx1.10/nginx_tmp;

fastcgi_intercept_errors on;

fastcgi_cache_path /usr/local/nginx1.10/fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128m inactive=1d max_size=10g;

gzip on;

gzip_min_length  2k;

gzip_buffers     4 32k;

gzip_http_version 1.1;

gzip_comp_level 6;

gzip_types  text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;

gzip_vary on;

gzip_proxied any;

server {

listen       80;

server_name  www.benet.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

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;

}

location / {

root   html;

index  index.php index.html index.htm;

}

location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ {

expires 30d;

#log_not_found off;

access_log off;

}

location ~* \.(js|css)$ {

expires 7d;

log_not_found off;

access_log off;

}

location = /(favicon.ico|roboots.txt) {

access_log off;

log_not_found off;

}

location /status {

stub_status on;

}

location ~ .*\.(php|php5)?$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

#          fastcgi_cache cache_fastcgi;

fastcgi_cache_valid 200 302 1h;

fastcgi_cache_valid 301 1d;

fastcgi_cache_valid any 1m;

fastcgi_cache_min_uses 1;

fastcgi_cache_use_stale error timeout invalid_header http_500;

fastcgi_cache_key http://$host$request_uri;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

建立一个软连接 启动Nginx服务 查看端口号是否开启

测试能不能访问到测试页

二进制安装mysql--解压mysql二进制包并且创建用户mysql

删除centos7中带的数据库避免发生冲突

编写配置/etc/my.cnf文件

创建下面的数据文件和log日志文件

添加权限给data文件 并且授予mysql文件为属主属组 创建软连接

初始化mysql

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

查看log日志中生成的密码 下面登录时会用到

复制启动文件到/etc/init.d/下

登录mysql数据库

使用yum安装php依赖包

需要的安装包例如:

编译安装libmcrypt

编译安装PHP软件包

复制PHP配置文件及设置自启动PHP

修改PHP配置文件

修改/usr/local/php5.6/etc/php.fpm.conf下面几项

pid = run/php-fpm.pid

listen = 0.0.0.0:9000

pm.max_children =300

pm.start_servers =20

pm.min_spare_servers = 20

pm.max_spare_servers = 100

启动PHP服务

设置防火墙允许9000端口经过

创建PHP测试页

测试是否能访问php页面

测试防盗链 首先在被盗主机上的网页确保有图片 比如:

然后设置域名www.benet.com

设置另一台主机为www.test.com

并且编写盗网页的编码

访问网页看是否能盗 因为在被盗主机www.benet.com中设置了防盗链 这时不能盗

点击链接lianjie查看测试成功是否

测试为成功 防盗链起效

使用yum安装httpd-tools包进行压力测试

测试压力 能够承受多大的压力

ab -c 600 -n 60000 http://192.168.5.128/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 192.168.5.128 (be patient)

Completed 6000 requests

Completed 12000 requests

Completed 18000 requests

Completed 24000 requests

Completed 30000 requests

Completed 36000 requests

Completed 42000 requests

Completed 48000 requests

Completed 54000 requests

Completed 60000 requests

Finished 60000 requests

Server Software:        nginx

Server Hostname:        192.168.5.128

Server Port:            80

Document Path:          /index.html

Document Length:        632 bytes

Concurrency Level:      600

Time taken for tests:   6.787 seconds

Complete requests:      60000

Failed requests:        0

Write errors:           0

Total transferred:      51480000 bytes

HTML transferred:       37920000 bytes

Requests per second:    8841.04 [#/sec] (mean)

Time per request:       67.865 [ms] (mean)

Time per request:       0.113 [ms] (mean, across all concurrent requests)

Transfer rate:          7407.83 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0   30  48.6     28    1039

Processing:     7   37   8.2     36      73

Waiting:        1   28   8.5     27      61

Total:         46   67  49.3     65    1073

Percentage of the requests served within a certain time (ms)

50%     65

66%     68

75%     71

80%     72

90%     76

95%     79

98%     82

99%     86

100%   1073 (longest request)

进行第二次测试 查看变化情况

[[email protected] html]# ab -c 600 -n 60000 http://192.168.5.128/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 192.168.5.128 (be patient)

Completed 6000 requests

Completed 12000 requests

Completed 18000 requests

Completed 24000 requests

Completed 30000 requests

Completed 36000 requests

Completed 42000 requests

Completed 48000 requests

Completed 54000 requests

Completed 60000 requests

Finished 60000 requests

Server Software:        nginx

Server Hostname:        192.168.5.128

Server Port:            80

Document Path:          /index.html

Document Length:        632 bytes

Concurrency Level:      600

Time taken for tests:   6.640 seconds

Complete requests:      60000

Failed requests:        0

Write errors:           0

Total transferred:      51480000 bytes

HTML transferred:       37920000 bytes

Requests per second:    9035.60 [#/sec] (mean) ##此值越大代表带宽浪费的越少

Time per request:       66.404 [ms] (mean)

Time per request:       0.111 [ms] (mean, across all concurrent requests)

Transfer rate:          7570.85 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0   29  24.1     28    1030

Processing:     8   37   7.9     37     254

Waiting:        5   28   8.5     28     238

Total:         37   66  24.7     64    1074

Percentage of the requests served within a certain time (ms)

50%     64

66%     68

75%     70

80%     72

90%     76

95%     79

98%     83

99%     85

100%   1074 (longest request)

编译安装xcache加速PHP

./configure --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/local/php5.6/bin/php-config &&make &&make install

编译安装完(就在编译安装后的最后一行)后要记住下面黄色字体

创建xcache缓存文件 把后台管理程序存放到网站根目录下 添加配置文件php.ini

在/etc/php.ini的最后面添加就可以

重启php.ini服务

测试能否打开xcache

进行php动态网页做压力测试

ab -c 1000 -n 100000 http://192.168.5.128/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 192.168.5.128 (be patient)

Completed 10000 requests

Completed 20000 requests

Completed 30000 requests

Completed 40000 requests

Completed 50000 requests

Completed 60000 requests

Completed 70000 requests

Completed 80000 requests

Completed 90000 requests

Completed 100000 requests

Finished 100000 requests

Server Software:        nginx

Server Hostname:        192.168.5.128

Server Port:            80

Document Path:          /index.html

Document Length:        632 bytes

Concurrency Level:      1000

Time taken for tests:   10.658 seconds

Complete requests:      100000

Failed requests:        0

Write errors:           0

Total transferred:      85800000 bytes

HTML transferred:       63200000 bytes

Requests per second:    9383.02 [#/sec] (mean)

Time per request:       106.576 [ms] (mean)

Time per request:       0.107 [ms] (mean, across all concurrent requests)

Transfer rate:          7861.94 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        4   53 109.1     42    1062

Processing:    11   53  15.4     54     216

Waiting:        1   40  14.5     39     210

Total:         26  105 110.8     99    1133

Percentage of the requests served within a certain time (ms)

50%     99

66%    103

75%    106

80%    108

90%    113

95%    117

98%    124

99%   1062

100%   1133 (longest request)

时间: 2024-10-21 05:14:29

安装部署LNMP/大并发nginx优化/php性能加速 实战的相关文章

Python实现一键安装部署LNMP环境

最近一直在学Python,东西比较多,时间持续的也比较长,为了能够学以致用,想到了原来写过的shell一键安装部署LNMP脚本,既然shell能写,Python也一定能写,就用学到的知识写了下面这个版本,这可能并不是最优版本,等学到更多东西的时候再进行优化升级! 环境介绍: Python 2.6.6 Centos 6.5 nginx 1.10.1 mysql 5.6.34 php 5.3.3 代码如下: #!/bin/env python import os import sys def ent

CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)

CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: 1 /etc/init.d/iptables stop #关闭防火墙 2 关闭SELINUX 3 vi /etc/selinux/config 4 #SELINUX=enforcing #注释掉 5 #SELINUXTYPE=targeted #注释掉 6 SELINUX=disabled #增加 7 :wq 8 shutdown -r now #重启系统 二.安装篇 1.安装nginx 1 yum re

CentOS 6.4 安装配置LNMP服务器(Nginx+PHP+MySQL) 及搭建Wordpress

准备:1.配置防火墙,开启80端口.3306端口 # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state –state ESTABLISHED,RE

CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)

服务器环境为:CentOS6.5 64位 目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码 相关目录:所有软件都安装到/www/目录下,在www目录下新建web文件夹作为网站的根路径,www目录下新建wwwsvn作为svn的仓库地址./www/software用来放nginx,mysql,php的安装包和源码.nginx运行分组和账户www:www 一,安装前的准备 yum -y install ntp m

CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)

准备篇 1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙 备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败, 正确

CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)【转】

转自:http://blog.csdn.net/yanzi1225627/article/details/49123659 服务器环境为:CentOS6.5 64位 目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码 相关目录:所有软件都安装到/www/目录下,在www目录下新建web文件夹作为网站的根路径,www目录下新建wwwsvn作为svn的仓库地址./www/software用来放nginx,mysq

centos6.8下安装部署LNMP(备注:nginx1.8.0+php5.6.10+mysql5.6.12)

在平时运维工作中,经常需要用到LNMP应用框架.以下对LNMP环境部署记录下: 1)前期准备:为了安装顺利,建议先使用yum安装依赖库[[email protected] ~]#yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zlib libxml2-devel ncurses-devel bison libtool-ltdl-devel libiconv libmcrypt m

大并发内核优化参数

如何分析系统的性能问题: 从以下几个维度进行考虑 当并发压力加大时,往往是吞吐量上不去,肯定是某一个方面出现了瓶颈,(比如CPU,内存(大量的swap),磁盘IO,网络IO,操作系统,应用) 如果CPU比较高(user,sys,wa),user高,可以把系统的线程dump出来,观察系统正在做的逻辑,优化逻辑:sys高,则说明kernel耗费了大量的CPU时间,比如当前的线程的切换比较厉害等等:wa高一般是IO操作比较频繁,CPU频繁调度 查看CPU,还需要观察系统load,一般不要超过系统的物理

CentOS6.2 yum安装配置lnmp服务器(Nginx+PHP+MySQL)

1.配置防火墙,开启80端口.3306端口        vi /etc/sysconfig/iptables        -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)        -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过防火墙) 特别提示:很多网友把这两条规则添加到防火