zabbix 监控lnmp
添加监控服务httpd
点server2 -> 模板 -> 选择 -> Template App HTTP Service
Nginx:
[root@server2 ~]# tar zxf nginx-1.16.0.tar.gz
[root@server2 ~]# yum install gcc make pcre-devel zlib-devel -y
[root@server2 nginx-1.16.0]# vim auto/cc/gcc
[root@server2 nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
[root@server2 nginx-1.16.0]# make && make install
配置文件,开启nginx服务
[root@server2 nginx-1.16.0]# vim /usr/local/nginx/conf/nginx.conf
location /status {
stub_status on; ##用于查看nginx信息
access_log off;
allow 127.0.0.1;
deny all;
}
[root@server2 nginx-1.16.0]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server2 nginx-1.16.0]# /usr/local/nginx/sbin/nginx
使用curl查看
[root@server2 nginx-1.16.0]# curl http://127.0.0.1/status
Active connections: 1
server accepts handled requests
2 2 1
Reading: 0 Writing: 1 Waiting: 0
#过滤出活跃连接数
[root@server2 nginx-1.16.0]# curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
#过滤出请求次数
curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
#添加监控项
[root@server2 nginx-1.16.0]# cd /etc/zabbix/zabbix_agentd.d/
[root@server2 zabbix_agentd.d]# ls
userparameter_mysql.conf
[root@server2 zabbix_agentd.d]# scp 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}'
UserParameter=nginx.access,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
[root@server2 zabbix_agentd.d]# systemctl restart zabbix-agent
在server1 测试
[root@server1 ~]# zabbix_get -s 172.25.76.2 -p 10050 -k "nginx.active"
1
[root@server1 ~]# zabbix_get -s 172.25.76.2 -p 10050 -k "nginx.access"
19
在web中添加
添加监控项
#改字体
[root@server1 fonts]# ls
graphfont.ttf simkai.ttf
[root@server1 fonts]# pwd
/usr/share/zabbix/fonts
[root@server1 include]# pwd
/usr/share/zabbix/include
[root@server1 include]# vim defines.inc.php
:$s/graphfont/simkai/g
因为zabbix自带的项目太少所以向zabbix监控中导入模版监控mysql的模版percona
配置mysql
[root@server1 zabbix_agentd.d]# mkdir /var/lib/zabbix
[root@server1 zabbix_agentd.d]# cd /var/lib/zabbix/
[root@server1 zabbix]# vim .my.cnf
[mysql]
host = localhost
user = root
password = redhat
socket = /var/lib/mysql/mysql.sock
[mysqladmin]
host = localhost
user = root
password = redhat
socket = /var/lib/mysql/mysql.sock
[root@server1 zabbix]# systemctl restart zabbix-agent
[root@server1 zabbix安装包]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
[root@server1 zabbix安装包]# cd /var/lib/zabbix/
[root@server1 zabbix]# ls
percona
[root@server1 zabbix]# cd 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 percona]# cd scripts/
[root@server1 scripts]# vim ss_get_mysql_stats.php.cnf
<?php
$mysql_user = 'root';
$mysql_pass = 'redhat';
[root@server1 scripts]# systemctl restart zabbix-agent
#测试
[root@server1 zabbix_agentd.d]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
19
倒入模板
添加模板