Introduction to zabbix | Monitoring construction and deployment

1. Introduction to Zabbix

Zabbix is ​​an enterprise-level open source solution that provides distributed system monitoring and network monitoring functions based on a web interface.
Zabbix can monitor various network parameters to ensure the safe operation of the server system; and provide a flexible notification mechanism to allow system administrators to quickly locate./solve various problems that exist. zabbix consists of 2 parts, zabbix server and optional component zabbix agent. Collect data through c/s mode, and display and configure it on the Web side through B/S mode. zabbix server can provide remote server/network status monitoring, data collection and other functions through SNMP, zabbix agent, ping, port monitoring and other methods, and
it can run on platforms such as Linux.
The zabbix agent needs to be installed on the monitored target server. It mainly completes the collection of hardware information or memory, CPU and other information related to the operating system.

Two. Zabbix monitoring principle

The zabix agent is installed on the monitored host. The zabbix agent is responsible for collecting local data on a regular basis and sending it to the zabbix server. After receiving the data, the zabbix server stores the data in the database, and users can see it based on Zabbix WEB Data presents images on the front end. When zabbix monitors a specific project,
the project will set a trigger threshold. When the monitored indicator exceeds the threshold set by the trigger, some necessary actions will be taken, including: sending information (email, WeChat, SMS) ), sending commands (shell commands, reboot, restart, install, etc.).

Three. The five most common program components monitored by Zabbix

zabbix server: zabbix server daemon process, in which zabbix_agent, zabbix_get, zabbix_sender, and zabbix proxy data are finally submitted to zabbix server;

zabbix agent: client daemon process, responsible for collecting client data, for example: collecting CPU load, memory, hard disk usage, etc.

ozabbix proxy: zabbix distributed proxy daemon process, usually larger than 500 hosts, requires distributed monitoring architecture deployment;

zabbix get: zabbix data receiving tool, a command used alone, usually executed on the server or proxy_ to obtain remote client information;

ozabbix sender: zabbix data sending tool, the user sends data to the server or proxy end, usually the user takes a long time to check.

Fourth, build zbx monitoring

4.1 Prepare two virtual machines

zabbix-server 内存至少 2G,推荐 4G
192.168.10.10                 zabbix 服务端
192.168.10.20                 zabbix 客户端 +nginx
systemctl stop firewalld      关闭防火墙
setenforce  0                 关闭selinux
192.168.10.10         hostnamectl set-hostname zbx-server
192.168.10.20         hostnamectl set-hostname zbx-agent
yum install -y ntpdate
ntpdate -u ntp.aliyun.com       #配置时间同步

Please add a picture description
Please add a picture description

4.2 The server client obtains the download source of zabbix

rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm 
更换 zabbix.repo 为阿里源
cd /etc/yum.repos.d
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' zabbix.repo                      # 将文档中更换zabbix为aliyun
yum clean all && yum makecache           #清理缓存源

Please add a picture description

4.3 Server installation modification 192.168.10.10

安装 zabbix-server-mysql,zabbix-agent
yum install -y zabbix-server-mysql zabbix-agent
安装SCL
yum install -y centos-release-scl
修改zabbix-front前端源,安装zabbix前端环境到scl环境下4
vim zabbix.repo 
第11行修改
enabled=1                           #开启安装源
之后在安装
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl

Please add a picture description

4.4 The database required to install zabbix on the server side (192.168.10.10)

安装mariadb并开启
yum install -y mariadb-server mariadb
systemctl enable --now mariadb.service 

修改mariadb密码
mysql_secure_installation
#初始化数据库,并设置密码,如 abc123 

Please add a picture description
Please add a picture description

4.5 Add database user

 添加数据库用户,以及 zabbix 所需的数据库信息
mysql -u root -p abc123

CREATE DATABASE zabbix character set utf8 collate utf8_bin;
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
flush privileges;

Please add a picture description

4.6 Import database information

rpm -ql zabbix-server-mysql                  #查询sql文件的位置
zcat /usr/share/doc/zabbix-server-mysql-5.0.33/create.sql.gz | mysql -uroot -pabc123 zabbix
mysql -uroot -pabc123                 #登录mysql查看
use zabbix;                           #切换到zabbix
show tables;                          #查看zabbix的表

Please add a picture description

4.7 Modify the server configuration file

vim /etc/zabbix/zabbix_server.conf 
124行取消注释 修改成
DBPassword=zabbix

Please add a picture description

4.8 Modify the php configuration file of zabbix

vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
24行,取消注释,修改时区
php_value[date.timezone] = Asia/Shanghai

Please add a picture description

4.9 Start zabbix related services

systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
浏览器访问:http://192.168.10.10/zabbix
点击下一步,设置数据库的密码 zabbix
设置文件界面:点击左边菜单栏的【User settings】,【Language】选择 Chinese(zh_CN),再点击 Update 更
安装完成后,默认的登录账号和密码为:Admin/zabbix新。

Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description

4.10 Solve the problem of Chinese garbled characters on the zabbix-server Web page

yum install -y wqy-microhei-fonts

\cp -f /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

Please add a picture description

Five deployment zabbix client 192.168.10.20

5.1 Install zabbix client package

因为上面我已经讲二台机子同时安装ntp和安装源,所以直接操作以下的
mv /etc/localtime{
    
    ,.bak}                                   #备份时间文件
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime      #创建软连接
yum install -y zabbix-agent2                              #安装zabbix客户端

Please add a picture description

5.2 Modify the client zabbix configuration file

vim /etc/zabbix/zabbix_agent2.conf 
Server=192.168.10.10		#80行,指定 zabbix 服务端的 IP 地址
ServerActive=192.168.10.10		#125行,指定 zabbix 服务端的 IP 地址
Hostname=zbx-agent01			#136行,指定当前 zabbix 客户端的主机名

