您好,登錄后才能下訂單哦!
八、監控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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。