@zabbix (5.0) client and server deployment and installation

Posted by Joeker on Tue, 21 Sep 2021 11:11:05 +0200

zabbix (5.0) deployment and installation

www.zabbix.com [official website]

1, zabbix client

1)agent2 New version adopted golang Language development client

2)agent2 The default is 10050 port, that is zabbix Port of the client

# Old client: ZABBIX agent
# New version client: zabbix-agent2

2, Client Deployment (zabbix-agent2 installation)

1. Machine preparation

Machine preparationIPService nameEnvironmental preparation
zabbix server13.75.120.200zabbix-serverTurn off firewall and selinux
zabbix client13.75.120.200zabbix-agent2Turn off firewall and selinux
zabbix client13.75.120.200zabbix-agent2Turn off firewall and selinux

2. Environmental optimization (all machines)

1,time synchronization 
[root@test ~]# yum -y install ntpdate
[root@test ~]# ntpdate ntp.aliyun.com
#Add scheduled task
[root@test ~]# crontab -l 
# Sync every five minutes
*/5 * * * * /usr/sbin/ntpdate ntp.aliyun.com &> /dev/null


2,Time zone synchronization
#Set time zone:
timedatectl set-timezone "Asia/Shanghai"
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime



3,Turn off firewall and selinx
#Close selinux
[root@test ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@test ~]# setenforce 0
[root@test ~]# getenforce 0
Permissive
#Turn off firewall
[root@test ~]# systemctl stop firewalld.service      # Temporarily turn off the irewalld firewall
[root@test ~]# systemctl disable firewalld.service   # Join don't let it start automatically

3. Installing zabbix

