您好,登录后才能下订单哦!
八、监控Nginx、httpd、Tomcat、php-fpm、Redis、MySQL和网页访问、响应速度:
1、监控Nginx:
(1)node-122节点安装Nginx
(2)开启Nginx状态页面:
# cd /etc/nginx
# cp nginx.conf{,.bak}
# vim nginx.conf,在server配置段中新增如下代码:
location = /nginx_status {
stub_status;
}
# nginx -t
# systemctl start nginx
# systemctl status nginx
(3)浏览器访问状态页面:http://192.168.0.122/nginx_status
说明:页面状态信息
Active connections:当前活动的客户端连接数,包括Waiting连接数
accepts:接收的客户端连接总数
handled:已处理的连接总数,通常该值与accepts的值相同,除非达到某些资源限制,如worker_connections
requests:客户端请求总数
Reading:Nginx正在读取请求头的当前连接数
Writing:Nginx正在将响应写回到客户端的当前连接数
Waiting:当前等待请求的空闲客户端连接数
(4)将nginx_monitor.sh脚本文件上传至/scripts目录,并赋予执行权限:# chmod +x /scripts/nginx_monitor.sh
(5)将nginx_status.conf配置文件上传至/etc/zabbix/zabbix_agentd.d目录,并重启Zabbix Agent:
# systemctl restart zabbix-agent
(6)zabbix-server节点使用zabbix-get进行取值测试:
# zabbix_get -s 192.168.0.122 -k nginx_status[active]
# zabbix_get -s 192.168.0.122 -k nginx_status[accepts]
# zabbix_get -s 192.168.0.122 -k nginx_status[requests]
如果出现上述错误提示,node-122节点删除/tmp/nginx_status.txt文件即可
(7)Zabbix Web导入Nginx监控模板zbx_nginx_templates.xml:
Configuration --> Templates --> Import --> Import
模板中默认定义的Nginx端口为80:
(8)node-122节点链接Nginx监控模板:
勾选所有Nginx监控项,点击“Check now”:
(9)查看最新监控数据:
2、监控httpd:
(1)node-122节点安装httpd
(2)https://github.com/lorf/zapache下载监控httpd时需要用到的脚本文件、配置文件和模板文件
(3)将httpd-server-status.conf配置文件上传至/etc/httpd/conf.d目录,开启httpd状态页面
说明:httpd-server-status.conf已经包含如下配置
# httpd -t
# systemctl start httpd
# systemctl status httpd
(4)浏览器访问状态页面:
http://192.168.0.122/server-status 或 http://192.168.0.122/server-status?auto&refresh=3
(5)将zapache脚本文件上传至/scripts目录,并赋予执行权限:# chmod +x /scripts/zapache
(6)将userparameter_zapache.conf配置文件上传至/etc/zabbix/zabbix_agentd.d目录,并重启Zabbix Agent:
# systemctl restart zabbix-agent
(7)zabbix-server节点使用zabbix-get进行取值测试:
# zabbix_get -s 192.168.0.122 -k zapache[Uptime]
# zabbix_get -s 192.168.0.122 -k zapache[ping]
(8)Zabbix Web导入httpd监控模板zapache-template-active.xml:
(9)node-122节点链接httpd监控模板:
勾选所有httpd监控项,点击“Check now”:
(10)查看最新监控数据:
3、通过JMX监控Tomcat:
(1)node-122节点安装JDK和Tomcat
(2)配置Tomcat支持JMX:
# vim /usr/local/tomcat/bin/catalina.sh,在首行#!/bin/sh下方新增如下代码:
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=192.168.0.122
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"
说明:
-Dcom.sun.management.jmxremote:启用远程监控JVM
-Djava.rmi.server.hostname=192.168.0.122:Tomcat的IP地址,而非Zabbix Server的IP地址
-Dcom.sun.management.jmxremote.port=12345:默认启动的JMX端口号
-Dcom.sun.management.jmxremote.ssl=false:不使用SSL认证
-Dcom.sun.management.jmxremote.authenticate=false:不使用用户名密码认证
CATALINA_OPTS和JAVA_OPTS的区别:
CATALINA_OPTS:只被Tomcat使用
JAVA_OPTS:被所有Java应用程序使用
# /usr/local/tomcat/bin/catalina.sh configtest
# /usr/local/tomcat/bin/startup.sh
# ss -tunlp | grep -w :12345
(3)node-122节点安装Zabbix Java Gateway:# yum -y install zabbix-java-gateway
(4)node-122节点修改zabbix_java_gateway.conf配置文件:
# cd /etc/zabbix
# cp zabbix_java_gateway.conf{,.bak}
# vim zabbix_java_gateway.conf
修改前 | 修改后 |
# LISTEN_IP="0.0.0.0" | LISTEN_IP="192.168.0.122" |
# LISTEN_PORT=10052 | LISTEN_PORT=10052 |
# START_POLLERS=5 | START_POLLERS=5 |
# TIMEOUT=3 | TIMEOUT=10 |
(5)node-122节点启动Zabbix Java Gateway:
# systemctl start zabbix-java-gateway
# systemctl status zabbix-java-gateway
# ss -tunlp | grep -w :10052
# systemctl enable zabbix-java-gateway
(6)zabbix-server节点修改zabbix_server.conf配置文件:
# vim /etc/zabbix/zabbix_server.conf
修改前 | 修改后 |
# JavaGateway= | JavaGateway=192.168.0.122 |
# JavaGatewayPort=10052 | JavaGatewayPort=10052 |
# StartJavaPollers=0 | StartJavaPollers=5 |
# systemctl restart zabbix-server
备注:StartJavaPollers的值要小于等于START_POLLERS的值
(7)Zabbix Web添加node-122节点的JMX监控接口:
说明:IP为Zabbix Java Gateway所部署服务器的IP,端口为Tomcat中配置的JMX远程端口
(8)node-122节点链接Tomcat监控模板:
(9)查看最新监控数据:
4、监控php-fpm:
(1)node-122节点安装php-fpm
(2)修改www.conf配置文件:
# cd /etc/php-fpm.d
# cp www.conf{,.bak}
# vim www.conf
修改前 | 修改后 |
user = apache | user = nginx |
group = apache | group = nginx |
;pm.status_path = /status | pm.status_path = /php-fpm_status |
(3)开启php-fpm状态页面:
# vim /etc/nginx/nginx.conf,在server配置段中新增如下代码:
location / {
root html;
index index.php index.html index.htm;
}
location = /php-fpm_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# nginx -t
# systemctl restart nginx php-fpm
# ss -tunlp | grep -w :80
# ss -tunlp | grep -w 9000
(4)浏览器访问状态页面:http://192.168.0.122/php-fpm_status
(5)将php-fpm_monitor.sh脚本文件上传至/scripts目录,并赋予执行权限:
# chmod +x /scripts/php-fpm_monitor.sh
(6)将php-fpm_status.conf配置文件上传至/etc/zabbix/zabbix_agentd.d目录,并重启Zabbix Agent:
# systemctl restart zabbix-agent
(7)zabbix-server节点使用zabbix-get进行取值测试:
# zabbix_get -s 192.168.0.122 -k php-fpm_status["active processes",http://192.168.0.122/php-fpm_status]
# zabbix_get -s 192.168.0.122 -k php-fpm_status["total processes",http://192.168.0.122/php-fpm_status]
# zabbix_get -s 192.168.0.122 -k php-fpm_status["max active processes",http://192.168.0.122/php-fpm_status]
(8)Zabbix Web导入php-fpm监控模板zbx_php-fpm_templates.xml:
(9)node-122节点链接php-fpm监控模板:
勾选所有php-fpm监控项,点击“Check now”:
(10)查看最新监控数据:
5、监控Redis:
(1)node-122节点安装Redis
(2)查看Redis状态信息:
# redis-cli info
(3)将redis_monitor.sh脚本文件上传至/scripts目录,并赋予执行权限:# chmod +x /scripts/redis_monitor.sh
(4)将redis_status.conf配置文件上传至/etc/zabbix/zabbix_agentd.d目录,并重启Zabbix Agent:
# systemctl restart zabbix-agent
(5)zabbix-server节点使用zabbix-get进行取值测试:
# zabbix_get -s 192.168.0.122 -k redis[127.0.0.1,rejected_connections,none]
(6)Zabbix Web导入Redis监控模板zbx_redis_templates.xml:
(7)node-122节点链接Redis监控模板:
勾选所有Redis监控项,点击“Check now”:
(8)查看最新监控数据:
6、使用Percona插件监控MySQL:
(1)node-122节点安装php、php-mysql和MySQL
备注:由于Percona的监控插件是php编写的,所以需要在被监控端安装php和php-mysql
(2)node-122节点下载安装插件:https://www.percona.com/downloads/percona-monitoring-plugins/LATEST/
# rpm -ivh https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm
# rpm -ql percona-zabbix-templates
备注:
脚本文件:/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
php文件:/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
配置文件:/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
模板文件:/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml,内置模板匹配的Zabbix版本为2.0,在4.0版本中不能使用,网上另行下载的zbx_percona_mysql_templates.xml
(3)将userparameter_percona_mysql.conf配置文件复制至/etc/zabbix/zabbix_agentd.d目录:
# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
(4)重启Zabbix Agent:# systemctl restart zabbix-agent
(5)修改ss_get_mysql_stats.php文件中的数据库连接信息:
# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = '123456';
(6)zabbix-server节点使用zabbix-get进行取值测试:
# zabbix_get -s 192.168.0.122 -k MySQL.Open-files
# zabbix_get -s 192.168.0.122 -k MySQL.Com-select
# zabbix_get -s 192.168.0.122 -k MySQL.slave-running
(7)Zabbix Web导入Percona MySQL监控模板zbx_percona_mysql_templates.xml:
备注:共191个监控项
(8)node-122节点链接Percona MySQL监控模板:
勾选所有Percona MySQL监控项,点击“Check now”:
其中1个有关主从复制的监控项,提示:
解决方案,修改node-122节点上MySQL配置文件:
# vim /etc/my.cnf,末尾新增如下代码:
[client]
user=root
password=123456
node-122节点重启MySQL:# systemctl restart mysqld
zabbix-server节点重新加载Zabbix Server配置缓存(功能类似于重启Zabbix Server):
# zabbix_server -R config_cache_reload
(9)查看最新监控数据:
备注:Zabbix还自带了一个监控MySQL的名为“Template DB MySQL”的模板,也可按上述方法进行使用
7、监控网页的访问速度和响应速度:
(1)node-122节点搭建LNMP环境,部署WordPress
(2)Zabbix Web创建node-122节点Web场景:
Configuration --> Hosts --> Web --> Create web scenario --> Add
说明:User agent string的来源
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
备注:Required string的来源
备注:Raw post的来源
WordPress默认登录页面:http://192.168.0.122/wordpress/wp-login.php
按Chrome浏览器F12,输入一个错误的密码,点击登录:
log=root&pwd=root@123&wp-submit=%E7%99%BB%E5%BD%95&redirect_to=http%3A%2F%2F192.168.0.122%2Fwordpress%2Fwp-admin%2F&testcookie=1
将错误密码替换为正确密码
(3)查看最新监控数据:
Monitoring --> Web --> WordPress
(4)创建触发器:
Web是特殊的监控项,直接添加触发器
Configuration --> Hosts --> Triggers --> Create trigger --> Add
(5)zabbix-server节点使用ab命令模拟访问node-122节点上的WordPress:
# yum provides ab
# yum -y install httpd-tools
# ab -n 10000 -c 20 http://192.168.0.122/wordpress/wp-login.php
常用选项:
-c:一次并发执行的请求个数,默认是一次一个请求
-n:执行的请求总数
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。