八、監(jiān)控Nginx、httpd、Tomcat、php-fpm、Redis、MySQL和網(wǎng)頁訪問、響應(yīng)速度:
硯山網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),硯山網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為硯山超過千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的硯山做網(wǎng)站的公司定做!1、監(jiān)控Nginx:
(1)node-122節(jié)點(diǎn)安裝Nginx
(2)開啟Nginx狀態(tài)頁面:
# 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)瀏覽器訪問狀態(tài)頁面:http://192.168.0.122/nginx_status
說明:頁面狀態(tài)信息
Active connections:當(dāng)前活動的客戶端連接數(shù),包括Waiting連接數(shù)
accepts:接收的客戶端連接總數(shù)
handled:已處理的連接總數(shù),通常該值與accepts的值相同,除非達(dá)到某些資源限制,如worker_connections
requests:客戶端請求總數(shù)
Reading:Nginx正在讀取請求頭的當(dāng)前連接數(shù)
Writing:Nginx正在將響應(yīng)寫回到客戶端的當(dāng)前連接數(shù)
Waiting:當(dāng)前等待請求的空閑客戶端連接數(shù)
(4)將nginx_monitor.sh腳本文件上傳至/scripts目錄,并賦予執(zhí)行權(quán)限:# chmod +x /scripts/nginx_monitor.sh
(5)將nginx_status.conf配置文件上傳至/etc/zabbix/zabbix_agentd.d目錄,并重啟Zabbix Agent:
# systemctl restart zabbix-agent
(6)zabbix-server節(jié)點(diǎn)使用zabbix-get進(jìn)行取值測試:
# 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]
如果出現(xiàn)上述錯誤提示,node-122節(jié)點(diǎn)刪除/tmp/nginx_status.txt文件即可
(7)Zabbix Web導(dǎo)入Nginx監(jiān)控模板zbx_nginx_templates.xml:
Configuration --> Templates --> Import --> Import
模板中默認(rèn)定義的Nginx端口為80:
(8)node-122節(jié)點(diǎn)鏈接Nginx監(jiān)控模板:
勾選所有Nginx監(jiān)控項,點(diǎn)擊“Check now”:
(9)查看最新監(jiān)控數(shù)據(jù):
2、監(jiān)控httpd:
(1)node-122節(jié)點(diǎn)安裝httpd
(2)https://github.com/lorf/zapache下載監(jiān)控httpd時需要用到的腳本文件、配置文件和模板文件
(3)將httpd-server-status.conf配置文件上傳至/etc/httpd/conf.d目錄,開啟httpd狀態(tài)頁面
說明:httpd-server-status.conf已經(jīng)包含如下配置
# httpd -t
# systemctl start httpd
# systemctl status httpd
(4)瀏覽器訪問狀態(tài)頁面:
http://192.168.0.122/server-status 或 http://192.168.0.122/server-status?auto&refresh=3
(5)將zapache腳本文件上傳至/scripts目錄,并賦予執(zhí)行權(quán)限:# chmod +x /scripts/zapache
(6)將userparameter_zapache.conf配置文件上傳至/etc/zabbix/zabbix_agentd.d目錄,并重啟Zabbix Agent:
# systemctl restart zabbix-agent
(7)zabbix-server節(jié)點(diǎn)使用zabbix-get進(jìn)行取值測試:
# zabbix_get -s 192.168.0.122 -k zapache[Uptime]
# zabbix_get -s 192.168.0.122 -k zapache[ping]
(8)Zabbix Web導(dǎo)入httpd監(jiān)控模板zapache-template-active.xml:
(9)node-122節(jié)點(diǎn)鏈接httpd監(jiān)控模板:
勾選所有httpd監(jiān)控項,點(diǎn)擊“Check now”:
(10)查看最新監(jiān)控數(shù)據(jù):
3、通過JMX監(jiān)控Tomcat:
(1)node-122節(jié)點(diǎn)安裝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:啟用遠(yuǎn)程監(jiān)控JVM
-Djava.rmi.server.hostname=192.168.0.122:Tomcat的IP地址,而非Zabbix Server的IP地址
-Dcom.sun.management.jmxremote.port=12345:默認(rèn)啟動的JMX端口號
-Dcom.sun.management.jmxremote.ssl=false:不使用SSL認(rèn)證
-Dcom.sun.management.jmxremote.authenticate=false:不使用用戶名密碼認(rèn)證
CATALINA_OPTS和JAVA_OPTS的區(qū)別:
CATALINA_OPTS:只被Tomcat使用
JAVA_OPTS:被所有Java應(yīng)用程序使用
# /usr/local/tomcat/bin/catalina.sh configtest
# /usr/local/tomcat/bin/startup.sh
# ss -tunlp | grep -w :12345
(3)node-122節(jié)點(diǎn)安裝Zabbix Java Gateway:# yum -y install zabbix-java-gateway
(4)node-122節(jié)點(diǎn)修改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節(jié)點(diǎn)啟動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節(jié)點(diǎn)修改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節(jié)點(diǎn)的JMX監(jiān)控接口:
說明:IP為Zabbix Java Gateway所部署服務(wù)器的IP,端口為Tomcat中配置的JMX遠(yuǎn)程端口
(8)node-122節(jié)點(diǎn)鏈接Tomcat監(jiān)控模板:
(9)查看最新監(jiān)控數(shù)據(jù):
4、監(jiān)控php-fpm:
(1)node-122節(jié)點(diǎn)安裝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狀態(tài)頁面:
# 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)瀏覽器訪問狀態(tài)頁面:http://192.168.0.122/php-fpm_status
(5)將php-fpm_monitor.sh腳本文件上傳至/scripts目錄,并賦予執(zhí)行權(quán)限:
# 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節(jié)點(diǎn)使用zabbix-get進(jìn)行取值測試:
# 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導(dǎo)入php-fpm監(jiān)控模板zbx_php-fpm_templates.xml:
(9)node-122節(jié)點(diǎn)鏈接php-fpm監(jiān)控模板:
勾選所有php-fpm監(jiān)控項,點(diǎn)擊“Check now”:
(10)查看最新監(jiān)控數(shù)據(jù):
5、監(jiān)控Redis:
(1)node-122節(jié)點(diǎn)安裝Redis
(2)查看Redis狀態(tài)信息:
# redis-cli info
(3)將redis_monitor.sh腳本文件上傳至/scripts目錄,并賦予執(zhí)行權(quán)限:# chmod +x /scripts/redis_monitor.sh
(4)將redis_status.conf配置文件上傳至/etc/zabbix/zabbix_agentd.d目錄,并重啟Zabbix Agent:
# systemctl restart zabbix-agent
(5)zabbix-server節(jié)點(diǎn)使用zabbix-get進(jìn)行取值測試:
# zabbix_get -s 192.168.0.122 -k redis[127.0.0.1,rejected_connections,none]
(6)Zabbix Web導(dǎo)入Redis監(jiān)控模板zbx_redis_templates.xml:
(7)node-122節(jié)點(diǎn)鏈接Redis監(jiān)控模板:
勾選所有Redis監(jiān)控項,點(diǎn)擊“Check now”:
(8)查看最新監(jiān)控數(shù)據(jù):
6、使用Percona插件監(jiān)控MySQL:
(1)node-122節(jié)點(diǎn)安裝php、php-mysql和MySQL
備注:由于Percona的監(jiān)控插件是php編寫的,所以需要在被監(jiān)控端安裝php和php-mysql
(2)node-122節(jié)點(diǎn)下載安裝插件: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,內(nèi)置模板匹配的Zabbix版本為2.0,在4.0版本中不能使用,網(wǎng)上另行下載的zbx_percona_mysql_templates.xml
(3)將userparameter_percona_mysql.conf配置文件復(fù)制至/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文件中的數(shù)據(jù)庫連接信息:
# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = '123456';
(6)zabbix-server節(jié)點(diǎn)使用zabbix-get進(jìn)行取值測試:
# 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導(dǎo)入Percona MySQL監(jiān)控模板zbx_percona_mysql_templates.xml:
備注:共191個監(jiān)控項
(8)node-122節(jié)點(diǎn)鏈接Percona MySQL監(jiān)控模板:
勾選所有Percona MySQL監(jiān)控項,點(diǎn)擊“Check now”:
其中1個有關(guān)主從復(fù)制的監(jiān)控項,提示:
解決方案,修改node-122節(jié)點(diǎn)上MySQL配置文件:
# vim /etc/my.cnf,末尾新增如下代碼:
[client]
user=root
password=123456
node-122節(jié)點(diǎn)重啟MySQL:# systemctl restart mysqld
zabbix-server節(jié)點(diǎn)重新加載Zabbix Server配置緩存(功能類似于重啟Zabbix Server):
# zabbix_server -R config_cache_reload
(9)查看最新監(jiān)控數(shù)據(jù):
備注:Zabbix還自帶了一個監(jiān)控MySQL的名為“Template DB MySQL”的模板,也可按上述方法進(jìn)行使用
7、監(jiān)控網(wǎng)頁的訪問速度和響應(yīng)速度:
(1)node-122節(jié)點(diǎn)搭建LNMP環(huán)境,部署WordPress
(2)Zabbix Web創(chuàng)建node-122節(jié)點(diǎn)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默認(rèn)登錄頁面:http://192.168.0.122/wordpress/wp-login.php
按Chrome瀏覽器F12,輸入一個錯誤的密碼,點(diǎn)擊登錄:
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)查看最新監(jiān)控數(shù)據(jù):
Monitoring --> Web --> WordPress
(4)創(chuàng)建觸發(fā)器:
Web是特殊的監(jiān)控項,直接添加觸發(fā)器
Configuration --> Hosts --> Triggers --> Create trigger --> Add
(5)zabbix-server節(jié)點(diǎn)使用ab命令模擬訪問node-122節(jié)點(diǎn)上的WordPress:
# yum provides ab
# yum -y install httpd-tools
# ab -n 10000 -c 20 http://192.168.0.122/wordpress/wp-login.php
常用選項:
-c:一次并發(fā)執(zhí)行的請求個數(shù),默認(rèn)是一次一個請求
-n:執(zhí)行的請求總數(shù)
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。