1,obtain zabbix Official source
[root@test ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm 



2,Modify configuration source file
[root@test ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@test ~]#  yum clean all && yum makecache



3,install zabbix-agent2 or zabbix-agent
[root@zabbix1 yum.repos.d]# yum install zabbix-agent2 -y




4,Install and view zabbix-agent2 configuration file
[root@test ~]# ls -l /usr/sbin/zabbix_agent2 
-rwxr-xr-x. 1 root root 17721128 Aug 30 17:32 /usr/sbin/zabbix_agent2



5,start-up zabbix-agent2
[root@test ~]# systemctl enable --now zabbix-agent2.service



6,Check startup status
[root@test ~]# netstat -lntp |grep zabbix
tcp6       0      0 :::10050                :::*                    LISTEN      5312/zabbix_agent2 



7,Profile modification
# zabbix-agent2 client configuration
[root@test ~]# vim  /etc/zabbix/zabbix_agent2.conf
[root@test ~]# egrep -v '^$|^#' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=127.0.0.1              # ZABBIX server server IP
ServerActive=127.0.0.1        # ZABBIX server server IP
Hostname=zabbix server        # zabbix server native address
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock



8,Restart (effective profile)
[root@test ~]# systemctl restart zabbix-agent2.service 
9,Check whether the service is started
[root@test ~]# netstat -lntp |grep 10050
tcp6       0      0 :::10050                :::*                    LISTEN      5469/zabbix_agent2  

3, zabbix server deployment

1. ZABBIX version 5.0 basic requirements

1. ZABBIX php version after 5.0 is at least 7.0

2. 2G2 core

3. ZABBIX server server installation

2. Deploy and install plug-in server

1,download epel source
[root@test ~]# yum install epel-release -y


2 ,obtain zabbix Official source (ignored if installed)
[root@test ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm 


3,Modify configuration source file
#Change source address
[root@test ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
#Generate cache upon emptying
[root@test ~]# yum clean all && yum makecache




4,install zabbix server and zabbix-agent2((negligible)
[root@test ~]# yum install zabbix-server-mysql zabbix-agent2 -y



5,install software collections Easy to install higher versions of php (yum default php It's five.4)
SCL(Software Collections)Multiple versions of software can be installed and used on the same operating system without affecting the installation package of the whole system. The software package will be installed on/opt/rh Directory.
To avoid widespread system conflicts,/opt/rh Packages are installed in a directory, for example, in CentOS7 Installed on the machine Python3.8,Without deletion or interference Python2.7. 
/etc/opt/rh All configuration files of the software package are stored in the corresponding directory, SCL The package provides the environment variables needed to define and use the included applications shell script.
#For example, PATH, LD_LIBRARY_PATH and MANPATH, which are stored in the file system as / opt / Rh / package name / enable
[root@test ~]# yum install centos-release-scl -y



6,modify zabbix Front end source 
[root@test ~]# cat /etc/yum.repos.d/zabbix.repo 
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1    #Change to 1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591




6,install zabbix Front end environment( zabbix-mysql,zabbix-apache)
[root@test ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

3. Deploy zabbix database

#Database required to install zabbix
1),to configure MySQL of yum source
[root@test ~]# cat > /etc/yum.repos.d/mysql.repo << EOF
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/
enabled=1
gpgcheck=0
EOF


2),Install Community Edition MySQL
[root@test ~]# yum install mysql-community-server


3),start-up MySQL
#Add boot auto start
[root@test ~]# systemctl enable --now mysqld.service  # The default password of MYSQL5.7 is in mysqld.log
#View password
[root@test ~]# grep 'password' /var/log/mysqld.log 
2021-07-31T07:54:52.161434Z 1 [Note] A temporary password is generated for root@localhost: !oA1Hy*-HYjK


4),inspect MySQL running state 
[root@test ~]# systemctl status mysqld.service 
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-07-29 00:04:02 CST; 8s ago
#Initialize the database and set the root password
[root@test ~]# mysql_secure_installation

# Enter the current root password (enter directly)
# Enter current password for root (enter for none):

# Set root password
# Set root password? [Y/n] y
# New password: 
# Re-enter new password:

# Remove anonymous user
# Remove anonymous users? [Y/n] y

# Prohibit root remote login
# Disallow root login remotely? [Y/n] n

# Remove test database
# Remove test database and access to it? [Y/n] y

# Refresh authorization table
# Reload privilege tables now? [Y/n] y



5),establish zabbix Dependent database
[root@test ~]# mysql -uroot -p'Zabbix@21'
# 1. Change the password and authorize the root user
mysql> set password=password('Zabbix@21');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to root@'%' identified by 'Zabbix@21';
mysql> flush privileges;
mysql> quit



# 2. Create zabbix library and authorize
#Database creation
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
#Create user and authorize
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'Zabbix@21';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
mysql> exit




# 3. Configuration database my.cnf file
[root@test ~]# grep '^[^#]' /etc/my.cnf
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8mb4

[mysql]
user="root"
password="Zabbix@21"
default-character-set=utf8mb4


# 8. Start database
[root@test ~]# systemctl restart mysqld
[root@test ~]# netstat  -lntp |grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      1119/mysqld     





# 9. mysql database data import
#ZABBIX server MySQL data import database mysqld
[root@test ~]# cd /usr/share/doc/zabbix-server-mysql-5.0.15
#Data import (time may be slow)
[root@test zabbix-server-mysql-5.0.15]# zcat create.sql.gz | mysql -uroot -p"Zabbix@21" zabbix 
mysql: [Warning] Using a password on the command line interface can be insecure.





# 10. Modify the zabbix configuration file (associated with mysql)
1,modify zabbix_server.conf file
[root@test ~]# vim /etc/zabbix/zabbix_server.conf
[root@test ~]# grep -E  '^[^#]' /etc/zabbix/zabbix_server.conf 
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix@21
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1


2,modify zabbix.conf File (change dependent) php Time zone)
[root@test ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 
[root@test ~]# grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 
php_value[date.timezone] = Asia/Shanghai




# 11. Start zabbix
#restart
[root@test ~]# systemctl restart zabbix-server zabbix-agent2.service httpd rh-php72-php-fpm.service
#Join boot auto start and start immediately
[root@test ~]# systemctl enable --now zabbix-server zabbix-agent2.service httpd rh-php72-php-fpm.service 



# 12. Test ip access
192.168.15.10/zabbix 
Default user: Admin   
password: zabbix

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-dqpuyr0x-1632120510449) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 1632057439199. PNG)]

Check whether the environment is ok

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-sqchnkpk-1632120510454) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 16320573772. PNG)]

zabbix Association Database

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (IMG gmfirqgb-1632120510457) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 163205893. PNG)]

Fill in the ZABBIX server information (according to the actual deployment)

[the external chain image transfer fails, and the source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-kjzxyaug-1632120510459) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 16320584814. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-bqpb5a6p-1632120510463) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 1632058559096. PNG)]

