Deploy Zabbix (monitoring) with yum!

Table of contents

1. What is zabbix?

Two, zabbix monitoring principle

 3. Install zabbix

3.1 Deploy zabbix server

3.2 Solve the Chinese garbled problem of zabbix-server Web page

3.2.1 Problem solving

 3.3 Deploy zabbix client

3.3.1 Both server and client configure time synchronization

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

3.3.3 Set the download source of zabbix and install zabbix-agent2

3.3.4 Modify the agent2 configuration file

3.3.5 Start zabbix-agent2

3.3.6 Verify the connectivity of zabbix-agent2 on the server side

3.3.7 Add agent host to the web page


1. 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 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.

●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 zabbix agent is installed on the monitored host. The zabbix agent is responsible for regularly collecting local data from the client 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.).

Zabbix monitoring is deployed in the system, including five common programs: zabbix_server, zabbix_agent, zabbix_proxy, zabbix_get, zabbix_sender, etc.

●zabbix server: zabbix server daemon process, the data of zabbix_agent, zabbix_get, zabbix_sender, zabbix_proxy 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.;

●zabbix 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 side to obtain remote clients information orders;

●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.

 3. Install zabbix

3.1 Deploy zabbix server

zabbix-server 内存至少 2G,推荐 4G;

systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-server

//获取 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

yum clean all && yum makecache

yum install -y zabbix-server-mysql zabbix-agent

//安装SCL(Software Collections),便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4,版本过低,zabbix 5.0 版本对 php 版本最低要 7.2.0 版本。SCL 可以使得在同一台机器上使用多个版本的软件,而又不会影响整个系统的依赖环境。软件包会安装在 /opt/rh 目录下。

yum install -y centos-release-scl 

//修改 zabbix-front 前端源,安装 zabbix 前端环境到 scl 环境下
vim zabbix.repo
......
[zabbix-frontend]
......
enabled=1          #开启安装源
......

yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl

//安装 zabbix 所需的数据库
yum install -y mariadb-server mariadb

systemctl enable --now mariadb

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

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

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

//导入数据库信息
rpm -ql zabbix-server-mysql 		#查询 sql 文件的位置

zcat /usr/share/doc/zabbix-server-mysql-5.0.24/create.sql.gz | mysql -uroot -pabc123 zabbix

//修改 zabbix server 配置文件,修改数据库的密码
vim /etc/zabbix/zabbix_server.conf 
......
DBPassword=zabbix					#124行,指定 zabbix 数据库的密码

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

//启动 zabbix 相关服务
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

Browser access: httpd://192.168.237.28/zabbix

 Click Next to set the database password. After the zabbix installation is complete, the default login account and password are: Admin/zabbix Setting file interface: Click [User settings] on the left menu bar, select Chinese (zh_CN) for [Language], and then click Update renew.

3.2 Solve the Chinese garbled problem of zabbix-server Web page

3.2.1 Problem solving

yum install -y wqy-microhei-fonts

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

 3.3 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.

3.3.1 Both server and client configure time synchronization

yum install -y ntpdate

ntpdate -u ntp.aliyun.com

3.3.2 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

3.3.3 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#Zabbix Official Repository' /etc/yum.repos.d/zabbix.repo
yum install -y zabbix-agent2

​

3.3.4 Modify the agent2 configuration file

vim /etc/zabbix/zabbix_agent2.conf

...... Server=192.168.10.22 #80行,指定 zabbix 服务端的 IP 地址

ServerActive=192.168.10.22 #125行,指定 zabbix 服务端的 IP 地址

Hostname=zbx-agent01 #13行,指定当前 zabbix 客户端的主机名

3.3.5 Start zabbix-agent2

systemctl start zabbix-agent2 systemctl enable zabbix-agent2

netstat -natp | grep zabbix

3.3.6 Verify the connectivity of zabbix-agent2 on the server side

yum install -y zabbix-get #安装 zabbix 主动获取数据的命令

zabbix_get -s '192.168.237.27' -p 10050 -k 'agent.ping' 1

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

3.3.7 Add agent host to the web page

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

【Host Name】Set to zbx-agent01

[Visible name] set to zbx-agent01-192.168.10.21

【Group】Select Linux server

[IP address] of [Interfaces] is set to 192.168.10.21

Then click on the top menu bar [Template]

[Link new tamplates] Search for Linux, select Template OS Linux by Zabbix agent and click [Add]

Guess you like

Origin blog.csdn.net/m0_71888825/article/details/132170994