1.安装nginx
##修改yum源
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
##安装
yum install nginx -y
##添加状态监控
[root@storm-nimbus-a conf.d]#vi /etc/nginx/conf.d/ default.conf
…
location /nginx_status{
stub_status on;
access_log off;
}
2.安装php
yum install php php-gd php-soap php-mbstring php-xmlrpc php-dom php-fpm –y
3.nginx整合php-fpm
##修改/etc/php-fpm.d/www.conf文件中的user和group,与nginx.conf中的user一致。
user = nginx
group = nginx
##需要和nginx的用户对应起来
cat /etc/nginx/nginx.conf
…
user nginx;
…
4.启动php-fpm服务
## systemctl start php-fpm 或 service php-fpm start
[root@storm-nimbus-a conf.d]# service php-fpm start
Starting php-fpm: [ OK ]
##查看9000端口是否在监听:netstat -nap | grep 9000
[root@storm-nimbus-a conf.d]# netstat -nap | grep 9000
tcp 127.0.0.1:9000 0.0.0.0:* LISTEN 17594/php-fpm
5.修改nginx的配置
vi /etc/nginx/conf.d/default.conf
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
6.重启nginx
nginx -s reload
7.编写index.php
cd /usr/share/nginx/html
[root@localhost php]# vi index.php
<?php phpinfo(); ?>
8.打开浏览器访问(firefox)
http://192.168.19.20/index.php
9.安装rrdtool相关依赖
yum install perl rrdtool perl-libwww-perl libwww-perl perl-rrdtool –y
10.安装nginx-rdd
##下载
wget http://soft.vpser.net/status/nginx-rrd/nginx-rrd-0.1.4.tgz
##安装
[root@storm-nimbus-a tmp]# cp -r /opt/nginx-rrd-0.1.4.tgz /tmp/
[root@storm-nimbus-a tmp]# tar -xzvf nginx-rrd-0.1.4.tgz
[root@storm-nimbus-a tmp]# cd nginx-rrd-0.1.4
##复制主程序文件到 /usr/sbin 下
[root@storm-nimbus-a nginx-rrd-0.1.4]# cp usr/sbin/* /usr/sbin
##复制配置文件到 /etc 下
[root@storm-nimbus-a nginx-rrd-0.1.4]# cp etc/nginx-rrd.conf /etc
##复制index.php到/usr/share/nginx/html/ 下
[root@storm-nimbus-a nginx-rrd-0.1.4]# cp html/index.php /usr/share/nginx/html/
11.修改配置vi /etc/nginx-rrd.conf
## RRD将收集的数据放到RRD_DIR,生成的图片放到WWW_DIR下
RRD_DIR="/usr/share/nginx/html/nginx-rrd";
WWW_DIR="/usr/share/nginx/html";
12.分析相关shell
##任务调度
cat etc/cron.d/nginx-rrd.cron
* * * * * root /usr/sbin/nginx-collect
*/15 * * * * root /usr/sbin/nginx-graph
## nginx-collect脚本
[root@storm-nimbus-a cron.d]# cat /usr/sbin/nginx-collect
#!/bin/bash
if [ ! -f /etc/nginx-rrd.conf ]; then
echo "Missing config file";
break;
fi
. /etc/nginx-rrd.conf
if [ ! -d $RRD_DIR ]; then
mkdir -p $RRD_DIR
fi
for SERVER in $SERVERS_URL; do
CURR_URL=`echo $SERVER | awk -F";" ' { print $1 } '`
CURR_NAME=`echo $SERVER | awk -F";" ' { print $2 } '`
nice -n $NICE_LEVEL $BIN_DIR/nginx-collect.pl $RRD_DIR $WWW_DIR $CURR_URL $CURR_NAME
done
## nginx-rrd.conf
RRD_DIR="/usr/share/nginx/html/nginx-rrd";
WWW_DIR="/usr/share/nginx/html";
##监控的nginx
SERVERS_URL="http://127.0.0.1/nginx_status;127.0.0.1 http://localhost/nginx_status;localhost"
13. 新建定时任务
需要定时来进行采集数据
##编辑定时任务
[root@storm-nimbus-a cron.d]# crontab -e
* * * * * /bin/sh /usr/sbin/nginx-collect
*/1 * * * * /bin/sh /usr/sbin/nginx-graph
##查询定时任务
[root@storm-nimbus-a cron.d]# crontab -l
* * * * * /bin/sh /usr/sbin/nginx-collect
*/1 * * * * /bin/sh /usr/sbin/nginx-graph
##查看定时任务的执行情况
tail -f /var/log/cron
14. ab压测
##安装ab压测工具
yum -y install httpd-tools
##指令:10个并发,总共发10000个请求来访问…/index.html
[root@storm-nimbus-a cron.d]# ab -n 10000 -c 10 http://127.0.0.1/index.html
…
Benchmarking 127.0.0.1 (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
…
连接信息
值有置后,因为是定时任务执行的