市场上常用的监控软件:
- 传统运维:zabbix、 Nagios
一、zabbix概述
作为一个运维,需要会使用监控系统查看服务器状态以及网站流量指标,利用监控系统的数据去了解上线发布的结果,和网站的健康状态。
利用一个优秀的监控软件,我们可以:
- 通过一个友好的界面进行浏览整个网站所有的服务器状态
- 可以在Web 前端方便的查看监控数据
- 可以回溯寻找事故发生时系统的问题和报警情况
1.1 zabbix是什么?
- zabbix是一个基于Web界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
- zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
- zabbix由2部分构成,zabbix server 与可选组件zabbix agent。 通过c/s 模式采集数据,通过B/s模式在web端展示和配置。
- zabbix server 可以通过SNMP(简单网络管理协议),zabbix agent,ping, 端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它 可以运行在Linux等平台上。(支持多个平台,windows也支持)
- zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。

1.2 zabbix监控原理
zabbix agent安装在被监控的主机上,zabbix agent 负责定期收集客户端本地各项数据,并发送至zabbix server 端,zabbix server收到数据后,将数据存储到数据库中,用户基于zabbix WEB可以看到数据在前端展现图像。
当zabbix 监控某个具体的项目,该项目会设置一个触发器阈值,当被监控的指标超过该触发器设定的阈值,会进行一些必要的动作,动作包括:发送信息(邮件、微信、短信)、发送命令(shell 命令、reboot、 restart、 install 等)。
用户可以基于zabbix-web可以在WEBUI界面中查看展现的数据图像,以及进行相关的配置管理用户还可以在WEBUI界面中设置监控项的触发器,如被监控的数据指标超过触发器设定的阈值,会进行发送通知信息或者一些应急操作指令。
1.3 zabbix常见的五个程序
zabbix监控部署在系统中,包含常见的五个程序: zabbix server、 zabbix agent、 zabbix proxy、zabbix get、zabbix sender 等。
(1) zabbix server: zabbix 服务端守护进程,其中zabbix_agent、 zabbix_ get、zabbix_sender、 zabbix_proxy的数据最终都提交给zabbix server;
(2) zabbix agent: 客户端守护进程,负责收集客户端数据,例如:收集CPU负载、内存、硬盘使用情况等;
(3)zabbi xproxy: zabbix分布式代理守护进程,通常大于500台主机,需要进行分布式监控架构部署;
(4)zabbix get: zabbix 数据接收工具,单独使用的命令,通常在server 或者proxy端执行获取远程客户端信息的命令;
(5)zabbix sender: zabbix 数据发送工具,用户发送数据给server 或proxy端,通常用户耗时比较长的检查。
1.4 zabbix端口号
- zabbix服务端zabbix_server 默认使用10051 端口。
- 客户端zabbix_agent2 默认使用10050 端口。
二、安装zabbix 5.0
建议使用5.0版本/4.6版本/4.8 版本,不使用6.0。
实验环境:
节点 | IP | 安装服务 |
---|---|---|
zabbix-server | 192.168.41.45 | zabbix-server-mysql、zabbix-agent |
zabbix-agent | 192.168.41.46 | zabbix-agent2 |
2.1 部署 zabbix 服务端(端口号10051)
zabbix-server内存至少2G,推荐4G。
zabbix 服务端同时安装zabbix-server-mysql和zabbix-agent,因为服务端所在主机自己也要被监控。
1、关闭防火墙,修改主机名

2、获取 zabbix 的下载源

3、更换 zabbix.repo 为阿里源,安装zabbix-server-mysql、zabbix-agent和SCL



4、修改 zabbix-front 前端源,安装 zabbix 前端环境到 scl 环境下。
修改/etc/yum.repos.d/zabbix.repo文件:


5、安装zabbix所需的数据库



6、添加数据库用户,以及 zabbix 所需的数据库信息



7、修改 zabbix-server 配置文件/etc/zabbix/zabbix_server.conf,修改数据库的密码。

8、修改 zabbix 的 php 配置文件,/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

9、启动 zabbix 相关服务


10、浏览器访问 http://192.168.41.45/zabbix











11、解决 zabbix-server Web页面中文乱码问题


2.2 部署zabbix 客户端(端口号10050)
zabbix 5.0版本采用golang 语言开发的新版本客户端agent2 。
zabbix 服务端 zabbix_server 默认使用 10051 端口,客户端 zabbix_agent2 默认使用 10050 端口。
1、关闭防火墙,修改主机名
systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-agent01
su
2、服务端和客户端都配置时间同步,使用阿里云的时钟源
yum install -y ntpdate
ntpdate -u ntp.aliyun.com
3、客户端配置时区,与服务器保持一致
mv /etc/localtime{,.bak}
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date
4、设置 zabbix 的下载源,安装 zabbix-agent2
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
cd /etc/yum.repos.d
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum install -y zabbix-agent2
5、修改 agent2 配置文件
vim /etc/zabbix/zabbix_agent2.conf
......
Server=192.168.41.45 #80行,指定 zabbix 服务端的 IP 地址
ServerActive=192.168.41.45 #120行,指定 zabbix 服务端的 IP 地址
Hostname=zbx-agent01 #131行,指定当前 zabbix 客户端的主机名
6、启动 zabbix-agent2
systemctl start zabbix-agent2
systemctl enable zabbix-agent2
netstat -natp | grep zabbix
tcp6 0 0 :::10050 :::* LISTEN 4381/zabbix_agent2
7、在服务端验证 zabbix-agent2 的连通性
yum install -y zabbix-get #服务端,安装 zabbix 主动获取数据的命令,get指令
zabbix_get -s '192.168.41.46' -p 10050 -k 'agent.ping'
1 #服务端对客户端进行连通性测试,返回1表示连通
zabbix_get -s '192.168.41.46' -p 10050 -k 'system.hostname'
zbx-agent01 #返回客户端的主机名说明正常连通
1、关闭防火墙,修改主机名

2、服务端和客户端都配置时间同步

3、客户端配置时区,与服务器保持一致

4、设置 zabbix 的下载源,安装 zabbix-agent2


5、修改 agent2 配置文件,/etc/zabbix/zabbix_agent2.conf



6、启动 zabbix-agent2

7、在服务端验证 zabbix-agent2 的连通性


2.3 将客户端加入服务端的监控主机中
在 Web 页面中添加 agent 主机。
1.点击左边菜单栏【配置】中的【主机】,点击【创建主机】
【主机名称】设置成 zbx-agent01
【可见的名称】设置成 zbx-agent01-192.168.41.46
【群组】选择 Linux server
【Interfaces】的【IP地址】设置成 192.168.41.46
2.再点击上方菜单栏【模板】
【Link new tamplates】搜索 Linux ,选择 Template OS Linux by Zabbix agent
点击 【添加】
1、点击左边菜单栏【配置】中的【主机】,点击【创建主机】



2、再点击上方菜单栏【模板】





总结
zabbix工作原理(工作流程):
- zabbix-agent 客户端,部署在被监控的对象主机上,负责定期收集监控数据,发送给zabbix-server 端;
- zabbix-server 收到数据后会将数据存储在数据库中。
- 用户可以基于zabbix-web可以在WEB UI界面中查看展现的数据图像,以及进行相关的配置管理 用户还可以在WEBUI界面中设置监控项的触发器,如被监控的数据指标超过触发器设定的阈值,会进行发送通知信息或者一些应急操作指令。