zabbix监控详解

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
//&#x5B89;&#x88C5;
[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
//&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#x6587;&#x4EF6;
Server=192.168.222.250   //&#x670D;&#x52A1;&#x7AEF;ip
ServerActive=192.168.222.250  //&#x670D;&#x52A1;&#x7AEF;ip
Hostname=Zabbix xbz  //zabbix&#x7CFB;&#x7EDF;&#x5185;&#x4E3B;&#x673A;&#x540D;&#xFF0C;&#x53EF;&#x81EA;&#x5B9A;&#x4E49;&#xFF0C;&#x4F46;&#x8981;&#x786E;&#x4FDD;&#x552F;&#x4E00;&#x6027;
[root@localhost etc]# ldconfig  //&#x5237;&#x65B0;&#x914D;&#x7F6E;
[root@localhost etc]# zabbix_agentd  //&#x542F;&#x52A8;zabbix_agentd
[root@localhost etc]# ss -antl   //&#x67E5;&#x770B;&#x7AEF;&#x53E3;
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                    [::]:*
</http:>

创建监控主机

点击右上角的创建

zabbix监控详解
设置好后点右下角的添加
zabbix监控详解
zabbix监控详解

创建主机组并加入主机

zabbix监控详解
zabbix监控详解
zabbix监控详解

添加监控项

用模板方式添加

zabbix监控详解
zabbix监控详解
您需要在此处关闭客户端的防火墙。
[En]

You need to turn off the client’s firewall here.

[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
&#x25CF; 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.

zabbix监控详解
此外已经在进行监控
手动添加监控项
我们可以首先在被监视端创建一个测试文件。
[En]

We can first create a test file on the monitored side.

[root@localhost ~]# touch /tmp/xbz

zabbix监控详解
zabbix监控详解
zabbix监控详解
查看监控数据
zabbix监控详解
zabbix监控详解
zabbix监控详解
测试:修改一下文件
[root@localhost ~]# echo "xxx" >> /tmp/xbz

刷新查看
可以看到value发生了改变

zabbix监控详解

添加触发器

开始添加触发器以监视该文件

[En]

Start adding a trigger to monitor the file

zabbix监控详解
zabbix监控详解
选择错误级别添加
zabbix监控详解
zabbix监控详解
zabbix监控详解
单击添加,然后找到您刚刚添加的触发器。您可以看到触发器已经启动。
[En]

Click add, and then find the trigger you just added. You can see that the trigger has been started.

zabbix监控详解
如果您查看监控项,您就已经有了触发器。
[En]

If you look at the monitoring item, you already have a trigger.

zabbix监控详解
进行测试
[root@localhost ~]# echo "333" >> /tmp/xbz
//&#x4FEE;&#x6539;/tmp/xbz&#x6587;&#x4EF6;

查看数据

zabbix监控详解
查看主页告警信息
zabbix监控详解

添加媒介(email方式)

如果要实现邮箱告警,则需要添加媒体。

[En]

If you want to achieve mailbox alarm, you need to add media.

zabbix监控详解
这里用网易126邮箱作为演示:
设置——常规设置
zabbix监控详解
BCKKTNWDZOMCXJOS
zabbix监控详解
打开后,您将获得授权密码,该密码将被保存,稍后将使用。
[En]

After opening it, you will get an authorization password, which will be saved and will be used later.

zabbix监控详解
zabbix监控详解
此媒体希望通过哪个用户发送邮件,以及发送给谁?
[En]

Through which user does this medium want to send mail, and to whom?

zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解

添加动作

zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解

手动触发报警

您需要在收件人邮箱中设置白名单后再进行验证,否则会被当作垃圾邮件拒绝。

[En]

You need to set up a whitelist in the recipient’s mailbox before verification, otherwise it will be rejected as spam.

设置——反垃圾

zabbix监控详解
zabbix监控详解
两个都很好。在这里选择域名白名单。
[En]

Both are fine. Choose the whitelist of domain names here.

zabbix监控详解
手动触发告警
[root@localhost ~]# echo "555" >> /tmp/xbz
//&#x4FEE;&#x6539;/tmp/zic&#x6587;&#x4EF6;

等待数据更新,触发告警

zabbix监控详解
进入邮箱查看
zabbix监控详解
zabbix监控详解

通过命令行配置邮件告警

前面有监控项目和触发器,只需配置介质即可。

[En]

There are monitoring items and triggers in front, so you just need to configure the media.

在zabbix服务端进行配置

[root@localhost ~]# hostnamectl set-hostname localhost.example.com
[root@localhost ~]# bash
[root@localhost ~]# hostname
localhost.example.com
//&#x4FEE;&#x6539;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x4E3B;&#x673A;&#x540D;
[root@localhost ~]# dnf -y install mailx postfix
//&#x5B89;&#x88C5;eamil&#x548C;postfix
[root@localhost ~]#  systemctl enable --now postfix.service
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service &#x2192; /usr/lib/systemd/system/postfix.service.

//&#x8BBE;&#x7F6E;&#x5F00;&#x673A;&#x81EA;&#x542F;
[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
//&#x7F16;&#x8F91;/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
//&#x7F16;&#x5199;&#x811A;&#x672C;
[root@localhost zabbix]# chmod +x sendemail.sh
//&#x8D4B;&#x4E88;&#x6267;&#x884C;&#x6743;&#x9650;
[root@localhost zabbix]# pkill zabbix_server
[root@localhost zabbix]# zabbix_server
//&#x5148;&#x6740;&#x6B7B;&#x518D;&#x91CD;&#x542F;

配置媒介

zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解

配置动作

zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
手动触发告警
[root@localhost ~]# echo "555" >> /tmp/xbz
//&#x4FEE;&#x6539;/tmp/xbz

等待最新数据产生

zabbix监控详解
查看邮箱
zabbix监控详解
zabbix监控详解
下载文件并在记事本中查看。
[En]

Download the file and look at it in the notepad.

zabbix监控详解

zabbix监控Windows客户端

zabbix官网
下载windows安装包

zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
zabbix监控详解
要创建主机,不要忘记关闭防火墙或添加防火墙入站规则
[En]

To create a host, don’t forget to turn off the firewall or add firewall inbound rules

zabbix监控详解
zabbix监控详解
zabbix监控详解

Original: https://www.cnblogs.com/tushanbu/p/16660335.html
Author: 涂山布
Title: zabbix监控详解

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/522747/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球