DAY 76 distributed monitoring platform: zabbix

Common monitoring software on the market:

  • Traditional operation and maintenance: zabbix, Nagios
  • Cloud native environment: Prometheus (developed in go language)

zabbix overview

As an operation and maintenance, you need to use the monitoring system to check the server status and website traffic indicators, and use the data of the monitoring system to understand the results of the online release and the health status of the website

With an excellent monitoring software, we can:

  • Browse all server status of the entire website through a friendly interface
  • The monitoring data can be easily viewed on the front end of the web
  • Can look back to find system problems and alarms when an accident occurs

What is 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.
  • zabbix consists of 2 parts, zabbix server and optional component zabbix agent. Collect data through the c/s mode, and display and configure it on the web side through the B/s mode.
  • zabbix server can provide remote server/network status monitoring, data collection and other functions through SNMP (Simple Network Management Protocol), zabbix agent, ping, port monitoring and other methods, and it can run on platforms such as Linux. (Support multiple platforms, windows also supports)
  • The zabbix agent needs to be installed on the monitored target server, which mainly completes the collection of hardware information or memory, CPU and other information related to the operating system

Zabbix monitoring principle

The zabbix agent is installed on the monitored host. The zabbix agent is responsible for collecting the local data of the client regularly and sending it to the zabbix server. After receiving the data, the zabbix server stores the data in the database. 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.).

Based on zabbix-web, users can view the displayed data images in the WEBUI interface, and perform related configuration management. Users can also set triggers for monitoring items in the WEBUI interface, such as the monitored data indicators exceed the threshold set by the trigger. , will send notification information or some emergency operation instructions

Five common programs in zabbix

Zabbix monitoring is deployed in the system, including five common programs: zabbix server, zabbix agent, zabbix proxy, zabbix get, zabbix sender, etc.

(1) zabbix server: zabbix server daemon process, in which the data of zabbix_agent, zabbix_get, zabbix_sender, and zabbix_proxy are finally submitted to zabbix server;

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

(3) zabbi xproxy: zabbix distributed proxy daemon process, usually larger than 500 hosts, requires distributed monitoring architecture deployment;

(4) zabbix get: zabbix data receiving tool, a command used alone, usually executed on the server or proxy side to obtain the remote client information command;

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

zabbix port number

  • The zabbix server zabbix_server uses port 10051 by default.
  • The client zabbix_agent2 uses port 10050 by default

Install zabbix 5.0

It is recommended to use version 5.0/version 4.6/version 4.8 instead of version 6.0.

  • zabbix-server memory at least 2G, 4G is recommended;
#关闭防火墙
systemctl disable --now firewalld
setenforce 0

 Get 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 

 change hostname

hostnamectl set-hostname zbx-server

Replace zabbix.repo with Ali source

cd /etc/yum.repos.d
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' zabbix.repo
yum clean all && yum makecache
yum install -y zabbix-server-mysql zabbix-agent

 

 

Install SCL (Software Collections)

  • It is convenient to install a higher version of php later. The default php version installed by yum is 5.4, which is too low. The zabbix 5.0 version requires a minimum version of php 7.2.0. SCL enables multiple versions of software to be used on the same machine without affecting the dependencies of the entire system. Packages will be installed in the /etc/opt/rh directory
     
yum install -y centos-release-scl 

 Modify the zabbix-front front-end source, install the zabbix front-end environment to the scl environment

vim zabbix.repo
......
[zabbix-frontend]
......
enabled=1          #开启安装源
......
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
#安装mysql及apache相关工具

 Install the database required by zabbix

yum install -y mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation         #初始化数据库,并设置密码

 

 

Add database users and database information required by zabbix

mysql -u root -pabc123
 
CREATE DATABASE zabbix character set utf8 collate utf8_bin;  #创建数据库并且设置字符集为utf8
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix'; #允许用户zabbix对zabbix中所有表进行操作且用户密码为zabbix
flush privileges;    #刷新权限

 Import database information

rpm -ql zabbix-server-mysql 		#查询 sql 文件的位置
 
zcat /usr/share/doc/zabbix-server-mysql-5.0.15/create.sql.gz | mysql -uroot -pabc123 zabbix
#zcat命令可以直接查看数据包里的文件内容

 

 

 Modify the zabbix-server configuration file and modify the database password

vim /etc/zabbix/zabbix_server.conf 
......
DBPassword=zabbix					#124行,指定 zabbix 数据库的密码

Modify the php configuration file of zabbix

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

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

 

 

点击下一步,设置数据库的密码 zabbix
安装完成后,默认的登录账号和密码为:Admin/zabbix
设置文件界面:点击左边菜单栏的【User settings】,【Language】选择 Chinese(zh_CN),再点击 Update 更新。

 

 

 

 

 Solve the Chinese garbled problem of 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

