监控系统和zabbix基本知识
为了保证集群的健康,我们需要检测服务器的状态,就有了监控系统,专门来监控服务器的状态。
服务器状态出现问题,可以用告警的形式来提示运维人员。
服务器上部署的关键的业务组件,nginx、mysql等等,如果出现故障,他也可以提示给用户,可以
让我们尽快的处理问题。监控系统只能发现,不能解决问题。
zabbix是简介
zabbix是基于web页面的(可视化系统),分布式的系统监控和网络监控的企业级的开源监控方案。
zabbix的功能
1、监控服务器关键硬件的状态
2、可以监控服务器的关键指标
3、可以监控服务器上关键应用的状态
4、可以监控网络设备(路由器、交换机等等)
5、关于监控容器(zabbix5开始已经兼容容器的监控,但是效果不是很好,目前监控容器的主流还是普罗米修斯)
zabbix的组件
C/S模式:client server,服务端和客户端,即zabbix server和zabbix-agent,C/S模式是一个数据采集的模式,客户端把数据发送给服务端。
B/S模式:browser/server,浏览器和服务端,浏览器访问服务端的内容。B/S模式提高的是数据的展示和相关的监控项的配置。
zabbix server:服务端
zabbix-agent:客户端
zabbix proxy:服务端的代理服务器,可以代替服务端收集客户端的数据,然后转发给服务端。可以降低服务端直接收集客户端数据带来的系统压力。
zabbix get:zabbix的命令行工具
zabbix安装
这里我们使用三台服务器完成zabbix实操,架构如下:
zw4:192.168.254.14,zabbix-server
zw5:192.168.254.15,zabbix-agent2、zabbix-proxy
zw6:192.168.254.31,zabbix-agent2
163网易邮箱,做smtp服务器
配置主服务器zw4
1、下载安装deb包
wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb #下载deb包
dpkg -i zabbix-release_6.4-1+ubuntu22.04_all.deb #编译安装

apt-get update #更新源
2、安装zabbix
apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent -y #安装zabbix及依赖环境
apt install mariadb-server -y #安装数据库
mysql_secure_installation #先初始化数据库
登录数据库并创建用户和赋权

3、导入mysql架构到zabbix库

4、修改zabbix服务端的配置文件并重启



5、登录服务端界面




这时候我们发现有很多乱码
6、解决界面乱码
准备好simkai.ttf文件,这个文件在windows的c盘

修改php配置文件




可以发现乱码问题已经解决
7、修改zabbix自己的客户端配置文件和主机映射




8、这时候我们登录界面显示主服务端配置成功
zabbix的可用性

- zbx:默认的,监控服务器设备的网络,以及服务器监控状态,以及告警。
- snmp:监控网络设备
- JMX:开发人员用来监控java应用程序
- ipmi:通过网络管理服务器的电源,温度,风扇速度等等
配置客户端操作zw5
1、下载安装deb包
dpkg -i zabbix-release_6.4-1+ubuntu22.04_all.deb
apt-get update
2、安装zabbix并检查
apt -y install zabbix-agent2


3、配置zabbix客户端配置文件
vim /etc/zabbix/zabbix_agent2.conf


做主机映射并重启后检查端口

1、返回主服务器zw4,在主服务器上安装一个命令行工具

测试服务端与客户端之间是否能通

有数值代表成功,0代表失败
2、在界面添加监控主机zw5


显示监控成功
创建对登录主机数量的监控
在上面安装的基础上,完成监控的创建,如果登录192.168.254.15的主机数超过三个就报警
zabbix的监控的原理
模板------监控项------触发器------实时监控(脚本的实现)
1、查看监控项的配置文件和写在脚本激活方式
vim /etc/zabbix/zabbix_agent2.conf


2、创建自定义监控项文件user.conf


这时候我们回到主服务器上测试下是否配置成功

3、页面操作
创建构建并保存

创建模板

创建监控项并测试


创建触发器

创建图形

添加模板Template Login User

这时候图形显示我们添加的模板正常

这时候我们使用3台远程连接主机登录192.168.254.15,显示了告警

创建监控nginx服务状态
1、配置nginx主配置文件,开启nginx状态统计


2、创建一个自定义监控项文件nginx_test.conf


3、创建nginx监控脚本文件,监控nginx状态

重启zabbix服务后,在主服务器zw4上测试是否成功监控


这时候我们zw5上nginx只有在开启的状态下,才有数值,关闭则是0
4、配置监控项和触发器
创建模板

创建监控项并测试


创建触发器

回到主机更新下模板即完成监控
我们关闭nginx,会发现有告警生成

5、设置邮件告警
创建媒介类型及测试


添加触发器动作



主题:Problem: {EVENT.NAME}
消息:<b>Problem started</b> at {EVENT.TIME} on {EVENT.DATE}<br><b>Problem name:</b> {EVENT.NAME}<br><b>Host:</b> {HOST.NAME}<br><b>Severity:</b> {EVENT.SEVERITY}<br><b>Operational data:</b> {EVENT.OPDATA}<br><b>Original problem ID:</b> {EVENT.ID}<br>{TRIGGER.URL}
这时候状态会变成已启用

然后回到用户Admin,点开添加告警媒介


这时候当我们关闭nginx服务后,会触发报警并自动发送给我们邮箱

监控mysql的状态
如果zw6的mysql服务关闭,发生邮件告警。
1、首先客户端zw6安装zabbix,将zw6加入到主zabbix,方法和上面配置客户端zw5一样

2、创建自定义监控项文件mysql_test1.conf

这时候我们回到主服务器上测试下是否配置成功

3、配置监控项和触发器
添加模板

添加监控项并测试

添加触发器

回到主机更新下模板即完成监控
我们关闭mysql,会发现有告警生成

4、设置邮件告警
创建媒介类型及测试

添加触发器动作

动作2我们之前做nginx的时候配置过了,直接点更新即可。
这时候状态会变成已启用

然后回到用户Admin,告警媒介也不需要再添加了。
这时候当我们关闭mysql服务后,会触发报警并自动发送给我们邮箱
