├── 1.Zabbix4.0的安装.md ├── 10.Zabbix4.0 版本升级.md ├── 11.Zabbix4.0性能调优.md ├── 12.Zabbix4.0分布式监控.md ├── 2.Zabbix4.0添加监控主机.md ├── 3.Zabbix4.0添加触发器.md ├── 4.Zabbix4.0自定义报警.md ├── 5.Zabbix4.0使用grafana自定义图形.md ├── 6.Zabbix4.0自定义模板.md ├── 7.Zabbix4.0使用percona监控MySQL数据库.md ├── 8.Zabbix4.0自动化监控.md ├── 9.Zabbix4.0 Agent主动模式.md ├── LICENSE ├── README.md └── Zabbix4.0中遇到的问题.md /1.Zabbix4.0的安装.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | >**Github:[https://github.com/ThanlonSmith/Zabbix-Tutorial](https://github.com/ThanlonSmith/Zabbix-Tutorial)** 3 | ###### 1. Zabbix架构 4 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602233449341.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 5 | Zabbix Agent:Zabbix的客户端,负责 **`数据收集上传`** 6 | Zabbix Server:Zabbix的服务端,负责数据汇总处理,告警策略,告警发送等 7 | Zabbix Web:Zabbix的前端界面,提供友好的展示和操作界面,负责数据的展示、监控系统的配置管理、用户权限配置管理等功能 8 | Database:配置数据存储的数据库,Zabbix支持多种数据库,包括MySQL、Oracle、DB2等 9 | Java GateWay:Java网关,负责通过JVM监控收集Java应用性能数据 10 | Zabbix Proxy:Zabbix代理,分布式部署架构会用到,主要是收集设备数据的监控数据并将数据发送给对应的Zabbix Server 11 | 12 | 数据通过Zabbix客户端收集并发送给Zabbix服务端,Zabbix服务端负责存储、分析数据、触发报警等任务。用户或者管理员可以通过Zabbix前端页面进行数据展示和配置管理。如果设备规模较多,并且分布在多地域或者多机房,都可以通过Zabbix Proxy实现分布式架构部署。 13 | ###### 2. Zabbix Server组成 14 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602234455752.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 15 | Zabbix Server由下面的一些列进程组成,每种进程有自己的特定功能。 16 | ###### 3. 安装版本说明 17 |        官方有标准版和长期支持版,因为官方对于长期支持版本支持的时间相对会长很多,所以我们会选择长期支持版本。Zabbix的4.0版本为当前日期最新的长期支持版本,所以接下来就安装这个版本。如果使用源码包安装,可能有些包没有启用。后期想用,它是不支持额外添加模块的,只能重新编译安装一次。所以,此外建议使用二进制包来安装,官方已经把该需要的功能都编译好了。 18 | ###### 4. 安装repo源 19 | ```js 20 | # 安装zabbix的repo源: 21 | [root@localhost ~]# rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm 22 | # 替换为清华源的地址: 23 | [root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo 24 | :%s#repo.zabbix.com#mirror.tuna.tsinghua.edu.cn/zabbix#g 25 | ``` 26 | ###### 5. 安装zabbix-server-mysql 27 | ```js 28 | [root@localhost ~]# yum install zabbix-server-mysql -y 29 | ``` 30 | ###### 6. 安装zabbix-web-mysql 31 | ```js 32 | [root@localhost ~]# yum install zabbix-web-mysql -y 33 | ``` 34 | ###### 7. 安装与配置数据库mariadb-server 35 | ```js 36 | # 安装mariadb-server 37 | [root@localhost ~]# yum install mariadb-server -y 38 | 39 | # 设置开机自启 40 | root@localhost ~]# systemctl enable mariadb 41 | [root@localhost ~]# systemctl is-enabled mariadb 42 | enabled 43 | 44 | # 数据库安全初始化(在/etc/mysq.cnf的[mysqld]下添加skip-grant-tables,设置密码部分为n,其他为y) 45 | [root@localhost ~]# mysql_secure_installation 46 | 47 | # 创建数据库 48 | MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; 49 | 50 | # 数据库授权 51 | MariaDB [(none)]> grant all on zabbix.* to zabbix@'%' identified by '123456'; 52 | MariaDB [(none)]> flush privileges; 53 | 54 | # 查找zabbix的sql文件 55 | [root@localhost ~]# rpm -ql zabbix-server-mysql 56 | [root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.20/ 57 | [root@localhost zabbix-server-mysql-4.0.20]# ls 58 | AUTHORS ChangeLog COPYING create.sql.gz NEWS README 59 | [root@localhost zabbix-server-mysql-4.0.20]# file create.sql.gz 60 | create.sql.gz: gzip compressed data, was "create.sql", from Unix, last modified: Mon Apr 27 09:04:32 2020 61 | [root@localhost zabbix-server-mysql-4.0.20]# gzip -d create.sql.gz 62 | 63 | # 将sql文件导入到数据库中 64 | [root@localhost zabbix-server-mysql-4.0.20]# mysql -uzabbix -p123456 zabbix **Github:[https://github.com/ThanlonSmith/Zabbix-Tutorial](https://github.com/ThanlonSmith/Zabbix-Tutorial)** 168 | -------------------------------------------------------------------------------- /10.Zabbix4.0 版本升级.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 为什么要升级Zabbix版本 3 | ① 提高性能;② 增加新功能;③ 解决模板不兼容等问题。 4 | ###### 2. 安装Zabbix2.2 5 | 新增10.0.0.4,在这台机器上安装Zabbix2.2以便升级到Zabbix4.0。Zabbix2.2下载地址:[https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/2.2/rhel/7/x86_64/](https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/2.2/rhel/7/x86_64/) 6 | ```js 7 | # 查看系统已安装的与Zabbix相关的安装文件 8 | [root@localhost ~]# rpm -qa|grep zabbix 9 | 10 | # 删除所有与Zabbix相关的安装文件 11 | [root@localhost ~]# yum remove zabbix-agent.x86_64 12 | 13 | # 删除Zabbix配置文件 14 | [root@localhost ~]# rm -rf /etc/zabbix 15 | 16 | # 安装Zabbix源 17 | [root@localhost ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm 18 | 19 | # 使用清华源加速下载 20 | [root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo 21 | %s#repo.zabbix.com#mirror.tuna.tsinghua.edu.cn/zabbix#g 22 | 23 | # 安装Zabbix主要的安装文件zabbix-server-mysql和zabbix-web-mysql 24 | [root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql -y 25 | 26 | # 设置Zabbix开机自启 27 | [root@localhost ~]# systemctl enable zabbix-server 28 | 29 | # 安装MySQL数据库 30 | [root@localhost ~]# yum install mariadb-server -y 31 | 32 | # 设置MySQL开机自启 33 | [root@localhost ~]# systemctl enable mariadb 34 | [root@localhost ~]# systemctl is-enabled mariadb 35 | enabled 36 | 37 | # 初始化数据库。一开始没密码直接回车,不设置密码no,其它为yes 38 | [root@localhost ~]# mysql_secure_installation 39 | 40 | # 创建数据库(charset utf8等价于character set utf8) 41 | MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin; 42 | 43 | # 创建授权。授权命令执行之后会创建zabbix用户 44 | MariaDB [(none)]> grant all on zabbix.* to zabbix@'%'; 45 | 46 | # 如果需要远程连接mysql,则需要关闭firewalld 47 | [root@localhost ~]# systemctl stop firewalld 48 | 49 | # 设置firewall开机不自启动 50 | [root@localhost ~]# systemctl disable firewalld 51 | 52 | # 查找初始数据sql文件 53 | [root@localhost ~]# rpm -ql zabbix-server-mysql 54 | /usr/sbin/zabbix_server_mysql 55 | /usr/share/doc/zabbix-server-mysql-2.2.23 56 | /usr/share/doc/zabbix-server-mysql-2.2.23/create 57 | /usr/share/doc/zabbix-server-mysql-2.2.23/create/data.sql 58 | /usr/share/doc/zabbix-server-mysql-2.2.23/create/images.sql 59 | /usr/share/doc/zabbix-server-mysql-2.2.23/create/schema.sql 60 | /usr/share/doc/zabbix-server-mysql-2.2.23/upgrades 61 | /usr/share/doc/zabbix-server-mysql-2.2.23/upgrades/dbpatches 62 | /usr/share/doc/zabbix-server-mysql-2.2.23/upgrades/dbpatches/1.6 63 | /usr/share/doc/zabbix-server-mysql-2.2.23/upgrades/dbpatches/1.6/mysql 64 | /usr/share/doc/zabbix-server-mysql-2.2.23/upgrades/dbpatches/1.6/mysql/patch.sql 65 | ... 66 | 67 | # 跳转到Zabbix初始数据目录下 68 | [root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-2.2.23/create/ 69 | 70 | # 查看数据库文件 71 | [root@localhost create]# ls 72 | data.sql images.sql schema.sql 73 | 74 | # 导入zabbix初始数据到数据库,注意顺序 75 | [root@localhost create]# mysql -uroot -p zabbix < schema.sql 76 | [root@localhost create]# mysql -uroot -p zabbix < images.sql 77 | [root@localhost create]# mysql -uroot -p zabbix < data.sql 78 | [root@localhost create]# vim /etc/zabbix/zabbix_server.conf 79 | 80 | # 需要使Zabbix连接MySQL,所以也要修改DBHost、DBUser、DBPassword的值。我这里zabbix数据库用户没有设置密码 81 | [root@localhost create]# vim /etc/zabbix/zabbix_server.conf 82 | 83 | # 过滤 84 | [root@localhost create]# grep -Ev '^$|#' /etc/zabbix/zabbix_server.conf 85 | LogFile=/var/log/zabbix/zabbix_server.log 86 | LogFileSize=0 87 | PidFile=/var/run/zabbix/zabbix_server.pid 88 | DBHost=localhost 89 | DBName=zabbix 90 | DBUser=zabbix 91 | DBPassword= 92 | DBSocket=/var/lib/mysql/mysql.sock 93 | SNMPTrapperFile=/var/log/snmptt/snmptt.log 94 | AlertScriptsPath=/usr/lib/zabbix/alertscripts 95 | ExternalScripts=/usr/lib/zabbix/externalscripts 96 | 97 | # 启动Zabbix 98 | [root@localhost create]# systemctl start zabbix-server 99 | 100 | # 修改时区 101 | [root@localhost create]# vim /etc/httpd/conf.d/zabbix.conf 102 | php_value date.timezone Asia/Shanghai 103 | 104 | # 启动httpd 105 | [root@localhost create]# systemctl start httpd 106 | ``` 107 | 至此Zabbix 2.2安装完成。可以登录Web界面: 108 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602143851461.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 109 | 连接MySQL数据库,这里只填了用户名没有填写密码是因为我这里的数据库用户zabbix没有设置密码: 110 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602144429168.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 111 | 默认,下一步: 112 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602144506154.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 113 | 配置完成后会生成 /etc/zabbix/web/zabbix.conf.php文件,如果要 **`把数据库从zabbix server中分离,迁移到单独的机器中`**,就需要修改这个文件中的数据库ip地址: 114 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602155736713.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 115 | 用户名是Admin或admin都可以,但密码必须是zabbix。 116 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602144952240.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 117 | 修改为中文编码: 118 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602145221903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 119 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060215582527.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 120 | ###### 3. Zabbix 2.2升级到Zabbix 4.0 121 | ```js 122 | # 下载4.0第二rpm包 123 | [root@localhost ~]# wget -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm 124 | 125 | # 升级Zabbix安装源 126 | [root@localhost ~]# rpm -Uvh zabbix-release-4.0-2.el7.noarch.rpm 127 | 警告:zabbix-release-4.0-2.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY 128 | 准备中... ################################# [100%] 129 | 正在升级/安装... 130 | 1:zabbix-release-4.0-2.el7 ################################# [ 50%] 131 | 正在清理/删除... 132 | 2:zabbix-release-2.2-1.el7 ################################# [100%] 133 | 134 | # 升级安装源后,zabbix.repo中的内容会被替换成4.0的源 135 | [root@localhost ~]# ls /etc/yum.repos.d/ 136 | CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo CentOS-x86_64-kernel.repo zabbix.repo 137 | 138 | # 使用清华源加速下载 139 | [root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo 140 | %s#repo.zabbix.com#mirror.tuna.tsinghua.edu.cn/zabbix#g 141 | 142 | # 为防止升级失败,需要备份数据库 143 | [root@localhost ~]# mysqldump -B zabbix > zabbix.sql 144 | 145 | # 开始升级 146 | [root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql -y 147 | 148 | # 安装新版本时zabbix会停止运行,可以查看运行状态 149 | [root@localhost ~]# systemctl status zabbix-server 150 | ● zabbix-server.service - Zabbix Server 151 | Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled; vendor preset: disabled) 152 | Active: inactive (dead) 153 | 154 | # 启动新版Zabbix 155 | [root@localhost ~]# systemctl start zabbix-server 156 | 157 | # 可以新开一个终端查看新版Zabbix的运行日志,可以看到Zabbix数据库正在升级 158 | [root@localhost ~]# tailf /var/log/zabbix/zabbix_server.log 159 | ... 160 | 49455:20200602:040939.578 current database version (mandatory/optional): D/02020001 161 | 49455:20200602:040939.578 required mandatory version: 04000000 162 | 49455:20200602:040939.578 optional patches were found 163 | ... 164 | 49455:20200602:040939.660 completed 2% of database upgrade 165 | 49455:20200602:040939.694 completed 3% of database upgrade 166 | 49455:20200602:040939.772 completed 4% of database upgrade 167 | 49455:20200602:040939.786 completed 5% of database upgrade 168 | 49455:20200602:040939.801 completed 6% of database upgrade 169 | 49455:20200602:040939.808 completed 7% of database upgrade 170 | 49455:20200602:040939.816 completed 8% of database upgrade 171 | 49455:20200602:040939.820 completed 9% of database upgrade 172 | ... 173 | ``` 174 | 启动Zabbix时会 **`读配置文件/etc/zabbix/zabbix_server.conf`**,配置文件有数据库的连接地址。 175 | 176 | 升级数据库就是把Zabbix 2版本.2的Zabbix数据库升级为Zabbix 4.4版本的数据库。**`升级之后才会Zabbix才会启动`**。升级之后,如果在2.2版本中创建了模板,新版本中模板还是存在的,因为数据没有被删除。升级之后,发现页面发生了改变,没错这就是4.4的版本: 177 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602165057585.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 178 | -------------------------------------------------------------------------------- /11.Zabbix4.0性能调优.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 数据库调优 3 | ① Zabbix是写多读少的业务,所以要提高Zabbix写入的性能。MyISAM引擎时不可以使用的,至少要使用InnoDB引擎(mysql 5.5),或者使用TokuDB引擎(mysql 5.7),当然也可以把数据库的硬盘升级为SSD硬盘。 4 | 5 | ② 去掉没有用的监控项,增加监控项的取值间隔,减少历史数据保存周期 6 | 7 | ③ 针对Zabbix历史数据和趋势图的表进行周期性分表 8 | 9 | ④ 把被动模式修改为主动模式,增加zabbix-proxy将监控项的采集数据集中写入,而不是每个Zabbix Agent都向最终的Zabbix Server发数据 10 | ###### 2. 进程调优 11 | ① 针对Zabbix-Server进程调优,进程忙碌的时候就增加进程数量 12 | 13 | 将扫描IP网段的频率时值为10s,这样会增加自动发现进程的压力: 14 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602214041801.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 15 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602214049405.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 16 | Zabbix的进程监控都在 **`图形`** 里面,可以选择查看数据采集进程的情况,如自动发现进程。这里不难发现,自动发现进程的已经到了100%: 17 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602215731375.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 18 | 下面通过调优来降低自动发现忙碌程度: 19 | ```js 20 | # 这里把自动发现进程数设置为6个(0~250) 21 | [root@Zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf 22 | StartDiscoverers=6 23 | 24 | # 重启Zabbix Server 25 | [root@Zabbix-server ~]# systemctl start zabbix-server.service 26 | ``` 27 | 不建议上来就把值设置为最大,因为 **`每增加一个进程需要消耗一定内存空间的。`** 然后再看自动发现的忙碌程度就降低了非常多: 28 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602220910367.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 29 | 调优的原则是:哪个进程比较忙就增加进程数量,不建议加到几十倍,最好要一点点去调。**`要保证曲线平稳,而不是高低起伏大。`** 30 | 31 | ② 针对Zabbix-Server缓存调优,剩余内存少的时候增加缓存值 32 | 33 | 缓存的作用是用来存储监控的主机,**`这些目标主机数据是从数据库查出来的然后放到内存中的。`** 当然,**`取值的监控项`** 和 **`触发器指标`** 也都是存在Zabbix Server的缓存中。如果缓存不够用了,Zabbix Server就会出问题。Zabbix Server默认的缓存是8M。为了测试缓存调优效果,这里先把缓存调为最低, 34 | ```js 35 | # 修改缓存为128K(128K-8G) 36 | [root@Zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf 37 | CacheSize=128K 38 | 39 | # 重启Zabbix Server 40 | [root@Zabbix-server ~]# systemctl restart zabbix-server.service 41 | ``` 42 | 这个时候发现,Zabbix Server挂掉: 43 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602222212311.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 44 | ```js 45 | # 查看Zabbix Server日志 46 | [root@Zabbix-server ~]# tailf /var/log/zabbix/zabbix_server.log 47 | 67257:20200602:102244.619 __mem_malloc: skipped 1 asked 1816 skip_min 1104 skip_max 1104 48 | 67257:20200602:102244.619 [file:dbconfig.c,line:94] __zbx_mem_realloc(): out of memory (requested 1816 bytes) 49 | 67257:20200602:102244.619 [file:dbconfig.c,line:94] __zbx_mem_realloc(): please increase CacheSize configuration parameter 50 | ``` 51 | 意思也就是内存不足( out of memory ),让我们增加CacheSize配置参数。如果以后有这样的报警,需要把缓存调整大一些。除了 **`内部进程、采集进程`** 还有缓存使用率: 52 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602222925219.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 53 | 大于75%的时候会报警,如果缓存不够就需要增加缓存! 54 | >**Github:[https://github.com/ThanlonSmith/Zabbix-Tutorial](https://github.com/ThanlonSmith/Zabbix-Tutorial)** 55 | -------------------------------------------------------------------------------- /12.Zabbix4.0分布式监控.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. Zabbix分布式监控系统概述 3 | Zabbix有三种监控架构,分别是Server-Agent、Server-Node-Agent和Server-Proxy-Agent。在大型环境中Zabbix有两种解决方案,**`使用节点(Node)和使用代理(Proxy)`**。使用节点和代理是有区别的: 4 | 5 | ① Proxy用于 **`本区域数据收集并将数据发送给Zabbix Server`**,它不做分析监控以及数据展示。Proxy只有一个proxy的daemon进程,Proxy也有自己的数据库(不完整的),但是它的数据库只会保存一定时间的数据,它与Master通信是将一批信息打包后发送到Master。Master将这些数据merger到Master数据库。 6 | 7 | ② Node提供完整的Zabbix Server用于 **`建立分布式监控的层级`**。Node本身是一台Zabbix Server,它有 **`完整的Web页面和完整的数据库,它会将数据源源不断地传给Master`**。 8 | 9 | **`节点是重量级应用,而代理是轻量级的应用`**。Master-Proxy相比Master-Node的优点有:Proxy压力小,数据库只存储一定时间的数据;Master压力变小,数据不是源源不断获取,减小IO压力(**`Node是收集数据就发数据,Proxy是保存一定时间然后一次性发送`**);**`架构更清晰,容易维护`**(在Master的Zabbix Server集中统一配置)。 10 | ###### 2. Server-Node-Agent架构特性 11 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200603104016375.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 12 | Server-Node-Agent架构是用来 **`解决主机过多时单台Server面临性能瓶颈`** 的问题。方案有使用多个实例,没有实例是独立的一套Zabbix,有数据库和前台(可选)。该架构支持热插拔,Node和Server的连接可以随时断开,但不会影响Node的正常运行。Node定时向Server发送Configuration,History,Event等。Server定时给Node发送Configuration。**`所有的配置变更只能在Node节点操作`**,不能在Server操作。支持树状结构,Node又可以是个Server。 13 | ###### 3. Server-Proxy-Agent架构特性 14 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/202006031044252.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 15 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200603184123329.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 16 | Proxy不会向Server同步Configuration,只会接收。Proxy的数据库会 **`定时将数据传送给Server,本地数据库只保存最近没有发送的数据。`** 其实,Proxy仅仅是 **`数据收集器`**,它不具有触发器、生成事件或发送警报等功能。**`Zabbix Server的功能有:监控远程区域;监控不可靠通信的位置;减轻Zabbix Server的压力;简化分布式监控的维护;与Zabbix Server是单TCP连接的,这种方式很容易绕过防火墙,只需要配置一条防火墙规则。`** 17 | >**`注意:Zabbix Proxy必须使用一个单独的数据库,不可以于Server使用同一个数据库。也不建议放到同一个物理服务器上`。** 18 | 19 | Zabbix的特性: 20 | | 特性项 | 是否支持 | 21 | |--|--| 22 | | **Zabbix agent checks** | **Yes** | 23 | | **Zabbix agent checks(active)** |**Yes** | 24 | | **Simple checks** | **Yes** | 25 | | **Trapper items** | **Yes** | 26 | | **SNMP checks**| **Yes** | 27 | | **SNMP traps** | **Yes** | 28 | | **IPMI checks** | **Yes** | 29 | | **JMX checks** | **Yes** | 30 | | **Log file monitoring** | **Yes** | 31 | | **`Internal checks`** | **`No`** | 32 | | **SSH checks** |**Yes** | 33 | | **Telnet checks** | **Yes** | | 34 | | **External checks** | **Yes** | 35 | | **Buit-in web monitering** | **Yes** | 36 | | **Network discovery** | **Yes** | 37 | | **Low-level discovery** |**Yes** | 38 | | **`Calculating triggers`** | **`No`** | 39 | | **`Processing events`** |**`No`** | 40 | | **`Sending alerts`** | **`No`** | 41 | | **`Remote commands`** | **`No`**| 42 | ###### 4. 分布式监控的实现 43 | 准备3台服务器,一台做=作Zabbix Server,另外一台作Zabbix Proxy,剩下一台作Zabbix Proxy的Agent。这三台服务器分别对应10.0.0.2、10.0.0.5和10.0.0.6。Zabbix Server和Zabbix Agent已经在前面介绍过,这里不赘述。为了测试方便,这里把MySQL和Zabbix Proxy放在统一台服务器上,首先安装与配置数据库: 44 | ```js 45 | # 安装MySQL数据库 46 | [root@zabbix-proxy ~]# yum install mariadb-server 47 | # 初始化数据库 48 | [root@zabbix-proxy ~]# mysql_secure_installation 49 | # 设置开机自启 50 | [root@zabbix-proxy ~]# chkconfig mariadb on 51 | # 创建zabbix_proxy数据库 52 | MariaDB [(none)]> create database zabbix_proxy character set utf8 collate utf8_bin; 53 | # 创建新用户并且授予权限 54 | MariaDB [(none)]> grant all on zabbix_proxy.* to zbxuser@'%' identified by '123456'; 55 | # 刷新权限 56 | MariaDB [(none)]> flush privileges; 57 | ``` 58 | 安装完成之后开始安装Zabbix Proxy: 59 | ```js 60 | # 下载包含数据库插件的Zabbix Proxy包 61 | [root@zabbix-proxy ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-proxy-mysql-4.0.21-2.el7.x86_64.rpm 62 | # 下载epel源 63 | [root@zabbix-proxy ~]# wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm 64 | # 安装epel源(也可以使用rpm) 65 | [root@zabbix-proxy ~]# yum install epel-release-7-12.noarch.rpm 66 | # 安装Zabbix Proxy。使用yum安装会自动解决依赖问题,自动安装依赖的fping等 67 | [root@zabbix-proxy ~]# yum localinstall -y zabbix-proxy-mysql-4.0.21-2.el7.x86_64.rpm 68 | # 设置Zabbix Proxy开机自启 69 | [root@zabbix-proxy ~]# chkconfig zabbix-proxy on 70 | # 查看Zabbix Proxy是否启动,以及占用的端口 71 | [root@zabbix-proxy ~]# netstat -tunlp|grep zabbix 72 | tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 1543/zabbix_proxy 73 | tcp6 0 0 :::10051 :::* LISTEN 1543/zabbix_proxy 74 | ``` 75 | 配置Zabbix Proxy连接Zabbix Server和MySQL: 76 | ```js 77 | # 查询Zabbix Proxy初始数据 78 | [root@zabbix-proxy ~]# rpm -ql zabbix-proxy-mysql 79 | ... 80 | /usr/share/doc/zabbix-proxy-mysql-4.0.21/schema.sql.gz 81 | ... 82 | # 解压sql文件 83 | [root@zabbix-proxy zabbix-proxy-mysql-4.0.21]# gunzip schema.sql.gz 84 | # 把sql文件导入到数据库 85 | [root@zabbix-proxy zabbix-proxy-mysql-4.0.21]# mysql -uzbxuser -p zabbix_proxy**Github:[https://github.com/ThanlonSmith/Zabbix-Tutorial](https://github.com/ThanlonSmith/Zabbix-Tutorial)** 137 | -------------------------------------------------------------------------------- /2.Zabbix4.0添加监控主机.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 在zabbix-server上安装监控主机 3 | ```js 4 | # 安装agent 5 | [root@Zabbix-server ~]# yum install zabbix-agent.x86_64 -y 6 | # 设置开机启动 7 | [root@Zabbix-server ~]# systemctl enable zabbix-agent 8 | # 启动agent 9 | [root@Zabbix-server ~]# systemctl start zabbix-agent 10 | # 查看默认启动的端口 11 | [root@Zabbix-server ~]# netstat -tunlp|grep 1005 12 | tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 9903/zabbix_agentd 13 | tcp6 0 0 :::10050 :::* LISTEN 9903/zabbix_agentd 14 | ``` 15 | ###### 2. 在其它服务器上安装监控主机 16 | ```js 17 | # 下载rpm包 18 | [root@agent ~]# axel https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.20-1.el7.x86_64.rpm 19 | 20 | # 安装agent 21 | [root@agent ~]# rpm -ivh zabbix-agent-4.0.20-1.el7.x86_64.rpm 22 | 23 | # 修改agent配置文件,将Server=127.0.0.1修改为10.0.0.2 24 | [root@agent ~]# vim /etc/zabbix/zabbix_agentd.conf 25 | 26 | # 启动zabbix-agent 27 | [root@agent ~]# systemctl enable zabbix-agent 28 | [root@agent ~]# systemctl start zabbix-agent 29 | ``` 30 | ###### 3. 添加监控主机 31 | 通过在Web界面上配置来添加监控主机: 32 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520175335473.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 33 | 关联模板,没有模板就没有监控项,可以先使用默认的模板,监控常规项: 34 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520175513747.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 35 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020052017574618.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 36 | -------------------------------------------------------------------------------- /3.Zabbix4.0添加触发器.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 系统触发器 3 | 点击用户头像,打开用户基本资料,选择开启“正在发送消息”来开启此功能。如果有警告,系统会发出警告声: 4 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520181349127.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 5 | 查看系统自带的触发器: 6 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520181513475.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 7 | 下面测试“Linux用户密码文件发生改变”的触发器: 8 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520182630295.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 9 | 首先设置采集的时间间隔,将原来默认1小时修改为10s: 10 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520183338833.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 11 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520183412331.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 12 | 查看最新数据,可以看到最新数据是:3356102413 13 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520233730226.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 14 | 在10.0.0.3监控主机上使密码文件发生变化: 15 | ```js 16 | [root@agent ~]# md5sum /etc/passwd 17 | 41a16f7241d08a7246b8999a0fab90c5 /etc/passwd 18 | # 得到的最新数据和Web界面上显示的一样 19 | [root@agent ~]# cksum /etc/passwd 20 | 3356102413 1002 /etc/passwd 21 | # 添加新用户来改变/etc/passwd文件 22 | [root@agent ~]# useradd thanlon 23 | # 再查看最新数据,这时候这个Web页面上最新数据应该发生改变为4061271438 24 | [root@agent ~]# cksum /etc/passwd 25 | 4061271438 1041 /etc/passwd 26 | ``` 27 | 可能Web界面上的最新数据没有发生改变,也没有产生警报。这是因为在Web界面作的操作都会提交到数据库, 添加一条主机后,数据库就会多一条记录。zabbix-server默认60s查寻一次数据库,才会知道任务目标是什么,然后再监控。如果值没有改变,可以重启zabbix server,让它提前查询数据库。这里可以看到值已经变成了4061271438: 28 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520234438266.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 29 | 进入图形,可以图形、值和最近500个值三种视图展示数据的改变: 30 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520234719537.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 31 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520234814453.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 32 | 数据发生改变后,系统会发出两声警报: 33 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200520235804837.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 34 | ###### 2. 自定义触发器 35 | 下面创建一个“当前系统用户登录超过2个报警”的触发器。选择创建触发器: 36 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521001332267.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 37 | 添加触发器名称和表达式,选择“添加”即可: 38 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521001543709.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 39 | 在触发器页面可以看到设置的触发器: 40 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521001710345.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 41 | 默认的更新间隔是10min,测试的时候,可以改为10s: 42 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521001826169.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 43 | 下面再创建2个登录终端,可以通过 **`w`** 命令查看当前登录的终端: 44 | ```js 45 | [root@agent ~]# w 46 | 12:10:21 up 53 min, 3 users, load average: 0.00, 0.03, 0.05 47 | USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT 48 | root pts/0 10.0.0.1 11:19 3:49 0.28s 0.28s -bash 49 | root pts/1 10.0.0.1 12:06 5.00s 0.02s 0.01s w 50 | root pts/2 10.0.0.1 12:07 2:57 0.01s 0.01s -bash 51 | ``` 52 | 此时当前的用户数为3,超过了我们自定的2,触发了我们自定义的当前系统用户数量登录数: 53 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521000843108.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 54 | 当我们关掉一个登录连接,可以发现登录数已经变成了2,系统响了一声在页面上发出提示,问题已解决: 55 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521001225979.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 56 | **`系统的触发器一般监控CPU、内存、硬盘、网络、进程`** 等常用的监控项。**`触发器之间还可以设置依赖关系`**,可以设置被依赖的触发器如果被触发了,依赖它的触发器可以不触发。 57 | ###### 3. 自动生成触发器 58 | 还不熟悉自己写表达式的时候,可以自定义生成触发器: 59 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521002643776.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 60 | 可以设置大于4个报警,小于3个恢复: 61 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521002908716.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 62 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521003115524.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 63 | 接下来就是改变当前系统(10.0.0.3)用户登录数,当设置为5个连接数时,系统报出现问题,当关闭两个连接设置为2个连接时,恢复: 64 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521004521713.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 65 | ###### 4. 报警声音的更换 66 | 可以在zabbix server上找到报警声音的文件: 67 | ```js 68 | [root@Zabbix-server ~]# cd /usr/share/zabbix/audio/ 69 | [root@Zabbix-server audio]# ls 70 | alarm_average.mp3 alarm_high.mp3 alarm_ok.mp3 no_sound.mp3 71 | alarm_disaster.mp3 alarm_information.mp3 alarm_warning.mp3 72 | ``` 73 | -------------------------------------------------------------------------------- /4.Zabbix4.0自定义报警.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 自定义监控项 3 | 在 **`监控主机`** 上配置自定义监控项: 4 | ```js 5 | # 查看当前登录用户 6 | [root@agent ~]# who 7 | root pts/0 2020-05-20 21:29 (10.0.0.1) 8 | root pts/1 2020-05-20 21:35 (10.0.0.1) 9 | # 查看当前用户登录数 10 | [root@agent ~]# who|wc -l 11 | 2 12 | # 设置自定义监控项login_users,命令是who|wc -l 13 | [root@agent ~]# vim /etc/zabbix/zabbix_agentd.conf 14 | UserParameter=login_users,who|wc -l 15 | # 重启zabbix监控主机 16 | [root@agent ~]# systemctl restart zabbix-agent 17 | ``` 18 | 在zabbix server机器上获取设置的监控项的值: 19 | ```js 20 | # 下载zabbix-get.x86_64 21 | [root@Zabbix-server ~]# yum install zabbix-get.x86_64 -y 22 | # 获取监控项的值 23 | [root@Zabbix-server ~]# zabbix_get -s 10.0.0.3 -k login_users 24 | ``` 25 | 添加监控项,可以把 **`历史数据保留时长`** 设置的小一些: 26 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521112123313.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 27 | 可以看到我们自定义的监控项: 28 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521112123384.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 29 | ###### 2. 创建触发器 30 | 这里要注意表达式部分监控项的名字要使用我们自定义的: 31 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521112516368.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 32 | ###### 3. 自定义邮件发件人 33 | 这里需要注意的是163邮箱需要开启SMTP服务,才能拿到授权码: 34 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521120428211.png) 35 | 授权码写在密码部分: 36 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521115300242.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 37 | ###### 4. 自定义邮件收件人 38 | 点击用户头像,到 **`用户基本资料`** 下的 **`报警媒介`** 下添加Email类型的报警媒介: 39 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521114137159.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 40 | ###### 5. 启用触发器的动作 41 | 到 **`配置`** 选项下的 **`动作`** 项中将状态修改为已启用的状态: 42 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521114522775.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 43 | ###### 6. 触发报警 44 | 当触发“当前系统用户的登录数”触发器的时候,会向接收邮箱发送消息。这里可以查看已经发送的报警邮件: 45 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521120038386.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 46 | 邮箱也会接收到报警消息: 47 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521120124541.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 48 | ###### 7. 自定义邮件报警信息 49 | 默认的邮件报警信息除了宏部分,其它均为英文且比较乱。所以,为了方便查看,需要自定义邮件报警信息: 50 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521120847989.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 51 | 自定义邮件报警信息,我这里使用的模板是: 52 | ```js 53 | 服务器: {HOST.NAME}发生:{EVENT.NAME}故障! 54 | { 55 | 告警主机: {HOST.NAME} 56 | 告警地址:{HOST.IP} 57 | 监控项目:{ITEM.NAME} 58 | 监控取值:{ITEM.LASTVALUE} 59 | 告警等级:{TRIGGER.SEVERITY} 60 | 当前状态:{TRIGGER.STATUS} 61 | 告警信息:{TRIGGER.NAME} 62 | 告警时间:{EVENT.DATE} {EVENT.TIME} 63 | 事件ID:{EVENT.ID} 64 | } 65 | ``` 66 | 下面换成我们定义的信息: 67 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521121917798.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 68 | 当触发报警后,可以在 **`动作日志`** 中查看到发送给接收邮件的报警信息: 69 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521122352496.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 70 | 检查邮箱后发现邮箱也收到了对应的报警信息: 71 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521122430240.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 72 | ###### 8. 自定义微信报警 73 | 写一个微信发送消息的脚本,这里需要用到企业微信。需要修改企业微信ID、机器人密码和应用ID,这些在企业微信管理都可以看到。下面是微信发送消息的脚本: 74 | ```py 75 | # 导入相关模块 76 | import requests, os, sys, logging, json 77 | 78 | # 定义日志的格式 79 | logging.basicConfig( 80 | filename=os.path.join('/tmp', 'weixin.log'), 81 | format='%(asctime)s - %(name)s - %(levelname)s - %(module)s:%(message)s', 82 | datefmt='%Y-%m-%d %H:%M:%S', 83 | level=logging.DEBUG, 84 | ) 85 | # 企业微信id 86 | corpid = '' 87 | # 机器人密码 88 | appsecret = '' 89 | # 应用id 90 | agentid = 1 91 | # 获取accesstoken 92 | token_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettonken?corpid' + corpid + '&corpsecret=' + appsecret 93 | req = requests.get(token_url) 94 | accesstoken = req.json()['access_token'] 95 | # 发送消息 96 | send_msg_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken 97 | touser = sys.argv[1] 98 | subject = sys.argv[2] 99 | message = subject + '\n\n' + sys.argv[3] 100 | params = { 101 | 'touser': touser, 102 | 'msgtype': 'text', 103 | 'agentid': agentid, 104 | 'text': { 105 | 'content': message 106 | }, 107 | 'safe': 0 108 | } 109 | req = requests.post(send_msg_url, data=json.dumps(params)) 110 | # 把结果记录的日志中 111 | logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message) 112 | ``` 113 | 把脚本放到zabbix server中的指定的目录下: 114 | ```js 115 | # 查看脚本应该放到哪个位置 116 | [root@Zabbix-server ~]# grep -Ev '^$|#' /etc/zabbix/zabbix_server.conf 117 | ... 118 | AlertScriptsPath=/usr/lib/zabbix/alertscripts 119 | ... 120 | ``` 121 | 添加微信报警媒介: 122 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521211303929.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 123 | 指定收件人: 124 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521211828247.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 125 | 添加完成后启用微信报警媒介,可以暂时把Email报警媒介停用: 126 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020052121194134.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 127 | 下面执行这个脚本开始向微信发送报警信息: 128 | ```js 129 | [root@Zabbix-server ~]# cd /usr/lib/zabbix/alertscripts/ 130 | [root@Zabbix-server alertscripts]# python weixin.py 用户名 标题 报警内容 131 | ``` 132 | -------------------------------------------------------------------------------- /5.Zabbix4.0使用grafana自定义图形.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 图形乱码的解决 3 | 默认监测图形中存在乱码: 4 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521224703430.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 5 | 需要我们替换zabbix web默认使用的字体,因为它不支持中文。可以到Windows中找到支持中文的字体,找到字体后把默认的 **`graphfont.ttf`** 替换掉即可。首先得找到字体的位置: 6 | ```js 7 | # 跳转到zabbix web界面的php下 8 | [root@Zabbix-server ~]# cd /usr/share/zabbix/ 9 | # 再跳转字体资源路径下 10 | [root@Zabbix-server zabbix]# cd assets/fonts/ 11 | # 可以查看到zabbix web界面使用的字体,这个字体默认是个软链接 12 | [root@Zabbix-server fonts]# ls 13 | graphfont.ttf 14 | [root@Zabbix-server fonts]# pwd 15 | /usr/share/zabbix/assets/fonts 16 | ``` 17 | 将字体上传到zabbix server服务器的 **`/usr/share/zabbix/assets/fonts`** 目录下: 18 | ```js 19 | thanlon@thanlon:~$ scp simhei.ttf root@10.0.0.2:/usr/share/zabbix/assets/fonts 20 | ``` 21 | 在zabbix server服务器执行替换操作: 22 | ```js 23 | [root@Zabbix-server fonts]# \mv simhei.ttf graphfont.ttf 24 | [root@Zabbix-server fonts]# ls 25 | graphfont.ttf 26 | ``` 27 | 乱码修改成功: 28 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521225605792.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 29 | ###### 2. grafana的安装 30 | ```js 31 | # 下载grafana 32 | [root@Zabbix-server ~]# axel https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-7.0.0-2.x86_64.rpm 33 | # 本地安装grafana 34 | [root@Zabbix-server ~]# yum localinstall grafana-7.0.0-2.x86_64.rpm 35 | # 开机自启 36 | [root@Zabbix-server ~]# systemctl enable grafana-server 37 | # 启动grafana 38 | [root@Zabbix-server ~]# systemctl start grafana-server 39 | ``` 40 | ###### 3. grafana插件的安装 41 | ```js 42 | # 查看所有的远程插件 43 | [root@Zabbix-server ~]# grafana-cli plugins list-remote 44 | # 过滤找到grafana的zabbix插件 45 | [root@Zabbix-server ~]# grafana-cli plugins list-remote|grep zabbix 46 | id: alexanderzobnin-zabbix-app version: 3.12.0 47 | # 根据id来安装插件,如果因为下载不了安装不上应该是网络的原因 48 | [root@Zabbix-server ~]# grafana-cli plugins install alexanderzobnin-zabbix-app 49 | # 重启grafana 50 | [root@Zabbix-server ~]# systemctl restart grafana-server 51 | ``` 52 | ###### 4. grafana的登录 53 | grafana默认运行在3000端口,使用默认的用户名和密码都是:admin 54 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020052123421444.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 55 | 可以修改密码也可以跳过: 56 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521234306865.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 57 | 默认是Dark主题,你可以修改为Light主题: 58 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200521234824758.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 59 | >**可以使用Docker启用汉化版的grafana!** 60 | 61 | 启用Zabbix插件: 62 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522002344809.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 63 | ###### 5. 添加Zabbix数据源 64 | 我们的Zabbix和Grafama安装在同一台服务器上,所以URL部分输入localhost就可以。然后还需要输入Zabbix的用户名和密码: 65 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522003728536.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 66 | ###### 6. 添加Dashboards 67 | 直接导入grafana中默认已经存在的三个模板: 68 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522004347602.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 69 | 首先从官网下载一个Dashboards:[https://grafana.com/grafana/dashboards?orderBy=name&direction=asc](https://grafana.com/grafana/dashboards?orderBy=name&direction=asc),从文件或Grafana.com导入Dashboards: 70 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522004937738.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 71 | 下载这个仪表板: 72 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522005107606.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 73 | 选择zabbix源: 74 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522005439528.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 75 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020052200593826.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 76 | 没有相应的监控项,所有没有数据,应该是使用配套的模板来支持。另外你还可以选择自定义置Dashboards的显示样式: 77 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522010722853.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 78 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200522010747359.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 79 | -------------------------------------------------------------------------------- /6.Zabbix4.0自定义模板.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 设置模板监控项 3 | 创建模板之前需要为模板创建监控项。这里以TCP连接的11种状态为监控项,首先需要找到这些监控项: 4 | ```js 5 | # TCP连接的11种状态 6 | [root@agent ~]# man netstat 7 | ``` 8 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601190842136.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 9 | ```js 10 | [root@agent ~]# cd /etc/zabbix/zabbix_agentd.d/ 11 | # 把监控项目放到文件中便于批量添加到监控项配置文件中 12 | [root@agent zabbix_agentd.d]# vim a.txt 13 | [root@agent zabbix_agentd.d]# cat a.txt 14 | ESTABLISHED 15 | SYN_SENT 16 | SYN_RECV 17 | FIN_WAIT1 18 | FIN_WAIT2 19 | TIME_WAIT 20 | CLOSE 21 | CLOSE_WAIT 22 | LAST_ACK 23 | LISTEN 24 | CLOSING 25 | 26 | # 创建监控项配置文件 27 | [root@agent zabbix_agentd.d]# vim zbx_tcp.conf 28 | [root@agent zabbix_agentd.d]# >zbx_tcp.conf 29 | 30 | # 查看tcp连接的11种状态 31 | [root@agent zabbix_agentd.d]# netstat -ant 32 | Active Internet connections (servers and established) 33 | Proto Recv-Q Send-Q Local Address Foreign Address State 34 | tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 35 | tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 36 | tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 37 | tcp 0 0 10.0.0.3:10050 10.0.0.2:51796 TIME_WAIT 38 | tcp 0 0 10.0.0.3:10050 10.0.0.2:51716 TIME_WAIT 39 | tcp 0 0 10.0.0.3:10050 10.0.0.2:51806 TIME_WAIT 40 | tcp 0 0 10.0.0.3:10050 10.0.0.2:51680 TIME_WAIT 41 | tcp 0 0 10.0.0.3:10050 10.0.0.2:51782 TIME_WAIT 42 | ...... 43 | 44 | # LISTEN状态的数目 45 | [root@agent zabbix_agentd.d]# netstat -ant|grep -c LISTEN 46 | 6 47 | # TIME_WAIT状态的数目 48 | [root@agent zabbix_agentd.d]# netstat -ant|grep -c TIME_WAIT 49 | 68 50 | 51 | # 批量为监控项配置文件添加内容 52 | [root@agent zabbix_agentd.d]# for n in `cat a.txt`;do echo "UserParameter=$n,netstat -ant|grep -c $n">>zbx_tcp.conf;done; 53 | 54 | # 重启zabbix agent 55 | [root@agent zabbix_agentd.d]# systemctl restart zabbix-agent 56 | 57 | # 重启zabbix server 58 | [root@Zabbix-server ~]# systemctl restart zabbix-server 59 | 60 | # 获取agent上的监控项的值 61 | [root@Zabbix-server ~]# zabbix_get -s 10.0.0.3 -k LISTEN 62 | 6 63 | [root@Zabbix-server ~]# zabbix_get -s 10.0.0.3 -k TIME_WAIT 64 | 63 65 | ``` 66 | 在Web界面上添加这些监控项: 67 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601175136170.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 68 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601175443541.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 69 | 使用克隆方便添加与之前类似的内容: 70 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601175625686.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 71 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601175745936.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 72 | 完成添加: 73 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601180357283.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 74 | 75 | ###### 2. 创建模板 76 | 创建模板,可以属于最大的群组: 77 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601181218585.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 78 | ###### 3. 监控项关联模板 79 | 批处理将监控项关联模板: 80 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601181637355.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 81 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601181536364.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 82 | >**`模板也是特殊的主机!!!`** 83 | ###### 4. 添加应用集 84 | 将所有监控项添加应用集: 85 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601183803407.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 86 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601183813302.png) 87 | ###### 5. 监控主机关联模板 88 | 监控主机可以关联很多监控不同类型监控项的模板: 89 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601184043600.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 90 | 91 | 设置不支持的监控项恢复时间为30s: 92 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/202006011847059.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 93 | 查看监控的最新数据: 94 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060118483893.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 95 | ###### 6. 导入模板注意事项 96 | 使用别人的模板,不止需要xml格式的模板,还需要模板对应的.conf结尾的监控项配置文件,以及取值脚本等。导入的模板如果和之前的重名,则需要修改名字。网上有很多模板,可以通过下面的链接获取: 97 | 98 | [https://share.zabbix.com/](https://share.zabbix.com/) 99 | [https://zabbix.org/wiki/Main_Page](https://zabbix.org/wiki/Main_Page) 100 | [https://github.com/monitoringartist/zabbix-community-repos](https://github.com/monitoringartist/zabbix-community-repos) 101 | -------------------------------------------------------------------------------- /7.Zabbix4.0使用percona监控MySQL数据库.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 插件下载 3 | 4 | 插件下载地址:[https://www.percona.com/downloads/percona-monitoring-plugins/LATEST/](https://www.percona.com/downloads/percona-monitoring-plugins/LATEST/) 5 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601203041314.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 6 | ###### 2. 插件安装 7 | 接下来安装percona zabbix插件,这个插件是用来监控MySQL的。由于我的MySQL安装在了Zabbix Server(10.0.0.2),所以这里就把插件安装在Zabbix Server上。需要注意的是插件是与Zabbix Agent结合使用的,所以这台Zabbix Server也要安装Zabbix Agent,当然在这之前我们已经在Zabbix Server上安装过Zabbix Agent。 8 | ```js 9 | # 下载插件rpm包 10 | [root@Zabbix-server ~]# wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm 11 | 12 | # 安装插件 13 | [root@Zabbix-server ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm 14 | 警告:percona-zabbix-templates-1.1.8-1.noarch.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID cd2efd2a: NOKEY 15 | 准备中... ################################# [100%] 16 | 正在升级/安装... 17 | 1:percona-zabbix-templates-1.1.8-1 ################################# [100%] 18 | 19 | Scripts are installed to /var/lib/zabbix/percona/scripts 20 | Templates are installed to /var/lib/zabbix/percona/templates 21 | 22 | # 跳转到模板目录下,需要将配置项文件复制到/etc/zabbix/zabbix_agentd.d/目录下 23 | [root@agent zabbix_agentd.d]# cd /var/lib/zabbix/percona/templates/ 24 | [root@agent templates]# ls 25 | userparameter_percona_mysql.conf zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml 26 | [root@agent templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/ 27 | ``` 28 | ###### 3. 导入模板 29 | 将/var/lib/zabbix/percona/templates/下的模板文件zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml拷贝出来,通过导入的方式添加这个模板。但是由于/var/lib/zabbix/percona/templates/下的模板版本比较低,所以不能成功导入。所以这里需要下载新的模板,模板下载地址:[zbx_percona_mysql_template.xml](https://yqall01.baidupcs.com/file/1d8671ec0c4ed833a46777d39eb58f17?bkt=en-40ebf341379bd9a09cbd46121497f4543ebb3655473caf8d6ef9b9418218d0140dd6568892d4d5d141c3b6ed568d139771bb1a12fb943b3047a173694e3df01d&fid=3598778341-250528-810203754126101&time=1591014563&sign=FDTAXUGERLQlBHSKfW-DCb740ccc5511e5e8fedcff06b081203-bVMhNz%2BfgBPvb%2BLL5iNu3zHYr1o%3D&to=74&size=517237&sta_dx=517237&sta_cs=3074&sta_ft=xml&sta_ct=7&sta_mt=7&fm2=MH%2CYangquan%2CAnywhere%2C%2Cshanghai%2Cct&ctime=1478267803&mtime=1506479460&resv0=-1&resv1=0&resv2=rlim&resv3=5&resv4=517237&vuk=1341537225&iv=0&htype=&randtype=&newver=1&newfm=1&secfm=1&flow_ver=3&pkey=en-4e460e445728adc605cb4aeb60cb37e30569194bf146d015ee12f5075bc56d04c1fbba276a910daeea857fe95a2d10ba156e71c40ad5c4fc305a5e1275657320&sl=68616270&expires=8h&rt=sh&r=895000670&vbdid=1608359299&fin=zbx_percona_mysql_template.xml&fn=zbx_percona_mysql_template.xml&rtype=1&dp-logid=3545109637442360956&dp-callid=0.1&hps=1&tsl=200&csl=200&fsl=-1&csign=D7MLdW2zR6RW6apozIPybJJqtDo%3D&so=0&ut=6&uter=4&serv=0&uc=3176236016&ti=8f692c02a37bcacc8a21722b98f4cd7d472fde114e9cbace&hflag=30&adg=c_e11812cf66835421ee7602a531b9185a&reqlabel=250528_f_7861bc33c58f0c7e60b5eed42fb788ec_-1_23c7c237e57ac19643ed7bc52f3ea722&by=themis)。![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060120323217.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 30 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601203345930.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 31 | ###### 4. 模板不兼容的处理 32 | 处理方式1:安装一个低版本的Zabbix 2.2,然后再导入这个模板 33 | 34 | 处理方式2:升级Zabbix 2.2到4.0,然后导出模板 35 | ###### 5. 测试取监控项的值 36 | 模板导入之后,要重启Zabbix Agent使模板生效。然后开始测试取MySQL监控的项的值。 37 | ```js 38 | # 模板导入之后,要重启Zabbix Agent使模板生效 39 | [root@Zabbix-server ~]# systemctl restart zabbix-agent 40 | # 查看监控项 41 | [root@Zabbix-server zabbix_agentd.d]# cat userparameter_percona_mysql.conf 42 | UserParameter=MySQL.Sort-scan,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kt 43 | UserParameter=MySQL.slave-stopped,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jh 44 | UserParameter=MySQL.Com-replace,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jz 45 | ... 46 | UserParameter=MySQL.running-slave,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave 47 | [root@Zabbix-server zabbix_agentd.d]# sh -x /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh op 48 | ... 49 | # 使用调试模式执行取值的命令 50 | [root@Zabbix-server zabbix_agentd.d]# sh -x /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ij 51 | + ITEM= 52 | + HOST=localhost 53 | ++ dirname /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh 54 | + DIR=/var/lib/zabbix/percona/scripts 55 | + CMD='/usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg' 56 | + CACHEFILE=/tmp/localhost-mysql_cacti_stats.txt 57 | ... 58 | # 执行这个php脚本取值 59 | [root@Zabbix-server zabbix_agentd.d]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg 60 | gg:0[root@Zabbix-server zabbix_agentd.d]# 61 | 62 | # 如果报MySQL拒绝用户的错误,就需要修改连接MySQL的用户名密码等(如果是二进制安装的,一定要协商MySQL的socket路径) 63 | [root@Zabbix-server zabbix_agentd.d]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php 64 | $mysql_user = 'zabbix'; 65 | $mysql_pass = ''; 66 | $mysql_port = 3306; 67 | $mysql_socket = NULL; 68 | 69 | # 这时候就可以取值了 70 | [root@Zabbix-server zabbix_agentd.d]# sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ih 71 | 319916 72 | [root@Zabbix-server zabbix_agentd.d]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items oj 73 | oj:6[root@Zabbix-server zabbix_agentd.d]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items ih 74 | ih:310965[root@Zabbix-server zabbix_agentd.d]# 75 | ``` 76 | 监控数据库不是每个监控项都要取一次值,而是监控一次生成缓存(文件),**`5分钟之后把这个缓存文件删除`** 再监控下一次。每一次 **`监控的间隔默认是300s`**,可以通过修改 /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh 脚本来修改这个值。 77 | ```js 78 | # 修改脚本,将取值的默认间隔设置为30s 79 | [root@Zabbix-server zabbix_agentd.d]# vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh 80 | 81 | # 缓存文件 82 | [root@Zabbix-server zabbix_agentd.d]# ll /tmp/localhost-mysql_cacti_stats.txt 83 | -rw-r--r-- 1 root root 1393 6月 1 11:48 /tmp/localhost-mysql_cacti_stats.txt 84 | ``` 85 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060123451266.png) 86 | ```js 87 | # 上面手动执行脚本取值生成的缓存文件的用户和用户组都是root,很容易出问题,提示权限拒绝,所以要删除。 88 | [root@Zabbix-server zabbix_agentd.d]# rm -r /tmp/localhost-mysql_cacti_stats.txt 89 | 90 | # 使用zabbix_get来取值,这里要把key复制粘贴下来,不要使用gg什么的 91 | [root@Zabbix-server zabbix_agentd.d]# zabbix_get -s 127.0.0.1 -k MySQL.Open-files 92 | 5 93 | # 这时候临时的缓存文件属于zabbix用户和zabbix用户组 94 | [root@Zabbix-server zabbix_agentd.d]# ll /tmp/localhost-mysql_cacti_stats.txt 95 | -rw-rw-r-- 1 zabbix zabbix 1398 6月 1 11:56 /tmp/localhost-mysql_cacti_stats.txt 96 | ``` 97 | >**`zabbix在执行脚本的时候使用的用户是zabbix`** 98 | ###### 6. 主机链接新模板 99 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601235814126.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 100 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200601235852242.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 101 | 设置每页显示200行,默认是50行: 102 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060200001163.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 103 | 设置间隔,与服务器中的设置一致是30s: 104 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602000344599.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 105 | 查看最新数据: 106 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602000456421.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 107 | ###### 7. 主从状态监控项 108 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602001017610.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 109 | 对于主库是没有MySQL同步进程的,所以主从状态监控项是取不到的,所以 **`需要禁用这个监控项`**。如果是从库,报帐号密码错误,可能是脚本的原因,get_mysql_stats_wrapper.sh: 110 | ```shell 111 | ITEM=$1 112 | HOST=localhost 113 | DIR=`dirname $0` 114 | CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg" 115 | CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt" 116 | 117 | if [ "$ITEM" = "running-slave" ]; then 118 | # Check for running slave 119 | RES=`HOME=~zabbix mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','` 120 | if [ "$RES" = " Yes, Yes," ]; then 121 | echo 1 122 | else 123 | echo 0 124 | fi 125 | exit 126 | elif [ -e $CACHEFILE ]; then 127 | # Check and run the script 128 | TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt` 129 | TIMENOW=`date +%s` 130 | if [ `expr $TIMENOW - $TIMEFLM` -gt 30 ]; then 131 | rm -f $CACHEFILE 132 | $CMD 2>&1 > /dev/null 133 | fi 134 | else 135 | $CMD 2>&1 > /dev/null 136 | fi 137 | 138 | # Parse cache file 139 | if [ -e $CACHEFILE ]; then 140 | cat $CACHEFILE | sed 's/ /\n/g; s/-1/0/g'| grep $ITEM | awk -F: '{print $2}' 141 | else 142 | echo "ERROR: run the command manually to investigate the problem: $CMD" 143 | fi 144 | ``` 145 | 那就可以试试不要使用zabbix用户取值,使用其它用户,如root用户。所以,需要修改: 146 | ```shell 147 | RES=`HOME=~zabbix mysql -uroot -p123456 -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','` 148 | ``` 149 | ```js 150 | # 这里在没有修改的情况下也是可以取到值的,不过这里是主库,取到的值是0 151 | [root@Zabbix-server zabbix_agentd.d]# zabbix_get -s 127.0.0.1 -k MySQL.running-slave 152 | 0 153 | ``` 154 | -------------------------------------------------------------------------------- /8.Zabbix4.0自动化监控.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 自动化监控概述 3 | 自动化监控有两种方式,一种是自动发现,也就是根据ip一个个去扫描,但是 **`效率是比较低的`**。另外一种自动化监控的方式是Zabbix自带的 **`自动注册`**。下面将通过自动注册来完成自动化监控。 4 | ###### 2. 配置自动注册的动作 5 | 设置 **`动作`** 和一系列动作相关的操作。**`动作是自动注册的前提,不配置动作就不能完成自动注册,当把动作禁用后,那么就相当于把自动注册给关闭了。`** 6 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602005156782.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 7 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060200541889.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 8 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602005641655.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 9 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602010204999.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 10 | 完成一个自动注册的动作后,可以直接克隆在这个动作基础上作修改进添加新的的动作。这里添加了两个动作,一个是监控web主机的动作,另一个是监控数据库主机的动作: 11 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602010419865.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 12 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602010601274.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 13 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602103143178.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 14 | 动作添加完成后,可以先删除所有主机,等配置好Zabbix Agent的配置文件并重启后,监控界面就会显示被监控的主机。 15 | ###### 3. 配置Zabbix Agent的配置文件 16 | 配置Zabbix Agent配置文件的目的是设置元数据,与在Web界面上设置的一致,用来唯一标识一台机器。先来配置Zabbix Server所在机器上的Agent,测试动作是否设置成功。 17 | ```js 18 | [root@Zabbix-server ~]# cd /etc/zabbix/ 19 | [root@Zabbix-server zabbix]# vim zabbix_agentd.conf 20 | [root@Zabbix-server zabbix]# grep -Ev '^$|#' zabbix_agentd.conf 21 | ... 22 | Server=127.0.0.1 # 所在的主机IP 23 | ServerActive=127.0.0.1 # 与Server一样 24 | Hostname=Zabbix server # 主机名(会在web界面显示) 25 | HostMetadata=db # 元数据 26 | ... 27 | [root@Zabbix-server zabbix]# systemctl restart zabbix-agent 28 | ``` 29 | 重启之后,可以发现新增加了一台监控的主机(事先已经删除了所有监控主机): 30 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602094539745.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 31 | 10.0.0.3的机器上也做同样的设置,只是需要修改Server必须是Zabbix Server所在的机器,也就是10.0.0.2,还有ServerActive=10.0.0.2。主机的名字可以自定义,元数据这里可以使用db。 32 | ```js 33 | [root@agent zabbix]# grep -Ev '^$|#' zabbix_agentd.conf 34 | ... 35 | Server=10.0.0.2 36 | ServerActive=10.0.0.2 37 | Hostname=10.0.0.3 38 | HostMetadata=web 39 | ... 40 | [root@agent zabbix]# systemctl restart zabbix-agent 41 | ``` 42 | 设置之后也会把这台主机监控起来: 43 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602102354704.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 44 | ###### 4. 动作日志 45 | 动作执行后,由于设置了发送邮件,会向管理员发送邮件,在动作日志中可以查看动作的执行日志: 46 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602114233568.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 47 | ###### 5. 报警时间设置 48 | 这部分是补充内容,当要求某些项目在指定时间不报警,可以右两种方法。第一种方法是全局设置,不推荐: 49 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602104200768.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 50 | 第二种是针对监控项设置报警时间: 51 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602104516754.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 52 | 不可以在触发器里配置。 53 | -------------------------------------------------------------------------------- /9.Zabbix4.0 Agent主动模式.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. 主动模式与被动模式 3 |       默认情况下,Zabbix Agent是被动模式。被动模式下,Zabbix Server会一个监控项一个监控项地向Zabbix Agent上获取,**`获取非常频繁,消耗更多的资源`**。被动模式最大的特点是监控项更新几乎都是间隔1s。主动模式下,Zabbix Agent主动去找Zabbix Server获取任务清单,Zabbix Server会把任务清单发给Zabbix Agent。这样Zabbix就受到了这些监控项,Zabbix Agent采集这些监控项,**`一次性`** 发给Zabbix Server。当然一次性发送的监控项的数目也是有限制的。 4 | ###### 2. 批量设置主动模式 5 | 监控项的类型就可以看出使用了被动模式还是主动模式,如果类型是“Zabbix客户端”,则就是默认的被动模式: 6 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602111429298.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 7 | 可以从模板中修改,模板修改后,**`模板中对应的监控项也会随后发生改变`**。也可以到主机监控项中修改都是可以的,但是在主机监控项修改后,模板中的监控项是不会生效的,模板中的监控项是全局作用的。修改时间间隔什么的也是同样的道理: 8 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602111804538.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 9 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602113055432.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 10 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602113253786.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 11 | ###### 3. 简单检查类型 12 | 简单检查是Zabbix Server向Zabbix Agetn要数据,一般用在: 13 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602113703703.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 14 | vmware中用到的就是简单检查类型: 15 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020060211372868.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 16 | ###### 4. snmp模式队列阻塞的处理 17 | 建议升级Zabbix的版本,旧版本容易出现阻塞现象,如果是新版本,在创建主机或者修改主机信息时可以勾选 **`使用最大量需求`** 可以提高性能: 18 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200602114740113.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Zabbix-Tutorial 2 | Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。 Zabbix能监视各种网络参数,保证服务器系统的安全运营,并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。本教程的长期支持版本Zabbix4.0,主要包括的内容有:Zabbix的安装, 添加监控主机, 添加触发器, 自定义报警, 使用grafana自定义图形, 自定义模板, 使用percona监控MySQL数据库, 自动化监控, Agent主动模式, Zabbix4.0版本升级, 分布式监控, 性能调优等。 3 | ##### [1. Zabbix4.0的安装.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/1.Zabbix4.0%E7%9A%84%E5%AE%89%E8%A3%85.md) 4 | ##### [2. Zabbix4.0添加监控主机.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/2.Zabbix4.0%E6%B7%BB%E5%8A%A0%E7%9B%91%E6%8E%A7%E4%B8%BB%E6%9C%BA.md) 5 | ##### [3. Zabbix4.0添加触发器.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/3.Zabbix4.0%E6%B7%BB%E5%8A%A0%E8%A7%A6%E5%8F%91%E5%99%A8.md) 6 | ##### [4. Zabbix4.0自定义报警.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/4.Zabbix4.0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8A%A5%E8%AD%A6.md) 7 | ##### [5. Zabbix4.0使用grafana自定义图形.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/5.Zabbix4.0%E4%BD%BF%E7%94%A8grafana%E8%87%AA%E5%AE%9A%E4%B9%89%E5%9B%BE%E5%BD%A2.md) 8 | ##### [6. Zabbix4.0自定义模板.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/6.Zabbix4.0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A8%A1%E6%9D%BF.md) 9 | ##### [7. Zabbix4.0使用percona监控MySQL数据库.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/7.Zabbix4.0%E4%BD%BF%E7%94%A8percona%E7%9B%91%E6%8E%A7MySQL%E6%95%B0%E6%8D%AE%E5%BA%93.md) 10 | ##### [8. Zabbix4.0自动化监控.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/8.Zabbix4.0%E8%87%AA%E5%8A%A8%E5%8C%96%E7%9B%91%E6%8E%A7.md) 11 | ##### [9. Zabbix4.0 Agent主动模式.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/9.Zabbix4.0%20Agent%E4%B8%BB%E5%8A%A8%E6%A8%A1%E5%BC%8F.md) 12 | ##### [10. Zabbix4.0 版本升级.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/10.Zabbix4.0%20%E7%89%88%E6%9C%AC%E5%8D%87%E7%BA%A7.md) 13 | ##### [11. Zabbix4.0性能调优.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/11.Zabbix4.0%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98.md) 14 | ##### [12. Zabbix4.0分布式监控.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/12.Zabbix4.0%E5%88%86%E5%B8%83%E5%BC%8F%E7%9B%91%E6%8E%A7.md) 15 | ##### [13. Zabbix4.0中遇到的问题.md](https://github.com/ThanlonSmith/Zabbix-Tutorial/blob/master/Zabbix4.0%E4%B8%AD%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98.md) 16 | -------------------------------------------------------------------------------- /Zabbix4.0中遇到的问题.md: -------------------------------------------------------------------------------- 1 | >@[toc] 2 | ###### 1. Please create database manually, and set the configuration parameters for connection to this database. Press "Next step" button when done. 3 | 问题来源:连接mariadb的时候总是连接不上 4 | 解决方法:创建zabbix数据库的时候应该这样创建:**`create database zabbix character set utf8 collate utf8_bin;`** 5 | ###### 2. Get value from agent failed: cannot connect to [[10.0.0.3]:10050]: [113] No route to host 6 | 问题来源:zabbix server连接监控主机时提示以上 7 | 解决方法:关闭监控主机的防火墙,**`systemctl stop firewalld`**,永久关闭使用 **`systemctl disable firewalld`**。 8 | ###### 3. cannot start alert manager service: Cannot bind socket to "/tmp/zabbix_server_alerter.sock": [13] Permission denied. 9 | 问题来源:Zabbix从低版本升级到高版本后重启Zabbix Server失败,日志报这个错误 10 | 解决方法:关闭SELINUX防火墙就可了,将SELINUX的值设置为disable,具体操作如下: 11 | ```js 12 | [root@localhost ~]# vim /etc/selinux/config 13 | [root@localhost ~]# grep -Ev '^$|#' /etc/selinux/config 14 | SELINUX=disable 15 | SELINUXTYPE=targeted 16 | ``` 17 | >**`配置完成后要重启系统!!!`** 18 | ###### 4. cannot start preprocessing service: Cannot bind socket to "/tmp/zabbix_server_preprocessing.sock": [13] Permission denied 19 | 问题来源:同上 20 | 解决方法:同上 21 | ###### 5.active check configuration update from [x.x.x.x:10051] started to fail (ZBX_TCP_READ() timed out) 22 | 问题来源:Zabbix Proxy下的客户端(Zabbix Agent)日志报错 23 | 解决方法:实际上这是不影响监控系统的使用,只需要在配置文件 **`/etc/zabbix/zabbix_agentd.conf`** 中把 **`ServerActive=xxxx`** 给注释了,不用配置。 24 | ###### 6. failed to accept an incoming connection: connection from "x.x.x.x" rejected, allowed hosts: "x.x.x.x" 25 | 问题来源:使用Zabbix Proxy作代理监控Zabbix Agent时,客户端(Zabbix Agent)报错 26 | 解决方法:在Web页面上添加代理下的监控主机时,这些监控主机中Zabbix Agent的配置文件中 **`Hostname的值一定要于这里的“主机名称”的值完全相同`**。 27 | ```js 28 | [root@proxy-agent ~]# grep -Ev "^$|#" /etc/zabbix/zabbix_agentd.conf 29 | ... 30 | Hostname=Zabbix agent 31 | ... 32 | ``` 33 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200604030805563.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoYW5sb24=,size_16,color_FFFFFF,t_70) 34 | --------------------------------------------------------------------------------