Please add a picture description
Please add a picture description

5.3 Start client agent2 verification

systemctl start zabbix-agent2
systemctl enable zabbix-agent2

netstat -natp | grep zabbix         #查看服务是否开启


!注意切换到服务端验证 192.168.10.10
在服务端验证 zabbix-agent2 的连通性
yum install -y zabbix-get				    #安装 zabbix 主动获取数据的命令

zabbix_get -s '192.168.10.20' -p 10050 -k 'agent.ping'   
1                                           #这个命令可以验证服务端是否连接成功,1为成功,0为失败

zabbix_get -s '192.168.10.20' -p 10050 -k 'system.hostname'
zbx-agent01

Please add a picture description

6. Add the agent host to the web page

6.1 Create a host

点击左边菜单栏【配置】中的【主机】,点击【创建主机】
【主机名称】设置成 zbx-agent01
【可见的名称】设置成 zbx-agent01-192.168.10.20
【群组】选择 Linux server
【Interfaces】的【IP地址】设置成 192.168.10.20

Please add a picture description

6.2 Create a template

再点击上方菜单栏【模板】
【Link new tamplates】搜索 Linux ,选择 Template OS Linux by Zabbix agent
点击 【添加】

Please add a picture description

6.3 Client add custom monitoring 192.168.10.20

1.明确需要执行的 linux 命令
who | wc -l

2.创建 zabbix 的监控项配置文件,用于自定义 key
vim /etc/zabbix/zabbix_agent2.conf
#可以将自定义的监控项配置文件创建在 zabbix_agent2.d 目录中
273 Include=/etc/zabbix/zabbix_agent2.d/*.conf
#自定义监控项的格式如下
#296 	Format: UserParameter=<key>,<shell command> 复制下来

cd /etc/zabbix/zabbix_agent2.d/

vim UserParameter_login.conf
UserParameter=login.user,who|wc -l

systemctl restart zabbix-agent2

3.在服务端验证新建的监控项
zabbix_get -s '192.168.10.20' -p 10050 -k 'login.user'

Please add a picture description

vim UserParameter_login.conf

insert image description here
Please add a picture description

6.4 Create a custom monitoring item template on the web page

1.创建模板
点击左边菜单栏【配置】中的【模板】,点击【创建模板】
【模板名称】设置成 Template Login User
【可见的名称】设置成 Template Login User
【群组】选择 Templates
【描述】可自定义
点击 【添加】,此时就可在【链接的模板】中搜索到 Template Login User 了

insert image description here
Please add a picture description

6.5 Create an application set (for managing monitoring items)

点击上方菜单栏【应用集】,点击【创建应用集】
【名称】设置成 Login User
点击 【添加】

Please add a picture description
Please add a picture description
Please add a picture description

6.6 Create monitoring items

点击上方菜单栏【监控项】,点击【创建监控项】【名称】设置成 Number of login users【键值】设置成 login.user #键值必须要与自定义的监控项配置文件中设置的保持一致、【更新间隔】设置成 10s、【历史数据保留时长】Storage period 30d #保留时间可自定义设置、点击 【添加】

Please add a picture description
Please add a picture description

6.7 Create a trigger (when the monitored item obtains the monitored value, compare it with the preset value of the trigger to determine whether to alarm)

点击上方菜单栏【触发器】,点击【创建触发器】
【名称】设置成 Number of login users is greater than 3
【严重性】设置成 一般严重
【表达式】点击添加,【监控项】点击选择 Number of login users,【功能】选择 last(),【结果】选择 > 3,点击 【插入】
点击 【添加】

Please add a picture description

6.8 Creating graphics

点击上方菜单栏【图形】,点击【创建图形】
【名称】设置成 Number of login users
【宽】、【高】可直接采用默认值
【监控项】点击添加勾选相关监控项 Number of login users,【功能】选择 最大,其它可保持默认值
点击 【添加】

Please add a picture description
Please add a picture description

6.9 Associating hosts with templates

(一个主机可以关联多个模板)点击左边菜单栏【配置】中的【主机】,点击你要关联的主机、点击上方菜单栏【模板】,【Link new tamplates】搜索 login,选择 Template Login User,点击【更新】

Please add a picture description
Please add a picture description
Please add a picture description

6.10 Set email alarm

点击左边菜单栏【管理】中的【报警媒介类型】,点击【创建媒体类型】
【名称】设置成 qq_Email
【SMTP服务器】设置成 smtp.qq.com
【SMTP服务器端口】设置成 25
【SMTP HELO】设置成 qq.com
【SMTP电邮】设置成 自己的邮箱地址,例如 704397225@qq.com
【认证】选择 用户名和密码
【用户名称】设置成 自己的邮箱地址,例如 704397225@qq.com
【密码】可登录QQ邮箱页面,点击【设置】-->【账户】中的【生成授权码】,通过短信获取授权码
【描述】可自定义                        
点击上方菜单栏【Message templates】,点击【添加】,【Message type】选择 问题,点击【更新】
点击 【添加】,并测试功能

点击左边菜单栏【User settings】-->【报警媒介】,点击【添加】
【类型】选择 qq_Email
【收件人】设置成 704397225@139.com
【当启用时】设置成 1-7,00:00-24:00
点击 【添加】
再点击 【更新】

点击左边菜单栏【配置】中的【动作】,选择相对应的动作名称,点击【启用】

Please add a picture description

Please add a picture description

Please add a picture description

Please add a picture description
Please add a picture description
Please add a picture description
Please add a picture description

Guess you like

Origin blog.csdn.net/m0_75015568/article/details/130086672