1.部署PHP服务
#上传php7.2版本的安装包
[root@web01 ~]# ls -l php72.tar.gz
-rw-r--r-- 1 root root 16568111 2020-03-30 16:24 php72.tar.gz
#解压、安装、启动
[root@web01 ~/opt]# tar xf php72.tar.gz
[root@web01 ~/opt]# yum localinstall -y /root/opt/php/packages/*.rpm
[root@web01 ~/opt]# systemctl start php-fpm.service
#配置php配置文件(大概在217行)
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
pm.status_path = /phpfpm_status
2.nginx配置文件
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ~ ^/(phpfpm_status)$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
allow 127.0.0.1;
deny all;
}
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
#重启nginx服务及php-fpm服务
[root@web01 ~]# systemctl restart nginx php-fpm.service
3.curl命令测试
[root@web01 ~]# curl http://127.0.0.1/phpfpm_status
pool: www
process manager: dynamic
start time: 21/May/2020:10:11:13 +0800
start since: 44
accepted conn: 1
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 4
active processes: 1
total processes: 5
max active processes: 1
max children reached: 0
slow requests: 0
4.编写监听脚本并赋予权限
[root@web01 /server/scripts]# vim phpfpm_status.sh
#!/bin/bash
PHPFPM_COMMAND=$1
PHPFPM_PORT=80
start_since(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^start since:/ {print $NF}'
}
accepted_conn(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^accepted conn:/ {print $NF}'
}
listen_queue(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue:/ {print $NF}'
}
max_listen_queue(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max listen queue:/ {print $NF}'
}
listen_queue_len(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue len:/ {print $NF}'
}
idle_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^idle processes:/ {print $NF}'
}
active_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^active processes:/ {print $NF}'
}
total_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^total processes:/ {print $NF}'
}
max_active_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max active processes:/ {print $NF}'
}
max_children_reached(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max children reached:/ {print $NF}'
}
slow_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^slow requests:/ {print $NF}'
}
case $PHPFPM_COMMAND in
start_since)
start_since;
;;
accepted_conn)
accepted_conn;
;;
listen_queue)
listen_queue;
;;
max_listen_queue)
max_listen_queue;
;;
listen_queue_len)
listen_queue_len;
;;
idle_processes)
idle_processes;
;;
active_processes)
active_processes;
;;
total_processes)
total_processes;
;;
max_active_processes)
max_active_processes;
;;
max_children_reached)
max_children_reached;
;;
slow_requests)
slow_requests;
;;
*)
echo $"USAGE:$0 {start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached|slow_requests}"
esac
#赋予脚本执行权限
[root@web01 /server/scripts]# chmod +x phpfpm_status.sh
5.编写zabbix监控项
#编写监控项代码
[root@web01 /server/scripts]# cat /etc/zabbix/zabbix_agentd.d/phpfpm_status.conf
UserParameter=phpfpm_status[*],/bin/bash /server/scripts/phpfpm_status.sh "$1"
#重启zabbix客户端
[root@web01 /server/scripts]# systemctl restart zabbix-agent
#zabbix客户端获取值测试
[root@web01 /server/scripts]# zabbix_agentd -t phpfpm_status[start_since]
phpfpm_status[start_since] [t|98]
#zabbix服务端获取值测试
[root@zabbix-server ~]# zabbix_get -s 172.16.1.7 -k phpfpm_status[slow_requests]
0
6.导入监控php状态模板
7.创建监控项(监控tcp80端口)
8.查看php_fpm status模板监控项(并且后面必须是已启动的)
9.被控主机关联链接模板
10.查看监控php服务的状态(等待30左右,若有数据则成功)