Distributed system monitoring zabbix installation, deployment and use

Table of contents

One, zabbix monitoring

1. What is zabbix

2. Zabbix function

3. Zabbix operating mechanism

4. Three architectures of zabbix

①C/S structure

②zabbix-proxy-client architecture

③master-zabbix-client architecture

5. Working principle and data direction of zabbix

6, zabbix monitoring mode

7. Zabbix deployment

8. Zabbix graphical page display settings 

Two, Zabbix monitoring use

1. Install zabbix monitoring client

2. The server verifies connectivity

3. Add the agent host to the web page

4. Configure the host template

5. Customize monitoring content

6. Web page configuration custom monitoring template

① Create a template

② Create an application set (for managing monitoring items) 

③ Create monitoring items

④ Create a trigger

⑤ Create graphics 

⑥Set email alarm

⑦Add a warning email

7, zabbix automatic discovery and automatic registration

①zabbix automatic discovery instructions

②Ensure that the monitoring server agent2 client is alive

③Delete the original client host

④ Client server add hosts

⑤Automatic discovery of web pages

⑥Discover the client 

⑦ Verify the findings


One, zabbix monitoring

1. What is zabbix

zabbix: It is an open source and free, automatic discovery service and distributed monitoring of network devices. It can monitor application layer services and centrally manage and display them with web front-end pages.

2. Zabbix function

Monitor server cpu load, server memory usage, server disk usage and network status, and middleware can also be monitored.

Disadvantages: only supports traditional operation and maintenance, does not support containers

3. Zabbix operating mechanism

Zabbix is ​​a C/S architecture composed of zabbbix server and zabbix agent

zabbix server: Responsible for storing and displaying hardware information, and passing it to the web side to display configuration through B/S mode

zabbix agent: monitor and collect server information, the port number is 10050

4. Three architectures of zabbix

①C/S structure

The monitored machine is directly connected to zabbix, zabbix agent is responsible for collecting server information, and zabbix server is responsible for storing and displaying hardware information through the web

②zabbix-proxy-client architecture

There is a proxy agent between the monitored machine and zabbix. The zabbix agent transmits the collected information to the agent, and the agent transmits the same information to the zabbix server for front-end page display and data storage.

③master-zabbix-client architecture

 There are node nodes under the master, which can store data. The node has its own configuration file and database, and is responsible for synchronizing the configuration information and monitoring data with the master. The node can directly access the host or access the proxy proxy.

5. Working principle and data direction of zabbix

①The zabbix agent collects the monitoring data on the host and transmits the collected data to the zabbix server

②The zabbix server stores the data in its own database after receiving the data

③ Then extract the data from the database for analysis, whether to call the police

④ After the analysis is completed, the server displays the interface data on the web front-end page

6, zabbix monitoring mode

Active mode: zabbix agent actively transmits the collected monitoring information to zabbix server

Passive mode: zabbix server indexes the collected monitoring information to zabbix agent, and zabbix agent returns the collected data 

7. Zabbix deployment

① A 2-core 4G memory database, at least 2 cores 2G

systemctl disable --now firewalld
#永久关闭并现在立即关闭防火墙
setenforce 0
#关闭selinux
hostnamectl set-hostname zbx-server
#更改主机名
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm 
#获得zabbix下载yum源
cd /etc/yum.repos.d
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' zabbix.repo
vim zabbix.repo
#编辑配置文件 开启安装源
[zabbix-frontend]
......
enabled=1          #1表示开启安装源
......
#进入yum源目录文件并使用sed将国外源替换为阿里云源
yum clean all && yum makecache
#清除原理yum源缓存并加载新的yum
yum install -y zabbix-server-mysql zabbix-agent
#安装zabbix客户端和服务端
yum install -y centos-release-scl 
#安装scl,原因为便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4zabbix要求php版本为7.2以上,若达到要求则无须安装scl
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
#安装连接数据库和连接apache前端页面的连接工具
yum install -y mariadb-server mariadb
systemctl enable --now mariadb
#安装并开启数据库
mysql_secure_installation         
#初始化数据库,并设置密码,如 abc123选择执行,先回车,然后输入2次自己想设置的密码,其他全部yes即可
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
#创建zabbix库并设置库格式为utf-8
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
#创建并授权zabbix远程登录用户密码为zabbix
flush privileges;
#刷新数据
rpm -ql zabbix-server-mysql
#查询zabbix数据库中配置文件的位置
zcat /usr/share/doc/zabbix-server-mysql-5.0.33/create.sql.gz | mysql -uroot -pabc123 zabbix(导入的库名)
#将zabbix数据库格式导入数据库中,此处需要等待10s左右
vim /etc/zabbix/zabbix_server.conf 
DBPassword=zabbix					#124行,去掉#注释然后指定 zabbix 数据库的密码
#编辑zabbix配置文件将设置的远程登录用户的密码zabbix输入进去保存退出
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai		#24行,取消注释,修改时区
#编辑php的配置文件,将时区改为亚洲上海,注意去掉前面的;在此文件中表示注释
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
#重启zabbix服务php服务并设置开机自启

8. Zabbix graphical page display settings 

①The browser enters the server address where the zabbix address is deployed, such as this machine: http://192.168.30.11/zabbix to enter the configuration page

②Click the netxt step to enter the next step to check the zabbix configuration, all statuses must be ok, if there is any problem, you need to check the configuration on the server side 

③If all configurations are normal, continue to click Next to log in to the database with the zabbix account 

④ After connecting to the database, the next step is to configure zabbix information

⑤ After configuring zabbix, check the configuration items and click Next to save the installation

⑥ After the information check is complete, click End to complete the installation

⑦After login verification, the default account is: Admin and the default password is: zabbix 

⑧ After login, the main page is as follows

