- A+
所属分类:linux技术
zabbix监控详解
目录
本章是基于zabbix的基础使用和监控服务zabbix部署基础之上.
本章进行的操作是zabbix监控linux,windows以及配置邮件告警
环境 | IP | 要安装的服务 |
---|---|---|
服务器 | 192.168.222.250 | lamp架构 zabbix server zabbix agent |
客户端 | 192.168.222.251 | zabbix agent |
在web界面进行linux部署agentd
zabbix客户端部署
zabbix6.2源码包
[root@localhost ~]# cd /usr/local/etc/ [root@localhost etc]# useradd -rMs /sbin/nologin zabbix //创建zabbix用户 [root@localhost etc]# cd /usr/src/ [root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz //下载源码包 [root@localhost src]# ls debug kernels zabbix-6.2.2.tar.gz [root@localhost src]# tar xf zabbix-6.2.2.tar.gz //解压 [root@localhost src]# cd zabbix-6.2.2/ [root@localhost zabbix-6.2.2]# dnf -y install openssl-devel pcre-devel expat-devel gcc gcc-c++ make //安装依赖包 [root@localhost zabbix-6.2.2]# ./configure --enable-agent //编译 .... *********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * <http://www.zabbix.com> * *********************************************************** [root@localhost zabbix-6.2.2]# make install //安装 [root@localhost zabbix-6.2.2]# cd /usr/local/etc/ [root@localhost etc]# ls zabbix_agentd.conf zabbix_agentd.conf.d [root@localhost etc]# vim zabbix_agentd.conf //修改配置文件 Server=192.168.222.250 //服务端ip ServerActive=192.168.222.250 //服务端ip Hostname=Zabbix xbz //zabbix系统内主机名,可自定义,但要确保唯一性 [root@localhost etc]# ldconfig //刷新配置 [root@localhost etc]# zabbix_agentd //启动zabbix_agentd [root@localhost etc]# ss -antl //查看端口 State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:*
创建监控主机
点击右上角的创建
设置好后点右下角的添加
创建主机组并加入主机
添加监控项
用模板方式添加
此处需要关闭客户端的防火墙
[root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# vim /etc/selinux/config [root@localhost ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX= disabled # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted [root@localhost ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since Mon 2022-09-05 22:26:01 CST; 34s ago Docs: man:firewalld(1) Process: 634412 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited,> Main PID: 634412 (code=exited, status=0/SUCCESS) Sep 05 21:54:24 localhost systemd[1]: Starting firewalld - dynamic firewall daemon... Sep 05 21:54:25 localhost systemd[1]: Started firewalld - dynamic firewall daemon. Sep 05 21:54:25 localhost firewalld[634412]: WARNING: AllowZoneDrifting is enabled. This is co> Sep 05 22:26:01 localhost systemd[1]: Stopping firewalld - dynamic firewall daemon... Sep 05 22:26:01 localhost systemd[1]: firewalld.service: Succeeded. Sep 05 22:26:01 localhost systemd[1]: Stopped firewalld - dynamic firewall daemon.
此外已经在进行监控
手动添加监控项
我们可以先在被监控端创建一个测试的文件
[root@localhost ~]# touch /tmp/xbz
查看监控数据
测试:修改一下文件
[root@localhost ~]# echo "xxx" >> /tmp/xbz
刷新查看
可以看到value发生了改变
添加触发器
开始添加一个监控文件的触发器
选择错误级别添加
点击添加,然后找到刚添加的触发器,可以看到触发器已经启动
再查看监控项,已经有了触发器
进行测试
[root@localhost ~]# echo "333" >> /tmp/xbz //修改/tmp/xbz文件
查看数据
查看主页告警信息
添加媒介(email方式)
如果想实现邮箱告警的话,需要添加媒介
这里用网易126邮箱作为演示:
设置——常规设置
BCKKTNWDZOMCXJOS
开启后会获得一个授权密码,这个授权密码要保存下来,后面会用到
这媒介想要通过哪个用户进行邮件发送,发送给谁?
添加动作
手动触发报警
在验证之前需要在收件人邮箱里设置白名单,否则会被当做垃圾邮件拒收
设置——反垃圾
两者都可以,这里选择域名白名单
手动触发告警
[root@localhost ~]# echo "555" >> /tmp/xbz //修改/tmp/zic文件
等待数据更新,触发告警
进入邮箱查看
通过命令行配置邮件告警
前面已经有了监控项和触发器,只需要配置媒介就好
在zabbix服务端进行配置
[root@localhost ~]# hostnamectl set-hostname localhost.example.com [root@localhost ~]# bash [root@localhost ~]# hostname localhost.example.com //修改服务端的主机名 [root@localhost ~]# dnf -y install mailx postfix //安装eamil和postfix [root@localhost ~]# systemctl enable --now postfix.service Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service. //设置开机自启 [root@localhost ~]# dnf -y install net-tools [root@localhost ~]# netstat -tunlp | grep 25 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2334677/master tcp6 0 0 ::1:25 :::* LISTEN 2334677/master [root@localhost ~]# vim /usr/local/etc/zabbix_server.conf //编辑/usr/local/etc/zabbix_server.conf AlertScriptsPath=/scripts/zabbix/ [root@localhost ~]# mkdir -p /scripts/zabbix/ [root@localhost ~]# cd /scripts/zabbix/ [root@localhost zabbix]# vim sendemail.sh [root@localhost zabbix]# cat sendemail.sh #!/bin/bash echo "$1" | mail -s "$2" $3 //编写脚本 [root@localhost zabbix]# chmod +x sendemail.sh //赋予执行权限 [root@localhost zabbix]# pkill zabbix_server [root@localhost zabbix]# zabbix_server //先杀死再重启
配置媒介(scripts方式)
配置动作
手动触发告警
[root@localhost ~]# echo "555" >> /tmp/xbz //修改/tmp/xbz
等待最新数据产生
查看邮箱
下载文件在记事本上面看看