#安装agent包 [root@17-Cobbler web]# yum -y install zabbix-agent #编辑agent配置文件路径:/etc/zabbix/zabbix_agentd.conf [root@17-Cobbler zabbix]# vim zabbix_agentd.conf #修改被动的Server,主动的ServerActive Server=192.168.0.17 ServerActive=192.168.0.17 Hostname=17-Cobbler #启动zabbix-agent服务 [root@17-Cobbler zabbix]# systemctl start zabbix-agent #查看服务运行情况 [root@17-Cobbler zabbix]# systemctl status zabbix-agent ● zabbix-agent.service - Zabbix Agent Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2018-02-27 04:19:03 EST; 3min 48s ago Process: 4450 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 4452 (zabbix_agentd) CGroup: /system.slice/zabbix-agent.service ├─4452 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf ├─4453 /usr/sbin/zabbix_agentd: collector [idle 1 sec] ├─4454 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] ├─4455 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] ├─4456 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] └─4457 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] Feb 27 04:19:03 17-Cobbler systemd[1]: Starting Zabbix Agent... Feb 27 04:19:03 17-Cobbler systemd[1]: PID file /run/zabbix/zabbix_agentd.pid not readable (yet?) after start. Feb 27 04:19:03 17-Cobbler systemd[1]: Started Zabbix Agent. #查看zabbix-agent进程 [root@17-Cobbler zabbix]# ps -ef | grep zabbix_agentd | grep -v grep zabbix 4452 1 0 04:19 ? 00:00:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf zabbix 4453 4452 0 04:19 ? 00:00:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec] zabbix 4454 4452 0 04:19 ? 00:00:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] zabbix 4455 4452 0 04:19 ? 00:00:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 4456 4452 0 04:19 ? 00:00:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] zabbix 4457 4452 0 04:19 ? 00:00:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] #查看端口号 [root@17-Cobbler zabbix]# netstat -tunlp|grep agent tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 4452/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 4452/zabbix_agentd
第一步: #开启stub_status模块 --with-http-stub-status_module 第二步: #nginx打开监控项: http { server { listen 8080; server_name localhost; location / { root html; index index.html index.htm; } location /nginx-status { stub_status on; access_log off; } } } 第三步: #打开测试页面 http://192.168.0.4:8080/nginx-status ---------- Active connections: 2 server accepts handled requests 6 6 3 Reading: 0 Writing: 1 Waiting: 1 ---------- 第四步(CentOS 7略过): #Centos6.x打开zabbix_agent默认路径为:/etc/zabbix/zabbix_agentd.conf #CentOS 6.x与CentOS 7目录名字不太一样,统一改成名字吧 [root@nginx-01 conf]#vim /etc/zabbix/zabbix_agentd.conf Include=/etc/zabbix/zabbix_agentd/ [root@nginx-01 conf]#mkdir /etc/zabbix/zabbix_agentd.d [root@nginx-01 conf]# grep -i Include /etc/zabbix/zabbix_agentd.conf ### Option: Include # You may include individual files or all files in a directory in the configuration file. # Include= # Include=/etc/zabbix/zabbix_agentd.userparams.conf Include=/etc/zabbix/zabbix_agentd.d/ 第五步: #客户端通过正则匹配nginx的活动连接数 [root@nginx-01 conf]# curl -s http://192.168.0.4:8080/nginx-status | grep "Active" |awk '{print $NF}' 2 # 文件追加到配置文件,命名为nginx.active [root@nginx-01 zabbix]# echo -e "UserParameter=nginx.active,/usr/bin/curl -s 'http://192.168.0.4:8080/nginx-status' | grep 'Active' | awk '{print \$NF}'" >/etc/zabbix/zabbix_agentd.d/nginx.active [root@nginx-01 zabbix]# cat /etc/zabbix/zabbix_agentd.d/nginx.active UserParameter=nginx.active,/usr/bin/curl -s 'http://192.168.0.4:8080/nginx-status' | grep 'Active' | awk '{print $NF}' #CentOS6.x设置完重启 [root@nginx-01 zabbix]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] #CentOS7.x重启 [root@17-Cobbler zabbix]# systemctl restart zabbix-agent 第六步: #服务端测试 #查看是否安装了zabbix-get,如果没有安装可以通过:yum -y install zabbix-get安装,至于yum源里面没有,可以去阿里云配置yum源 [root@17-Cobbler zabbix]# rpm -qa | grep zabbix-get zabbix-get-3.0.14-1.el7.x86_64 #测试 [root@17-Cobbler zabbix]# zabbix_get -s 192.168.0.4 -p 10050 -k nginx.active 1 #客户端添加完成,剩下服务端web添加。
原文地址:http://blog.51cto.com/hongdouzi555/2074266