Table of contents
2. Configure the firewall, Selinux
3. Configure YUM source (not required)
4. Configure time synchronization (not necessary, it is best to configure)
Five, configure the IP address (Agent passive mode needs to be configured, the default passive mode)
1. Install the Zabbix installation package:
2. Display the list of Zabbix installations:
3. Install epel. My system has installed epel-7 before. If it is not installed, install epel
4. Install Zabbix related services
5. Create the initial database: install mysql, install mysql-5.7
7. Configure PHP for the Zabbix front end (version 5.0 is required)
9. Start Zabbix server and agent processes
1. Environment
System: centos7.9
Software version:
mysql: 5.7
zabbix: 5.0
Three servers:
IP1: 192.168.126.141 (primary)
IP2:192.168.126.142 (monitoring machine)
IP3:192.168.126.143 (monitoring machine)
Server side reserved port: 10051
Agent reserved port: 10051
Agent passive mode (default)
The server actively connects to the agent
server and agent are in the same network
Or map agent 10050 port to Server
Agent active mode
The agent actively connects to the server
server and agent are in the same network
Or map server 10051 port to Agent
Zabbix documentation:
Zabbix Chinese documentation https://www.zabbix.com/documentation/5.0/zh/start
2. Configure the firewall, Selinux
1. The following ports need to be opened:
zabbix-web: 80
mysql:3306
zabbix-agent:10050
zabbix-server:10051
2. The firewall does not perform filtering (or close the firewall directly)
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=3360/tcp --permanent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --reload
// If the firewall is turned off, execute as follows
systemctl stop firewalld.service
3. Close selinux
Security-Enhanced Linux (Security-Enhanced Linux), referred to as SELinux, is a Linux kernel module and a security subsystem of Linux.
1) Command to view the status of selinux
sestatus -v
2) Temporarily close selinux
setenforce 0
setenforce 1 Set SELinux to become enforcing mode
setenforce 0 Set SELinux to become permissive mode
3) Permanently shut down selinux
vi /etc/sysconfig/selinux
Change the line inside to SELINUX=disabled
If you want to completely disable SELinux, you need to set the parameter selinux=0 in /etc/sysconfig/selinux
// Modify the SELINUX=disabled of the configuration file, permanently close
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
3. Configure YUM source (not required)
mkdir /etc/yum.repos.d/OldRepo
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/OldRepo/
curl -so /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -so /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i '/aliyuncs.com/d' /etc/yum.repos.d/Centos-7.repo /etc/yum.repos.d/epel-7.repo
4. Configure time synchronization (not necessary, it is best to configure)
#安装ntp服务
yum install -y ntpdate
#同步时间服务器
ntpdate ntp1.aliyun.com
#调整为亚洲上海时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock -w
echo "*/30 * * * * $(which ntpdate) ntp1.aliyun.com > /dev/null 2>&1 && $(which hwclock) -w" > /var/spool/cron/root
chmod 600 /var/spool/cron/root
# 查看日期
date
Five, configure the IP address (Agent passive mode needs to be configured, the default passive mode)
vi /etc/hosts
192.168.126.141 zabbix(主)
192.168.126.142 fw
192.168.126.143 docker1
# 立即生效
/etc/init.d/network restart
6. Install zabbix server
1. Install the Zabbix installation package:
# Download the deployment package
# rpm -ivh is to execute the rpm package command. After executing the following command, it is the yum warehouse for installing zabbix
# Note: cent7 and cent8 download different packages respectively https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=7&db=mysql&ws=apache
Syntax: rpm -ivh file.rpm % This is used to install a new rpm package
rpm -Uvh file.rpm % This is used to upgrade an rpm package
For example:
# 升级:
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
安装新的包:
rpm -ivh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# Clear the YUM cache.
yum clean all
2. Display the list of Zabbix installations:
# Execute the installation: list all your yum repo
Yum repolist Check whether zabbix is included in the current yum library
The result is as follows:
3. Install epel. My system has installed epel-7 before. If it is not installed, install epel
yum -y install epel-release.noarch
4. Install Zabbix related services
1)Install Zabbix server and agent
sudo yum install zabbix-server-mysql zabbix-agent
2)Enable Red Hat Software Collections
sudo yum install centos-release-scl
3) Then edit the configuration file /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.
[zabbix-frontend]
...
enabled=1
...
4) Install Zabbix frontend packages.
sudo yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
5) zabbix command, used to test whether the agent is valid, install zabbix-get
yum install zabbix-get.x86_64
Execute the following example to obtain the default monitoring indicator values in the agent:
zabbix_get -s 192.168.126.141 -p 10050 -k 'system.cpu.intr'
zabbix_get -s 192.168.126.141 -p 10050 -k 'net.tcp.listen[10050]'
5. Create the initial database: install mysql, install mysql-5.7
step1: Configure the installation source
yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum repolist all | grep mysql # 查看所有 mysql 子存储库
yum install -y yum-utils # 安装 yum 配置工具管理 YUM 源
yum-config-manager --disable mysql80-community # 禁用 mysql80版本 子存储库
yum-config-manager --enable mysql57-community
yum repolist enabled | grep mysql # 查看已启用的 mysql 子存储库
step2: install mysql
yum install -y mysql-community-server
step3: Start the mysql service, and set it to start automatically at boot
systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld//设置开机自启动
step4: Create a database, and grant zabbix permission to modify the database password,
Create zabbix user and authorize (set mysql local login root password to ABcd_123!
Create zabbix user password is ABcd_123! )
a. // log in to mysql
mysql -u root -p
mysql> set password for root@localhost = password('123');
b. Create a database
create database zabbix character set utf8 collate utf8_bin;
c. Create user
create user zabbix@localhost identified by 'ABcd_123!';
d. Authorize zabbixs
grant all privileges on zabbix.* to zabbix@localhost;
grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'ABcd_123!';
flush privileges;
quit;
step5: Import the initial schema and data (data and tables), you will be prompted to enter the newly created password.
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbix -p zabbix
Password: ABcd_123!
step6: Initialize the database table (this step is ignored, it may be used in individual zabbix versions, step5 has completed the table creation)
# 查看表
rpm -ql zabbix-server-mysql
# 解压
gzip -d /usr/share/doc/zabbix-server-mysql-5.0.13/create.sql.gz
# 执行导入
mysql -u root -p zabbix < create.sql
6. Configure the database for the Zabbix server (it is not necessary to enter the web with zabbix 5.0 to set it. If it does not take effect after the page is set, you must manually set the following parameters. Note that in the web page setting, write the IP address of the host and database instead of localhost)
Edit the configuration file /etc/zabbix/zabbix_server.conf
Note: The following does not seem to be necessary, different zabbix versions, the requirements are not necessarily the same, zabbix 5.0 can be set when entering the web
======== The following configuration is not necessary, zabbix 5.0 can be configured when entering the web page
vi /etc/zabbix/zabbix_server.conf
ExternalScripts=/usr/lib/zabbix/externalscripts
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
LogFile=/var/log/zabbix/zabbix_server.log
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
LogFileSize=0
ListenPort=10051
SourceIP=127.0.0.1
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=$NewPass // 如: DBPassword=ABcd_123!
Timeout=30
LogSlowQueries=3000
7. Configure PHP for the Zabbix front end (version 5.0 is required)
Edit the configuration file /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf, uncomment and set the right timezone for you.
php_value[date.timezone] = Asia/Shanghai
Note the writing format:
8. Install the PHP environment (it seems not necessary, different zabbix versions, the requirements are not necessarily the same, version 5.0 is not necessary)
When installing zabbix-related packages, php will be installed, but there is no result when using php -v, and there is result when using rpm -qa | grep php. The specific reason is unknown.
locate php.ini, php.ini is not in "/etc/php.ini", the reason is unknown
9. Start Zabbix server and agent processes
Start the Zabbix server and agent processes, and set them to start automatically:
systemctl start zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
Here are the relevant commands:
# 相关命令
systemctl start zabbix-server
systemctl restart zabbix-server
systemctl status zabbix-server
systemctl enable zabbix-server
systemctl stop zabbix-server
# 查看zabbix的端口
# zabbix-server
ss -nutl|grep 10051
# zabbix-agent
ss -nutl|grep 10050
# zabbix 服务启动日志
# vim /var/log/zabbix/zabbix_server.log
Visit http://ip:80/zabbix after the service starts successfully, and the following page is displayed:
10. Configure Zabbix frontend
# Change php, apache time zone (it seems not necessary, different zabbix versions, the requirements are not necessarily the same)
step1: Configure /etc/php.ini, but in /etc/opt/rh/rh-php72/php.ini
sed -i 's#;date.timezone =.*#date.timezone = "Asia/Shanghai"#' /etc/php.ini
step2: Configure /etc/httpd/conf.d/zabbix.conf (it seems not necessary, different zabbix versions, the requirements are not necessarily the same, the 5.0 version is not implemented, and the execution error)
sed -i '20a\ php_value date.timezone Asia/ShangHai' /etc/httpd/conf.d/zabbix.conf
step3: # Start the Apache process, follow the system startup
systemctl start httpd
systemctl enable httpd
systemctl status httpd
#查看Apache的端口
netstat -tunlp| grep 80
netstat -lnpt
step4: What if you want to modify the default port
When installing zabbix server, apache is installed by default. Zabbix relies on the web service provided by apache. Modifying the browser access port of Zabbix is to modify the service port of apache (default port: 80)
1. Edit the httpd.conf file: vim /etc/httpd/conf/httpd.conf
2. Modify the default listening port and ServerName
136 Listen 8008
277 ServerName IP:8008
3. Restart the apache service to make the configuration take effect: service httpd restart
4. Add firewall rules to allow port access
Edit: vim /etc/sysconfig/iptables
# zabbix web
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8008 -j ACCEPT
Restart the firewall: service iptables restart
5. Browser access http://IP:8008/zabbix to test whether the modification is successful