web installation succeeded

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-ywamxxa0-1632120510466) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 16320586160. PNG)]

Log in to zabbix web

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-itxjyjcy-1632120510469) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 16320580027. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-j4jayjzs-1632120510470) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 16320587163. PNG)]

Change web language

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-6wxypfjv-1632120510472) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632058805210. PNG)]

web Chinese mode

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-x5lsnwmj-1632120510473) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632058823277. PNG)]

Character garbled on web

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-nx2hdw7w-1632120510477) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 163205912812. PNG)]

4. Install character plug-in (web character garbled)

1,Install Chinese Fonts
yum -y install wqy-microhei-fonts


2,Copy the downloaded binary file to the specified path
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

web overload (page characters have been displayed normally)

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-gljlt09t-1632120510479) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 16320593786. PNG)]

4, zabbix add web (custom key)

User defined monitoring login users

Demand: the number of people is limited to no more than three, and more than three will generate alarm information

##### Client execution

# 1. linux commands need to be executed when using (this command can view the number of currently logged in users)
[root@test ~]# who |wc -l
2


# 2. In the zabbix configuration file, the configuration uses the included form to optimize the configuration file and add multiple configurations, as shown below
[root@test ~]# cat /etc/zabbix/zabbix_agent2.conf | grep -i "^include"
Include=/etc/zabbix/zabbix_agent2.d/*.conf




# 3. Add zabbix_agent2 configuration file is used to customize the key (zabbix configuration file can be created manually)
#Add profile directly
[root@test ~]# vim /etc/zabbix/zabbix_agent2.conf
#Custom configuration file and specified path (configuration name)
[root@test ~]# cd /etc/zabbix/zabbix_agent2.d/
[root@test zabbix_agent2.d]# vim /etc/zabbix/zabbix_agent2.d/userparameter_login.conf
#Custom profile syntax
#Format: UserParameter=<key>,<shell command>
UserParameter=login.user,who|wc -l
#Multiple monitoring, changing different key values
#UserParameter=login.user1,who|wc -l



# 3. Restart service
[root@test ~]# systemctl restart zabbix-agent2.service




#### Server monitoring
# 1. zabbix server (as shown below)

Create Group

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-w4a0f9e9-1632120510481) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632061558561. PNG)]

Add custom group

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-cnpcqciy-1632120510482) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632061651636. PNG)]

Create template

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-3y8dvsms-1632120510483) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632061912972. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-mxyfwvm3-1632120510484) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632061975416. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-1l54ol8f-1632120510485) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062078437. PNG)]

Create application set

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-82ybv1bq-1632120510487) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062178365. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-gawddqqc-1632120510489) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062250330. PNG)]

Create a monitoring item and select the specific content you want to monitor (custom item)

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-sizovwht-1632120510490) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062386376. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-ghkgvpbd-1632120510492) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062553566. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-n9xi9lhu-1632120510496) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062663587. PNG)]

Create trigger, custom create (monitor item triggers alarm addition)

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-kwrw7kao-1632120510498) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632062758864. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-lbugu8px-1632120510501) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063033665. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-m5ajd6wa-1632120510503) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063068379. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-iplxjfcb-1632120510505) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063275495. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-5rvggejy-1632120510506) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063319361. PNG)]

Create drawing

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-xa6qu9iy-1632120510508) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063503624. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-1z4quxfj-1632120510509) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063587864. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-vfpp2zz7-1632120510511) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063628675. PNG)]

Create host associated with template

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-vt9hihnu-1632120510512) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632063739791. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-oc9cwbc0-1632120510513) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632064157449. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-19tfyuhf-1632120510516) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632064469146. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-wxfv2sjy-1632120510517) (C: \ users \ 86176 \ appdata \ roaming \ typora user images \ 1632064190013. PNG)]

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (IMG caahbfom-1632120510519) (C: \ users \ 86176 \ appdata \ roaming \ typora \ typora user images \ 1632064381548. PNG)]

[external chain picture transferring... (img-m5ajd6wa-1632120510503)]

[external chain picture transferring... (img-iplxjFcB-1632120510505)]

[external chain picture transferring... (img-5RVGgeJY-1632120510506)]

Topics: Go Operation & Maintenance CentOS Zabbix