Zabbix监控平台基于Zabbix的集群基础上操作,所以需要建立集群。
添加http服务监控项
在上个实验的基础上,server2开启httpd服务
- 因为http在zabbix中自带监控模版,直接添加
点击配置->主机->server2->模版->选择:Tempalte App HTTP Service
点击更新后server2模版中显示Template App HTTP Service
添加nginx服务监控项
- zabbix监控项中没有nginx,需要在zabbix-agent端部署nginx服务
-
nginx部署
[root@server2 ~]# yum install -y gcc pcre-devel zlib-devel make #安装需要的工具库 [root@server2 ~]# tar zxf nginx-1.15.8.tar.gz [root@server2 ~]# cd nginx-1.15.8 [root@server2 nginx-1.15.8]# vim auto/cc/gcc 171 # debug ##注释这两行,关闭debug日志实现最小安装 172 #CFLAGS="$CFLAGS -g" [root@server2 nginx-1.15.8]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module ##编译指定nginx的按装位置,和增加的模块 [root@server2 nginx-1.15.8]# make && make install ##安装 [root@server2 nginx-1.15.8]# cd /usr/local/nginx [root@server2 nginx]# du -sh 872K . [root@server2 conf]# vim /usr/local/nginx/conf/nginx.conf 3 worker_processes auto; 48 location /status { 49 stub_status on; #nginx中的stub_status模块用于查看nginx的一些状态信息 50 access_log off; #关闭日志记录 51 } [root@server2 conf]# /usr/local/nginx/sbin/nginx -t #检查编辑的文件是否有语法错误 [root@server2 conf]# ln -s /usr/local/nginx/sbin/nginx /sbin/ ##软连接到/sbin/下 [root@server2 conf]# nginx #开启nginx服务
过滤监控参数(访问次数、连接次数…),将过滤出的参数以key-value键值对的形式储存:
[root@server2 nginx]# curl -s 172.25.25.2/status | grep Active | awk {'print $3'}
1
创建nginx的监控项
[root@server2 conf]# curl -s http://localhost/status |grep Active |awk '{print $3}' ##测试是否能够取得键值
[root@server2 conf]# 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 #以mysql监控模版复制一份nginx的模版
[root@server2 zabbix_agentd.d]# vim userparameter_nginx..conf #添加nginx监控项 [root@server2 zabbix_agentd.d]# cat userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://localhost/status |grep Active |awk '{print $3}'
UserParameter=nginx.access,curl -s http://localhost/status |awk NR==3 |awk '{print $1}'
UserParameter=nginx.handled,curl -s http://localhost/status |awk NR==3 |awk '{print $2}'
UserParameter=nginx.request,curl -s http://localhost/status |awk NR==3 |awk '{print $3}'
[root@server2 zabbix_agentd.d]# systemctl restart zabbix-agent ##重启监控端口
zabbix-server端检测是否能拿到数据
[root@server1 ~]# zabbix_get -s 172.25.25.2 -p 10050 -k "nginx.active"
1
[root@server1 ~]# zabbix_get -s 172.25.25.2 -p 10050 -k "nginx.request"
19
配置 ->主机-> 点击server2-> 点击监控项 ->创建监控项
添加监控项,这里的键值要和创建监控项是的一致;所有的监控项都以这种方法添加(创建后记得更新)
添加图形,点击刚才的监控项
点击图形->创建图形->名称->添加监控项(可同时选择多个)->添加
添加成功后预览:
如果不支持文字
1.)下载喜欢的字体,到server1 下的/use/share/zabbix/fonts目录替换
[root@server1 4.0]# cd /usr/share/zabbix/fonts/
[root@server1 fonts]# ls
graphfont.ttf
[root@server1 fonts]# ls
graphfont.ttf simkai.ttf ## simkai.ttf 自己下的字体
[root@server1 fonts]# cd ..
[root@server1 zabbix]# cd include/
[root@server1 include]# vim defines.inc.php #编辑该文件
:%s/graphfont/simkai/g #将所有的graphfont 改成simkai
监控mysql服务
1)可以先给server 主机添加自带的监控mysql的模版
配置->主机(zabbix server)->模版
但是自带的模版监控项比较少,我们可以添加模版增加监控项
配置mysql
[root@server1 ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm #安装percona模块
[root@server1 ~]#cd /var/lib/zabbix/percona/templates/
[root@server1 templates]#cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/ #将模块文件复制到zabbix监控目录下
[root@server1 templates]#systemctl restart zabbix-agent #重启监控服务
[root@server1 templates]#cd /var/lib/zabbix/percona/scripts/
[root@server1 scripts]#vim ss_get_mysql_stats.php.cnf #由于该模块监控脚本为php语言,所以这里提供的数据库与密码也使用php语言
<?php
$mysql_user = 'root';
$mysql_pass = 'redhat';
[root@server1 scripts]#/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg #测试脚本
[root@server1 scripts]#cd /tmp/
[root@server1 tmp]#rm -fr localhost-mysql_cacti_stats.txt #由于此文件所有者为root用户,zabbix无法查看,所以删除,zabbix查看时会以自己的身份重建此文件
导入percona-zabbix模版
配置->模版->导入->导入文件->选择
模版导入成功
给zabbix server 添加模版