At this time, look back and see that the garbled code has been resolved

 Deploy zabbix client

  • The zabbix 5.0 version uses a new version of the client agent2 developed in the golang language.
    The zabbix server zabbix_server uses port 10051 by default, and the client zabbix_agent2 uses port 10050 by default.
#关闭防火墙并修改主机名
systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-agent01

 Both server and client configure time synchronization

yum install -y ntpdate
ntpdate -u ntp.aliyun.com

The client configures the time zone to be consistent with the server

mv /etc/localtime{,.bak}
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 
date

 Set the download source of zabbix and install 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

 Modify the agent2 configuration file

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

 

 

 Start zabbix-agent2

systemctl start zabbix-agent2
systemctl enable zabbix-agent2
 
netstat -natp | grep zabbix
tcp6       0      0 :::10050                :::*                    LISTEN      63784/zabbix_agent2

 Verify the connectivity of zabbix-agent2 on the server side

yum install -y zabbix-get				#安装 zabbix 主动获取数据的命令
 
zabbix_get -s '192.168.137.15' -p 10050 -k 'agent.ping'
1
 
zabbix_get -s '192.168.137.15' -p 10050 -k 'system.hostname'
zbx-agent01

 

 

Add the agent host to the web page

点击左边菜单栏【配置】中的【主机】,点击【创建主机】
【主机名称】设置成 zbx-agent01
【可见的名称】设置成 zbx-agent01-192.168.137.15
【群组】选择 Linux server
【Interfaces】的【IP地址】设置成 192.168.137.15
 
再点击上方菜单栏【模板】
【Link new tamplates】搜索 Linux ,选择 Template OS Linux by Zabbix agent
点击 【更新】

 

 

 Customize monitoring content

Case: Custom monitoring client server login number
requirements: limit the number of logins to no more than 3, and send an alarm message if more than 3

Create a custom key on the client

Specify the linux commands that need to be executed

who | wc -l   #统计登录人数

Create zabbix monitoring item configuration file for custom key

vim /etc/zabbix/zabbix_agent2.conf
#可以将自定义的监控项配置文件创建在 zabbix_agent2.d 目录中269行
Include=/etc/zabbix/zabbix_agent2.d/*.conf
#自定义监控项的格式如下
292行 
#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

Verify the newly created monitoring item on the server side

zabbix_get -s '192.168.137.15' -p 10050 -k 'login.user'
#可以看到获得键的值了

Create custom monitoring item templates on web pages

create template

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

Create an application set (for managing monitoring items)

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

Create monitoring items

 

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

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,点击 【插入】
点击 【添加】

create graphics

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

Associate hosts with templates (a host can be associated with multiple templates

点击左边菜单栏【配置】中的【主机】,点击你要关联的主机
点击上方菜单栏【模板】,【Link new tamplates】搜索 login,选择 Template Login User,点击【更新】
 
此时就点击【监测】中的【主机】,点击你关联主机的【图形】,即可查看到相关的监控项指标

Log in to both terminals at this point

server view

Set email alarm (provided that your mailbox has to open smtp)

点击左边菜单栏【管理】中的【报警媒介类型】,点击【创建媒体类型】
【名称】设置成 qq_Email
【SMTP服务器】设置成 smtp.qq.com
【SMTP服务器端口】设置成 25
【SMTP HELO】设置成 qq.com
【SMTP电邮】设置成 自己的邮箱地址,例如 [email protected]
【认证】选择 用户名和密码
【用户名称】设置成 自己的邮箱地址,例如 [email protected]
【密码】可登录QQ邮箱页面,点击【设置】-->【账户】中的【生成授权码】,通过短信获取授权码
【描述】可自定义
点击上方菜单栏【Message templates】,点击【添加】,【Message type】选择 问题,点击【更新】
点击 【添加】,并测试功能
 
点击左边菜单栏【User settings】-->【报警媒介】,点击【添加】
【类型】选择 qq_Email
【收件人】设置成 [email protected]
【当启用时】设置成 1-7,00:00-24:00
点击 【添加】
再点击 【更新】
 
点击左边菜单栏【配置】中的【动作】
选择相对应的动作名称点击进入,点击 【添加】
【类型】选择 触发器,【触发器】点击选择 Nunber of login users is greater than 3
点击【启用】

Summarize

1确定获取监控指标数值的命令或者脚本路径
 
2在客户端的zabbix-agent2的配置目录中创建*.conf文件在文件里定义监控的键名UserParameter=<key>,<shell command>
 
3在zabbix web界面中自定义监控模板,创建模板->应用集->监控项->触发器->图形
 
4将主机与监控模板关联起来
 
5设置邮件报警创建报警媒介->添加报警媒介一>在动作当中去添加触发器

Guess you like

Origin blog.csdn.net/weixin_57560240/article/details/131040997