实验环境
server1:rhel 7.3系统——172.25.54.1
server2:rhel 6.5系统——172.25.54.11
一、zabbix监控nginx
- 添加监控项active
server2
[root@server2 ~]# ls
nginx-1.8.0-1.el6.ngx.x86_64.rpm zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@server2 ~]# rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm
//安装nginx
[root@server2 ~]# cd /etc/nginx/conf.d/
[root@server2 conf.d]# vim default.conf
13 location /status {
14 stub_status on;
15 access_log off;
16 allow 127.0.0.1;
17 deny all;
18 }
[root@server2 conf.d]# nginx -t
[root@server2 conf.d]# nginx
[root@server2 conf.d]# curl -s http://127.0.0.1/status | grep Active | awk '{print $NF}'
//$NF:最后一列
1
[root@server2 conf.d]# curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
1
[root@server2 conf.d]# cd /etc/zabbix/zabbix_agentd.d/
[root@server2 zabbix_agentd.d]# ls
userparameter_mysql.conf
[root@server2 zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
[root@server2 zabbix_agentd.d]# vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
[root@server2 zabbix_agentd.d]# /etc/init.d/zabbix-agent start
[root@server2 zabbix_agentd.d]# chkconfig zabbix-agent on //设置开机自启
server1
[root@server1 ~]# systemctl start mariadb
[root@server1 ~]# systemctl enable mariadb
[root@server1 ~]# systemctl start zabbix-server
[root@server1 ~]# systemctl enable zabbix-server
[root@server1 ~]# systemctl start zabbix-agent
[root@server1 ~]# systemctl enable zabbix-agent
[root@server1 ~]# systemctl start httpd
[root@server1 ~]# systemctl enable httpd
[root@server1 ~]# ls
fping-3.10-1.el7.x86_64.rpm zabbix-get-3.4.6-1.el7.x86_64.rpm
iksemel-1.4-2.el7.centos.x86_64.rpm zabbix-java-gateway-3.4.6-1.el7.x86_64.rpm
php-bcmath-5.4.16-42.el7.x86_64.rpm zabbix-proxy-mysql-3.4.6-1.el7.x86_64.rpm
php-mbstring-5.4.16-42.el7.x86_64.rpm zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm
zabbix-agent-3.4.6-1.el7.x86_64.rpm zabbix-web-3.4.6-1.el7.noarch.rpm
zabbix-api1.sh zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
zabbix-api.sh
[root@server1 ~]# rpm -ivh zabbix-get-3.4.6-1.el7.x86_64.rpm
[root@server1 ~]# zabbix_get -s 172.25.54.11 -p 10050 -k 'nginx.active'
1
[root@server1 ~]#
浏览器
- 添加监控项accepts、handled、requests
server2
[root@server2 zabbix_agentd.d]# vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
UserParameter=nginx.accepts,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
UserParameter=nginx.handled,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $2}'
UserParameter=nginx.requests,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $3}'
[root@server2 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
35
[root@server2 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $2}'
36
[root@server2 zabbix_agentd.d]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $3}'
37
[root@server2 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
浏览器
先添加三个新的监控项
一、zabbix添加mysql模块并监控
percona-zabbix-templates-1.1.8-1.noarch.rpm安装包下载
server1
[root@server1 ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
[root@server1 ~]# cd /var/lib/zabbix/percona/templates/
[root@server1 templates]# ls
userparameter_percona_mysql.conf zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
[root@server1 templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@server1 zabbix_agentd.d]# systemctl restart zabbix-agent
[root@server1 zabbix_agentd.d]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
<?php
$mysql_user = 'root';
$mysql_pass = 'redhat';
[root@server1 zabbix_agentd.d]# mysql -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 586
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
[root@server1 zabbix_agentd.d]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
4
[root@server1 zabbix_agentd.d]# cd /tmp/
[root@server1 tmp]# ls
localhost-mysql_cacti_stats.txt
systemd-private-5d2805d4023241a291abf9bec82244af-httpd.service-x6qoiW
systemd-private-5d2805d4023241a291abf9bec82244af-mariadb.service-8uQXRk
systemd-private-85310d76fe5d48c9af82fc3eeddb75c0-mariadb.service-dwB5hY
systemd-private-87d37df39e4b4602909e8a8390477aa7-httpd.service-cy69v5
systemd-private-87d37df39e4b4602909e8a8390477aa7-mariadb.service-gLeaRS
[root@server1 tmp]# cat localhost-mysql_cacti_stats.txt
[root@server1 tmp]# rm -fr localhost-mysql_cacti_stats.txt
[root@server1 tmp]# cd
[root@server1 ~]# zabbix_get -s 172.25.54.1 -p 10050 -k 'MySQL.Threads-cached'
zabbix_get [13888]: Check access restrictions in Zabbix agent configuration
[root@server1 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k 'MySQL.Threads-cached'
0
[root@server1 ~]#
浏览器