⑨Modify the zabbix language to Chinese, click user settings and select the language as Chinese, click update to save

Two, Zabbix monitoring use

1. Install zabbix monitoring client

 Turn on another server to install the zabbix agent client system

systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-agent01
bash
#关闭防火墙和selinux,更改主机名并运行bash刷新主机名
yum install -y ntpdate
ntpdate -u ntp.aliyun.com
#服务端和客户端都配置时间同步
mv /etc/localtime{,.bak}
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date
#客户端配置时区,与服务器保持一致
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
#设置 zabbix 的下载源,安装 zabbix-agent2
vim /etc/zabbix/zabbix_agent2.conf
#修改配置文件,修改内容如下
Server=192.168.30.11			
#80行,指定 zabbix 服务端的 IP 地址
ServerActive=192.168.30.11		
#120行,指定 zabbix 服务端的 IP 地址
Hostname=zbx-agent01			
#131行,指定当前 zabbix 客户端的主机名
systemctl start zabbix-agent2
systemctl enable zabbix-agent2
netstat -natp | grep zabbix
#设置zabbix-agent2开机自启并现在启动,检查端口是否存在

2. The server verifies connectivity

yum install -y zabbix-get
#安装 zabbix 主动获取数据的命令
zabbix_get -s '192.168.30.12' -p 10050 -k 'agent.ping'
#返回结果为1则表示连接成功
zabbix_get -s '192.168.30.12' -p 10050 -k 'system.hostname'
#可以显示客户端zbx-agent01的主机名表示连接成功

3. Add the agent host to the web page

① Click [Host] in [Configuration] on the left menu bar, and click [Create Host]

4. Configure the host template

5. Customize monitoring content

1.明确需要执行的 linux 命令
who | wc -l
2.创建 zabbix 的监控项配置文件,用于自定义 key
vim /etc/zabbix/zabbix_agent2.conf
#可以将自定义的监控项配置文件创建在 zabbix_agent2.d 目录中
268 Include=/etc/zabbix/zabbix_agent2.d/*.conf
#自定义监控项的格式如下
291 #	Format: UserParameter=<key>,<shell command>
cd /etc/zabbix/zabbix_agent2.d/
vim UserParameter_login.conf
#添加内容如下
UserParameter=login.user,who|wc -l
#UserParameter为键不可变login.user为键值名称逗号后可写命令或脚步
systemctl restart zabbix-agent2
#重启zabbix-agent2
3.在服务端验证新建的监控项
zabbix_get -s '192.168.30.12' -p 10050 -k 'login.user'
#返回值为1则表示监控项无问题

6. Web page configuration custom monitoring template

① Create a template


        Click [Template] in [Configuration] on the left menu bar, click [Create Template]
[Template Name] set to Template Login User
[Visible Name] set to Template Login User
[Group] select Template
[Description] to customize
Click [Add] Now you can search for Template Login User in [Name]

② Create an application set (for managing monitoring items) 

 Click [Application Collection] on the upper menu bar, click [Create Application Collection]
[Name], set it as Login User,
and click [Add]

 

③ Create monitoring items

Click [Monitoring Item] on the upper menu bar, and click [Create Monitoring Item]

[Name] is set to Number of login users
[Key value] is set to login.user #The key value must be consistent with that set in the custom monitoring item configuration file
[Update interval] is set to 10s
[Historical data retention time] Storage period 30d #Retention time can be customized and set
Click【Add】 

④ Create a trigger

[Name] is set to Number of login users is greater than 3
[Severity] is set to general severity
[Expression] click to add, [Monitoring item] click to select Number of login users, [Function] to select last(), [Result] Select > 3, click [Insert]
and click [Add]

⑤ Create graphics 


[Name] is set to Number of login users
[Width], [Height] can directly use the default value
[Monitoring Item] Click to add and check the related monitoring item Number of login users, [Function] select the largest, and the other can keep the default value
Click [ Add to】

⑥Set email alarm

Click [Alarm Media Type] in [Management] on the left menu bar, and click [Create Media Type] 

 

⑦Add a warning email

Click [User Settings] on the left menu bar --> [Alarm Media], click [Add]

7, zabbix automatic discovery and automatic registration

①zabbix automatic discovery instructions

The automatic discovery and automatic registration refer to the relative server. If it is passive discovery, you need to manually add the client machine to zabbix. If it is automatic discovery, it is configured on zabbix, and zabbix will actively scan it.

②Ensure that the monitoring server agent2 client is alive

server agent2上执行:
systemctl is-active zabbix-agent2.service 
#返回active即agent2正常

③Delete the original client host

Click [Host] in [Configuration] on the left menu bar, check the original client host, and click Delete

④ Client server add hosts

vim /etc/hosts
192.168.30.11 zbx-server
192.168.30.12 zbx-agent01

⑤Automatic discovery of web pages

Click [Automatic Discovery] in [Configuration] on the left menu bar, click [Create Discovery Rule] [Name] set to mynetw3ork [
IP Range] set to 192.168.30.1-254
[Update Interval] set to 30s
[Check] click [Add] ], [Check type] select Zabbix client, [Port range] is set to 10050, [Key value] is set to system.uname [
Device uniqueness criteria] Select IP address
[Host name] Select DNS name
[Visible name] Select Host name
Check [Enabled], click [Update]

 

⑥Discover the client 

Click [Actions] in [Configuration] on the left menu bar, select [Discover Actions] in the upper menu,
check [Discover Actions], and click [Enable]

⑦ Verify the findings

Click [Host] in [Configuration] on the left menu bar to refresh. After waiting for a while, the automatically discovered client host will be refreshed. It takes a while.

Guess you like

Origin blog.csdn.net/weixin_67287151/article/details/130083170