Zabbix
一、Zabbix组件说明
1.1 Zabbix概述
zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案(基于GPL V2)。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
1.2 工作结构
{width="5.768055555555556in" height="3.732638888888889in"}
Zabbix-server: 监控服务端
Zabbix-agent: 监控客户端
Zabbix-web: 监控web页面
Php: 动态解析
Mysql: 存储数据
Zabbix-proxy: 负责收集agent信息给server端
1.3 Zabbix工作进程
zabbix安装完成后会产生5个程序: zabbix agentd、 zabbix get、 zabbix proxy、zabbix_sender、 zabbix_server, zabbix_jva_gateway是可选,这个需要另外安装
·zabbix_agentd:客户端守护进程,此进程收集客户端数据,例如cpu负载、内存、硬盘使用情况等
·zabbix_get: zabbix工具,单独使用的命令,通常用于排错
· zabbix_sender: zabbix工具,用于发送数据给 server或者 proxy,在脚本完成之后使用 sender主动将数据提交
·zabbix_server: zabbix服务端守护进程,所有的数据都是被提交或主动提交到zabbix server端
·zabbix_ proxy: zabbixserve代理守护进程。功能类似,唯一不同的是它只是一个中转站,
它需要把收集到的数据提交/被提交到server里
·zabbix_java_gateway: zabbix2.0之后引入的一个功能。顾名思义:Java网关,类似
agentd,但是只用于Java方面。需要特别注意的是,它只能主动去获取数据,而不能被动获
取数据。它的数据最终会给到 server或者proxy
1.4 硬件要求
{width="5.768055555555556in" height="0.8611111111111112in"}
二、构建Zabbix监控
2.1 初始环境
关闭firewalld以及selinux
2.2 构建lamp环境
[root@localhost yum.repos.d]# yum -y install httpd php mariadb-server
or
[root@localhost yum.repos.d]# yum -y install httpd php php-gd php-ldap php-mysqlnd php-json php-bcmath php-mbstring php-xml mariadb mariadb-server mysql-devel libevent-devel pcre-devel libcurl-devel curl-* net-snmp* libxml2-*
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl enable maraidb
2.3 Zabbix安装
[root@localhost ~]# rpm -Uvh <https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm>
#安装阿里镜像源
[root@localhost mysql-5.7.32]# vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
name=Zabbix Official...
basrurl=http://....
enabled=1
gpgcheck=1
gpgkey=file://.....
#所有的https://repo.zabbix.com/ 改成 https://mirrors.aliyun.com/zabbix/
#vim编辑器下使用:%s/http:\/\/repo.zabbix.com\//https:\/\/mirrors.aliyun.com\/zabbix\//g进行替换
[root@localhost ~]# yum clean all #清除yum缓存
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-agent
#下载zabbix-agent端
[root@localhost ~]# yum -y install centos-release-scl
[root@localhost mysql-5.7.32]# yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
#进入数据库 为zabbix建库授权
[root@localhost htdocs]# mysql -u root -p123
MySQL [(none)]> create database zabbix character set utf8 collate utf8_bin;
MySQL [(none)]> create user zabbix@localhost identified by '123';
MySQL [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
MySQL [(none)]> \q
#导入zabbix数据库
[root@localhost htdocs]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p Zabbix
#配置zabbix server配置数据库
Default:
DBPassword=123
#为zabbix配置前端PHP
[root@localhost htdocs]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
[root@localhost ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@localhost ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
2.4 测试
Ip地址/Zabbix
2.5 修改监控页面字体
Windows下win+r搜索fonts复制一个字体到linux中
将字体移动到/usr/share/zabbix/assets/fonts/下,并修改后缀为ttf
[root@localhost ~]# chmod o+w msyh.ttf
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'msyh');
修改字体名称为拷贝过来的字体名称
三、添加监控主机-agent
3.1 添加监控主机
监控主机端安装
[root@localhost ~]# mkdir /usr/local/zabbix-agent
[root@localhost ~] # tar zxf zabbix_agent-5.0.6-linux-3.0-amd64-static.tar.gz -C /usr/local/zabbix-agent/
[root@localhost ~]# cp -a /usr/local/zabbix-agent/conf/zabbix_agentd.conf /usr/local/etc/
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
useradd Zabbix
[root@localhost ~]# /usr/local/zabbix-agent/sbin/zabbix_agentd
Server=192.168.100.101 #监控端地址
ServerActive=192.168.100.101 #监控端地址
Hostname=192.168.100.100 #被监控端地址即可
查看是否启动成功
[root@localhost ~]# netstat -antup \| grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:\* LISTEN 3926/zabbix_agentd
3.2 Zabbix-web端添加主机
{width="1.926842738407699in" height="3.30167104111986in"}
{width="2.9579636920384953in" height="0.9998753280839895in"}
{width="5.768055555555556in" height="3.4368055555555554in"}
{width="5.768055555555556in" height="1.604861111111111in"}
添加监控模板,否则没有监控项目。无任何信息。添加后在监测--主机中即可看到到添加的主机
四、添加自定义监控项
4.1 在命令行中输出值或者写shell脚本输出值(类似于下面的监控nginx)
[root@localhost ~]# df -hT|grep '^/dev/sda1'|awk '{print $6}'|cut -d '%' -f 1
15
# 输出/dev/sda1的分区磁盘使用率
4.2 修改agent端配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=check.sda1, df -hT|grep '^/dev/sd'|awk '{print $6}'|cut -d '%' -f 1
[root@localhost ~]# systemctl restart zabbix-agent.service
4.3 Zabbix-server端测试访问数据
[root@localhost ~]# zabbix_get -s 192.168.10.31 -p 10050 -k 'check.sda1'
15
4.4 在zabbix-web端添加自定义监控项
{width="2.2080577427821524in" height="3.426654636920385in"}
{width="5.768055555555556in" height="1.1736111111111112in"}
{width="4.145314960629921in" height="2.4788571741032372in"}
{width="5.768055555555556in" height="5.881944444444445in"}
进行测试
{width="5.768055555555556in" height="2.375in"}
测试成功成功取到值
4.5 使用post提交方式批量添加自定义监控项
五、自定义触发器
5.1 添加触发器
{width="2.010165135608049in" height="3.062117235345582in"}
{width="5.768055555555556in" height="2.435416666666667in"}
{width="3.176686351706037in" height="1.3539971566054243in"}
{width="5.768055555555556in" height="4.934027777777778in"}
表达式添加时选择对应监控项
5.2 测试
[root@localhost ~]# curl 192.168.10.33:80/nginx_status
{width="3.7391163604549433in" height="1.5206430446194226in"}
5.3 自定义触发器表达式进阶
{width="5.768055555555556in" height="5.8590277777777775in"}
创建恢复表达式,当值低于多少时恢复。
六、设置邮件报警和微信报警
6.1 邮件报警
在管理报警媒介类型
{width="5.768055555555556in" height="4.839583333333334in"}
{width="5.768055555555556in" height="3.2090277777777776in"}
添加收件人
{width="5.768055555555556in" height="1.1833333333333333in"}
添加动作
{width="1.6872889326334208in" height="3.020456036745407in"}
{width="5.768055555555556in" height="3.35625in"}
{width="5.768055555555556in" height="2.973611111111111in"}
6.2 微信报警
微信报警需要企业号
6.3 报警机制修改
{width="5.768055555555556in" height="2.816666666666667in"}
报警第一步之后等待时间,在此时间内问题没有被处理还。步骤1-1表示只执行一次
{width="5.768055555555556in" height="4.8069444444444445in"}
步骤2-0为第二步骤一直执行,每次等待问题处理时间10分钟。每隔10分钟再检测如触发器再触发就再继续执行一次动作
报警后可尝试远程命令自动处理,需提前在zabbix-server端安装ansible并且对agent的主机ssh设置免密和免交互,以及在zabbix-server端的配置文件。还可在命令处执行ansible剧本
EnableRemoteCommands=1 #开启远程命令
AllowRoot=1 #开启允许root
添加此两项
{width="5.768055555555556in" height="5.622222222222222in"}
七、自定义图形
7.1 Zabbix默认出图
配置主机图形创建图形
{width="5.768055555555556in" height="3.307638888888889in"}
7.2 Grafana出图
7.2.1 安装grafana
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-7.3.7-1.x86_64.rpm #下载清华源rpm包
7.2.2 安装grafana
[root@localhost ~]# yum -y install grafana-7.3.7-1.x86_64.rpm
7.2.3 启动grafana
[root@localhost ~]# systemctl start grafana-server.service
[root@localhost ~]# systemctl enable grafana-server.service
7.2.4 访问grafana
http://192.168.10.32:3000/ 默认账号:admin 密码admin 初次登录需改密
7.2.5 安装zabbix的grafana插件
[root@localhost ~]# grafana-cli plugins list-remote |grep zabbix
#查看插件名称
[root@localhost ~]# grafana-cli plugins install alexanderzobnin-zabbix-app
#下载插件
[root@localhost ~]# systemctl restart grafana-server.service
#重启grafana
在grafana中开启zabbix插件
7.2.6 新建一个zabbix数据源
{width="2.1872265966754156in" height="2.8954713473315836in"}
{width="2.4788571741032372in" height="0.7707370953630797in"}
{width="5.768055555555556in" height="0.7638888888888888in"}
{width="1.5206430446194226in" height="0.708244750656168in"}
{width="5.768055555555556in" height="1.3618055555555555in"}
在点击home下可查看到zabbix即可查看到
{width="5.768055555555556in" height="2.770138888888889in"}
7.2.7 导入dashboard模板
八、自定义zabbix模板
8.1 创建自定义模板
{width="5.768055555555556in" height="2.0819444444444444in"}
{width="5.768055555555556in" height="2.50625in"}
{width="5.768055555555556in" height="0.3020833333333333in"}
{width="5.768055555555556in" height="1.0819444444444444in"}
{width="5.768055555555556in" height="1.6743055555555555in"}
复制过来的监控项默认不会将应用集也复制过来,所以需要自己创建应用集全选应用集批量更新添加新的应用集
创建触发器,图形,自动发现
九、添加自动发现规则
9.1 添加规则
同上面被控端安装,两台分别ip地址为192.168.100.102、192.168.100.103
{width="2.1768110236220473in" height="5.1347747156605426in"}
在配置--->自动发现-->创建发现规则
{width="5.768055555555556in" height="4.867361111111111in"}
9.2 添加发现后动作
#在上面完成后,发现主机了需要自动链接模板
{width="2.1351498250218723in" height="3.0517016622922135in"}
{width="2.864225721784777in" height="1.6352121609798775in"}
在此处选择发现动作
{width="5.768055555555556in" height="1.979861111111111in"}
{width="5.768055555555556in" height="1.7673611111111112in"}
9.3 测试
{width="5.768055555555556in" height="2.4097222222222223in"}
等待一段时间后会自动添加主机
9.4 Zabbix-agent自动注册到server端
9.4.1 Zabbix-server端配置动作自动注册
{width="5.2910050306211724in" height="5.207682633420823in"}
自动注册动作
{width="1.1977668416447944in" height="0.635336832895888in"}
创建动作
{width="5.768055555555556in" height="2.0006944444444446in"}
{width="5.768055555555556in" height="1.8090277777777777in"}
9.4.2 Zabbix-agent端配置
{width="2.2705489938757655in" height="0.3541229221347332in"} #agent端配置服务端地址
{width="2.9683792650918637in" height="0.4374453193350831in"} #向哪台server端发起注册请求
{width="2.5413484251968503in" height="0.41661417322834643in"} #注册时主机的主机名,可自定义,不能重复。推荐ip地址。
{width="2.0934886264216974in" height="0.34370734908136485in"} #agent端注册时附带的信息,可供server端验证
9.4.3 测试
[root@localhost ~]# systemctl restart zabbix-agent.service
#agent端重启服务,server-web上马上出现了主机
{width="5.768055555555556in" height="1.8798611111111112in"}
十、Nginx监控
10.1 源码安装ngxin
[root@localhost ~]# useradd -s /sbin/nologin -M nginx
#创建nginx运行用户
[root@localhost ~]# tar zxf nginx-1.19.4.tar.gz
[root@localhost ~]# cd nginx-1.19.4
#解压进入nginx
[root@localhost nginx-1.19.4]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
#开启健康检查模块
[root@localhost nginx-1.19.4]# make && make install
#编译安装
[root@localhost nginx-1.19.4]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#创建软连接方便调用
[root@localhost nginx-1.19.4]# echo "this is test" >/usr/local/nginx/html/index.html
#创建测试页面
[root@localhost nginx-1.19.4]# nginx
#启动nginx
[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf
#打开nginx主配置文件,添加一个location
{width="3.9474234470691165in" height="0.7811526684164479in"}
[root@localhost nginx]# kill -HUP $(cat /usr/local/nginx/logs/nginx.pid)
#重新载入配置文件
#查看nginx状态
{width="4.5827602799650045in" height="1.2915048118985126in"}
10.2 编写脚本监控nginx
#!/bin/bash
#date 2021.1.28
#Author yang
nginx_status_fun() { #nginx健康值获取函数
nginx_port=$1 #nginx端口,此参数为main函数的第二个参数
nginx_command=$2 #传入的需获得的nginx状态值 ,此参数为main函数的第三个参数
nginx_active_con(){ #获得nginx的active值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null| grep 'Active' |awk '{print $3}'
}
nginx_reading(){ #获得nginx的reading值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null| grep 'Reading' |awk '{print $2}'
}
nginx_writing(){ #获得nginx的writing值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null| grep 'Writing' |awk '{print $2}'
}
nginx_waiting(){ #获得nginx的waiting值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null| grep 'Waiting' |awk '{print $2}'
}
nginx_accepts(){ #获得nginx的accepts值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null|awk 'NR==3{print $1}'
}
nginx_handled(){ #获得nginx的handled值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null|awk 'NR==3{print $2}'
}
nginx_requests(){ #获得nginx的requests值
/usr/bin/curl "http://127.0.0.1:\\"\\$nginx_port\\"/nginx_status\\" 2>/dev/null|awk 'NR==3{print $3}'
}
case $nginx_command in #判断传入参数要执行的动作
active)
nginx_active_con;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
esac
}
main() { #主函数入口
case $1 in #主函数第一个参数
nginx_status) #判断主函数第一个参数是不是nginx_status
nginx_status_fun $2 $3 ; #main函数的第一个参数为nginx_status_fun的第一个参数
;;
*) #如果$1输入的不是nginx_status则提示输入正确值
echo "please input nginx_status"
esac
}
main $1 $2 $3 #调用主函数
10.3 在zabbix_agent.conf中添加用户自定义监控项
{width="5.768055555555556in" height="1.5298611111111111in"}
定义自定义项agent脚本,调用上面的脚本
{width="5.768055555555556in" height="0.19583333333333333in"}
nginx.status[*]中括号中的代表给这个自定义传递的所有参数,也可自己自定个数
[root@localhost ~]# zabbix_get -s 192.168.10.33 -p 10050 -k "nginx.status[nginx_status,80,accepts]"
35
Zabbix服务端使用以上命令可以测试访问是否可以从agent获得数据
10.4 Zabbix-server端web配置模板
十一、Redis监控
11.1 Redis监控脚本
Redis默认开启info页面
[root@localhost tmp]# redis-cli info
十二、Tomcat监控
12.1 Agent端部署tomcat
上传java的jdk,并解压缩到/usr/local/jdk
声明环境变量
[root@localhost bin]# vim /etc/profile
#JAVA - JDK
export JAVA_HOME=/usr/local/jdk
export JAVA_BIN=/usr/local/jdk/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
测试java-jdk是否可用
{width="5.768055555555556in" height="0.7270833333333333in"}
上传tomcat二进制包,并解压缩到/usr/local/tomcat
[root@localhost bin]# ./startup.sh
启动tomcat
测试访问
{width="5.768055555555556in" height="2.373611111111111in"}
12.2 配置tomcat监控
[root@localhost bin]# vim catalina.sh #打开tomcat启动脚本
{width="5.768055555555556in" height="0.5541666666666667in"}
找到此处添加以下内容
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=192.168.10.31"
[root@localhost bin]# ./catalina.sh start
#启动tomcat
12.3 配置java-gateway
{width="5.768055555555556in" height="1.7083333333333333in"}
由于zabbix是php编写,无法直接获取tomcat(java)的数据,所以zabbix需要java-gateway在中间获取数据
Java-gateway可不部署在java的web服务器上,可另外服务器安装
在需要配置java-gateway的服务器上配置zabbix镜像源
[root@localhost webapps]# # rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@localhost webapps]# # yum clean all
#安装zabbix-java-gateway软件包
[root@localhost webapps]# yum -y install zabbix-java-gateway
#配置java-gateway配置文件
[root@localhost webapps]# vim /etc/zabbix/zabbix_java_gateway.conf
{width="2.562179571303587in" height="0.45827646544181977in"}
{width="2.0622419072615923in" height="0.39578412073490815in"}
{width="1.8226891951006123in" height="0.3332917760279965in"} #此为工作线程数
{width="1.2290135608048993in" height="0.32287620297462816in"} 建议此值设大一点,避免tomcat服务因访问大没有及时响应导致错误判断
#启动zabbix-java-gateway
[root@localhost webapps]# systemctl start zabbix-java-gateway
#设为开机自启动
[root@localhost webapps]# systemctl enable zabbix-java-gateway
12.4 Zabbix-server端配置
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
{width="2.92671697287839in" height="1.9789195100612424in"}
{width="2.405949256342957in" height="0.5207677165354331in"}
此处与上面的zabbix-java-gateway线程数相同即可
[root@localhost ~]# systemctl restart zabbix-server
#重启zabbix-server生效
12.5 Zabbix-web端配置模板
十三、Php监控
13.1 安装nginx和php
[root@localhost yum.repos.d]# vim /etc/php-fpm.d/www.conf
#修改php配置文件
{width="1.7497812773403325in" height="0.7186603237095363in"}
[root@localhost yum.repos.d]# vim /etc/nginx/conf.d/www.conf
#对nginx添加php支持
{width="5.768055555555556in" height="2.1805555555555554in"}
[root@localhost yum.repos.d]# echo "<?php phpinfo(); ?>" >/usr/share/nginx/html/index.php
#创建测试页面
{width="5.113943569553806in" height="2.218472222222222in"}
#测试访问
13.2 开启phps的status
[root@localhost yum.repos.d]# vim /etc/php-fpm.d/www.conf
{width="3.2079319772528434in" height="0.49993766404199474in"}
#取消注释并修改
[root@localhost yum.repos.d]# vim /etc/nginx/conf.d/www.conf
#修改nginx配置文件开启php_status
{width="3.9474234470691165in" height="0.4895220909886264in"}
[root@localhost yum.repos.d]# systemctl restart php-fpm
[root@localhost yum.repos.d]# systemctl reload nginx
#重启服务
{width="3.7599464129483815in" height="3.2808398950131235in"}
测试访问
13.3 Agent端上传配置文件和脚本
[root@localhost ~]# mv check_php_status.sh /src/
[root@localhost ~]# mv zxb_php_status.conf /etc/zabbix/zabbix_agentd.d/
[root@localhost ~]# systemctl restart zabbix-agent.service
13.4 Server端测试
[root@localhost ~]# zabbix_get -s 192.168.10.31 -p 10050 -k "php_status[slow_requests,80]"
0
13.5 链接模板
十四、Web检测
14.1 添加web监测
{width="5.768055555555556in" height="1.2409722222222221in"}
{width="1.895596019247594in" height="0.6457524059492563in"}
{width="5.768055555555556in" height="3.341666666666667in"}
十五、Mysql监控
15.1 使用percona插件监控
Mysql默认开启监控页面
15.2 安装percona插件脚本
{width="5.768055555555556in" height="1.3701388888888888in"}
安装后的脚本存放在/var/lib/zabbix/percona/templates
15.3 配置percona
下载上面目录中的xml模板文件
将conf文件拷贝至agent端的目录下
十六、网站uv、pv、ip统计
16.1 第三方平台
如腾讯分析等,将其提供的js代码放在站点源代码中
16.2 使用开源软件
Matomo
十七、监控维度
{width="5.768055555555556in" height="1.0909722222222222in"}
十八、SNMP协议
18.1 服务端安装snmp
[root@localhost ~]# yum -y install net-snmp
[root@localhost ~]# vim /etc/snmp/snmpd.conf
{width="5.166020341207349in" height="0.4791065179352581in"}
#修改此处自定义
{width="4.957713254593176in" height="0.27079943132108486in"}
#添加一行
[root@localhost ~]# systemctl start snmpd.service
18.2 客户端(zabbix-web端)配置
[root@localhost ~]# yum -y install net-snmp-utils.x86_64
[root@localhost ~]# snmpwalk -v 2c -c 123456 192.168.10.31 .1.3.6.1.2.1.25.2.2.0
HOST-RESOURCES-MIB::hrMemorySize.0 = INTEGER: 1863004 Kbytes
#测试访问OK
18.3 Zabbix-web端添加snmp主机
{width="5.768055555555556in" height="2.863888888888889in"}
如果在snmp服务端修改的public名称 在添加主机的模板后需要求改主机模板中继承的宏值
{width="5.082697944006999in" height="1.4269050743657044in"}
{width="5.768055555555556in" height="0.8361111111111111in"}
十九、Zabbix主、被动配置
19.1 Zabbix主、被区别
Zabbix默认为被动模式:server端需要数据的话向agent端索要,每种监控项索要一次。
Zabbix主动模式:agent端向server询问需要的数据,agent获得数据后主动发给server端。
19.2 主动模式配置
19.2.1 Zabbix-server端配置
{width="5.768055555555556in" height="3.2569444444444446in"}
在模板中选择全克隆
{width="5.768055555555556in" height="2.6881944444444446in"}
{width="5.768055555555556in" height="1.5395833333333333in"}
在克隆的模板的监控项中选择批量更新
{width="4.843144138232721in" height="5.072282370953631in"}
将类型修改为zabbix客户端(主动模式)
在修改过后可能不会全部显示主动模式,因为修改的模板是链接的别的模板,需要将链接的模板也克隆并修改为主动模式,然后重新在主模板中链接克隆的模板即可。
19.2.2 Zabbix-agent端配置
{width="2.3434569116360455in" height="0.37495297462817145in"}
{width="3.291255468066492in" height="0.31246062992125984in"}
{width="2.6871642607174104in" height="0.4270297462817148in"}
[root@localhost ~]# systemctl restart zabbix-agent.service
#agent端重启
{width="5.768055555555556in" height="4.538194444444445in"}
二十、Zabbix-proxy模式
20.1 环境配置
Zabbix-server:192.168.10.32
Zabbix-proxy:网卡1:192.168.10.35
网卡2:10.0.0.3
Zabbix-agent:10.0.0.4
20.2 Zabbix-server端安装
略。。。。。。
20.3 Zabbix-agent端安装
略。。。。。。
20.4 Zabbix-proxy端安装
20.4.1 安装zabbix官方源或其他源
[root@localhost ~]# rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo
%s#http://repo.zabbix.com\\#https://mirror.tuna.tsinghua.edu.cn/zabbix\\#g
20.4.2 安装zabbix-proxy端
[root@localhost ~]# yum -y install zabbix-proxy-mysql.x86_64
[root@localhost ~]# yum -y install mariadb mariadb-server
#安装数据库
[root@localhost ~]# systemctl start mariadb.service
#启动数据库
MariaDB [(none)]> create database zabbix_proxy default charset utf8;
#创建数据库并设置字符集
MariaDB [(none)]> grant all on zabbix_proxy.* to zbx_proxy@'localhost' identified by '123456';
#授权用户
[root@localhost ~]# zcat /usr/share/doc/zabbix-proxy-mysql-5.0.8/schema.sql.gz |mysql -u zbx_proxy -p123456 zabbix_proxy
#导入表数据
[root@localhost ~]# vim /etc/zabbix/zabbix_proxy.conf
{width="2.447610454943132in" height="0.4686909448818898in"}
{width="2.4580260279965005in" height="0.39578412073490815in"}
#此处的hostname要与主机名相同hostnamectl set-hostname zabbix_proxy
{width="2.2913801399825022in" height="0.32287620297462816in"}
{width="2.3226268591426074in" height="0.39578412073490815in"}
{width="2.0205807086614174in" height="0.39578412073490815in"}
{width="2.5517639982502187in" height="0.4374453193350831in"}
[root@localhost ~]# systemctl restart zabbix-proxy.service
#启动proxy
20.5 Zabbix-web-server上添加proxy
{width="2.4371948818897637in" height="3.6453772965879265in"}
{width="5.768055555555556in" height="2.4590277777777776in"}
{width="5.768055555555556in" height="1.0944444444444446in"}
20.6 Zabbix-agent端配置
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
{width="2.166395450568679in" height="0.4270297462817148in"}
{width="2.395533683289589in" height="0.3541229221347332in"}
{width="2.041411854768154in" height="0.38536854768153983in"}
[root@localhost ~]# systemctl restart zabbix-agent.service
20.7 Zabbix-server和zabbix-proxy端同步文件心跳
{width="2.6455030621172355in" height="0.4270297462817148in"} #此为server和proxy之间的心跳检测间隔
{width="2.3642880577427823in" height="0.4061996937882765in"} #此为server和proxy之间同步配置文件间隔
二十一、Zabbix优化性能
1)对mysq写多读少 mariadb5.5 innodb升级mysq5.,7 tokuda
2)去掉无用监控项增加监控项的取值间隔减少历史数据保存周期
3)把被动模式修改为主动模式增加zabⅸx- proxy
4)针对于 zabbix- server进程调优谁忙就加大它的进程数量
5)对于 zabbix- server缓存调优谁的剩余内存少就加大它的缓存值
6)对zabbⅸx历史数据和趋势图的表进行周期性分表
{width="2.1768110236220473in" height="5.1347747156605426in"}
{width="5.768055555555556in" height="4.867361111111111in"}