zabbix 5.0 新增加了许多模板,我们可以利用自带的模板对某些应用服务或网络设备进行监控。
监控nginx:
nginx配置文件添加如下:
location /status { #定义运行状态页面名称,页面为status
stub_status on; #开启模块
access_log off; #不开启访问日志记录
allow 127.0.0.1; #运行127.0.0.1地址访问此网页
allow 192.168.25.0/24; #只运行192.168.25.0网段的主机访问此网页
deny all; #其余网段主机不允许访问
}
需要注意的是nginx需要开启模块:--with-http_stub_status_module
发送请求:curl http://192.168.25.42:8090/status 必须有数据返回
监控apache:
新建配置文件:
/etc/httpd/conf.d/info.conf
<Location /server-status>
SetHandler server-status
Order allow,deny
Allow from localhost
Allow from 192.168.25.0/24
</Location>
ExtendedStatus On
需要注意的是,此方法是使用apache 服务的status模块
请求:curl http://192.168.25.42:8000/server-status?auto 必须有数据返回
监控redis:
zabbix 5.0 zabbix-agent2 已经内置监控redis的接口
修改redis配置:
bind 0.0.0.0
这个地方必须要改,不然zabbix-server不在同一机器上采集不到数据
zabbix-agent2 也必须安装,配置好zabbix-server信息
redis无密码的情况下直接使用模板进行关联
redis有密码的情况下需要添加宏值:$REDIS_PASS}
此处可参考:
监控ntp服务:
zabbix 5.0 监控ntp服务,首先需要搭建ntpd服务
服务端:(ntp方式)
/etc/ntp.conf
#restrict default nomodify notrap nopeer noquery
restrict 192.168.25.42 nomodify notrap nopeer noquery
restrict 192.168.25.0 mask 255.255.252.0 nomodify notrap
#server 0.centos.pool.ntp.org iburst
#server iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
客户端:(ntp方式)
/etc/ntp.conf
server 192.168.25.42
测试检验:
ntpd -p
ntpdate -q 192.168.25.42
--------------------------------------------------------
服务端:(chrony方式)
/etc/chrony.conf
server 0.centos.pool.ntp.org iburst #可以修改ntp的服务器。最好用国内的。
server iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
allow 192.168.25.0/24 #打开允许同步的IP
阿里的时间服务器:
chronyc sources
客户端:(chrony方式)
#server 0.centos.pool.ntp.org iburst #注释此处
#server iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.25.42 iburst #添加server
验证:date
chronyc sources
监控ntp时间服务进程,直接关联模板即可
监控docker:
zabbix 5.0 监控docker 需要使用zabbix-agent2
将zabbix添加到docker组:
usermod -aG docker zabbix
这里不加的话,用户权限存在问题
web上直接关联模板即可
自动发现监控docker,更加深入的使用参考如下:
监控php-fpm:
修改php-fpm配置www.conf
pm.status_path = /php-fpm-status
ping.path = /php-fpm-ping
修改nginx配置:
location ~ ^/php-fpm-(status|ping)$ {
access_log off;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass unix:/usr/local/php-fastcgi/var/run/php-fpm.sock;
allow 127.0.0.1;
deny all;
}
测试:
curl http://127.0.0.1/php-fpm-ping
curl http://127.0.0.1/php-fpm-status
在Zabbix前端页面,点击“Configuration” -> “Templates”,找到名称为“Template App PHP-FPM by Zabbix agent”的模板。
该模板定义了几个重要的参数:
{$PHP_FPM.HOST}:PHP-FPM状态的Nginx主机名或IP地址,默认是“localhost”;
{$PHP_FPM.PING.PAGE}:PHP-FPM ping状态页面地址,默认是“ping”,这里是“php-fpm-ping”,
{$PHP_FPM.PING.REPLY}:PHP-FPM ping的返回值,默认是“pong”;
{$PHP_FPM.PORT}:PHP-FPM状态的Nginx主机的端口号,默认值是“80”;
{$PHP_FPM.STATUS.PAGE}:PHP-FPM状态页面地址,默认值是“status”,这里是”php-fpm-status“。
监控网络设备,使用snmp协议,前提是需要交换机、路由器、打印机这些设备开启了snmp协议,并记录下版本和ip地址,然后在web上直接关联模板即可