Detailed process of CentOS 7 installation and cloning and Zabbix installation and deployment

1. Install the virtual machine

1.1 Install the first CentOS 7 virtual machine

For specific operation methods, see reference blog 1 .
[Note]: In step 11 of Section 3 of Blog 1, we need to configure the network and host name of the virtual machine . We set the IP to static IP. My reference process is as follows:
1) Win+R to open Run, enter cmd and press Enter to open the terminal, enter ipconfig to view the current Windows host IP address, as shown in the figure below: 2) You can see that
Insert image description here
the local VMnet8 IP is 192.168.134.1 .
Let the virtual machine access the Internet, so we use VMNet8 (NAT mode) IP
3) Therefore, we set the IPv4 address of the virtual machine to 192.168.134.3 , as shown in the figure below:
bold style

1.2 Copy the virtual machine to get a second virtual machine and name it CentOS 7_02

  1. Create a folder in advance to store the copied virtual machine
  2. Open VMpro, click on the virtual machine you want to copy, right-click and select Manage, then select Clone, select Copy the current state, and create a complete virtual machine. The demonstration is as follows:
    Insert image description here3. Define the name and storage location of the virtual machine:
    Insert image description here

Wait for the cloning to complete.
4. The cloned virtual machine settings are exactly the same as the original virtual machine. Because we previously set a static IP address for the original virtual machine, the system will not automatically assign a new IP address to the cloned virtual machine. Instead, it will be the same static IP address as the original virtual machine. We can open the virtual machine terminal, enter ifconfig (or ip addr), and see that the ip is also 192.168.134.3:Insert image description here

1.3 Modify the host name and IP address of the second virtual machine (CentOS 7_02)

For monitoring needs, we need to distinguish two virtual machines, one as a server (server) and the other as a client (agent), and the IP addresses must also be kept different. The arrangement is as follows:

virtual machine CPU name Host IP
CentOS 7 server 192.168.134.3
CentOS 7_02 agent 192.168.134.4

[Note]: These names can be customized and do not have to be named like mine.

  1. Modify the CentOS 7_02 host name:
    1) Method 1 (graphical operation) :
    Find the share in the settings, you can see the computer name, just change it to agent, the demonstration is as follows:
    Insert image description here
    2) Method 2 (command line operation)
  • First, right-click on the desktop to open the terminal and enter the command as follows:
    hostname          # 1.查看当前主机名/查看方法1
    su                # 2.切换为root用户,获得root权限
    hostnamectl set-hostname agent # 3.修改主机名命令1,立即生效
    cat /etc/hostname # 4.再次查看当前主机名是否修改成功/查看方法2
    bash              # 5.刷新一下bash
    
  • The demonstration is as follows: Insert image description here
    Similarly, if the CentOS 7 host name has not been modified, you can also change it to server according to this method.
    3) Method 3 (command line operation/advanced)
    sudo vi /etc/hostname 	 # 1.输入管理员密码之后,会进入vi文件模式。
    #输盘输入字母i即可进入编辑模式,修改好之后,按 ESE 键,再同时按下 Shift 和 : 这两个键,在页面底部输入wq,再回车即可保存退出
    sudo reboot              # 2.重启生效
    hostname                 # 3.开机,验证是否已经修改成功   
    
    [Note]: This method needs to be restarted to take effect
    [Image]:Insert image description here
  1. Modify CentOS 7_02 IP:
  • Method 1:
    First enter the following command:

    sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
    

    Get the following diagram: Insert image description hereChange the IP to 192.168.134.4 (the last digit is not unique, you can set it yourself), enter wq and press Enter to exit.
    Then enter the restart network command:

     sudo  systemctl restart network :重启网卡服务
    

    Finally, check whether the current IP has been modified successfully. The whole process is shown in the figure below:Insert image description here

  • Method 2 (graphical operation): As shown below:
    Insert image description here
    Finally enter the restart network command:

     sudo systemctl restart network :重启网卡服务
    
  1. Ping each other between the virtual machine and the windows host as follows to verify whether they can communicate with each other.
    Command: ping the IP address of the destination host
    1) Ping the windows host and two virtual machines. Insert image description here
    As shown above, there is no problem.

2)CentOS 7_windows、CentOS 7_02 ping。

Insert image description hereAs shown above: CentOS 7_02 and CentOS 7 can ping each other, but cannot ping the VM8 IP address of Windows.

3) Similarly: CentOS 7_02 and windows, CentOS 7 ping
CentOS 7_02 and CentOS 7 can ping each other, but cannot ping the VM8 IP address of windows.

[Problem]: The virtual machine cannot ping the VM8 IP address of Windows, but it can ping the VM5 IP address.
[The reason is]: The Windows firewall blocks the communication between the virtual machine and VM8. Just turn off the firewall.
[Solution]: Refer to Blog 3 , as shown in the figure below: Search for the firewall in the win10 search bar and close the firewall.
Insert image description here
Since the virtual machine and windows do not need to ping here for the time being, turn on the windows firewall first, and then turn it off according to this method if necessary later.

Some details can be supplemented by referring to Blog 2

1.4 Reference

  1. CentOS: (30 messages) CentOS7 (Linux) detailed installation tutorial (detailed picture and text)_centos7 installation tutorial_Silent.ńī's blog-CSDN blog In the manual partition part, select the standard partition instead of LVM /boot:
    set
    to 300M,/swap: set to 3.5GB

    Kdump is turned on
    Insert image description here
  2. VMware Copy Virtual Machine, Clone Virtual Machine_Virtual Machine Cloning_Chiyou Descendants' Blog-CSDN Blog
  3. The host can ping vmnet8, but the virtual machine cannot ping vmnet8.

2. Install and deploy zabbix under CentOS 7

2.1 Web environment construction

Web environment explanation : LAMP and LNMP are common Web environments. This example uses LAMP

  • L: Linux, Linux operating system
  • A or N: Apache or Nginx, Web server software
  • M: MySQL or MariaDB, database software
  • P: PHP, Perl, Python, scripting software

Log in as the root user . All the following operations are performed as the root user.

2.1.1 Configure firewall and SELinux services

(1) Type the following commands in the CentOS 7 (server) virtual machine terminal in sequence and execute them:

sudo systemctl stop firewalld.service    # 1.关闭Linux防火墙
firewall-cmd --state                     # 2.查看防火墙状态,确认已关闭(关闭后显示notrunning,开启后显示running)
sudo systemctl disable firewalld.service # 3.禁止防火墙自启动
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux     
                                         # 4.通过修改配置文件的方式关闭SELinux,可以通过cat /etc/sysconfig/selinux命令查看当前SELinux的状态

2.1.1 Change YUM source:

Type the following commands in the CentOS 7 (server) virtual machine terminal in sequence and execute them:

yum -y install wget                      # 1.安装wget                     
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup  
                                         # 2.通过将CentOS-Base.repo文件复制另存的方式将默认的repo文件备份
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
                                         # 3.换成阿里源
yum clean all                            # 4.清理缓存
yum makecache fast                       # 5.生成新的缓存

2.1.3 Use YUM command to install MariaDB, PHP and httpd

yum install -y mariadb mariadb-server php php-mysql httpd
If the following results appear, the installation is successful:
Insert image description here

2.1.4 Testing Apache

1) Execute the following two commands in sequence:

systemctl start httpd                      # 1.启动HTTP服务(通过Apache访问服务器时,需要先启动HTTP服务)
systemctl enable httpd                     # 2.将httpd设置为自启动
systemctl status httpd                     # 查看当前状态,可以不执行此条命令

2) Open the Firefox browser in the virtual machine, enter the IP address of the virtual machine (server) (which can be viewed through the ifconfig or ip addr command) and press Enter. If you get the following results, it means that Apache is configured successfully.
Insert image description here[Note]: You can check the version through the command: rpm -qa|grep httpdView path: rpm -ql httpd, as shown below:
Insert image description here

2.1.5 Database (MariaDB) configuration

1) Set up auto-start

systemctl start mariadb                   # 1.启动数据库
systemctl enable mariadb                  # 2.设置自启动

You can check the status of the database through the systemctl status mariadb command:
Insert image description here
2) Use the following mysqladmin command to change the root password:

Generally, the default root password of mysql is empty. If you have not set a root password before, use the mysqladmin command.

mysqladmin -u root password 'mima'        # 注意这里的密码你自己定义,我这里以“mima”为例 

The above command defines the default password of the root user. You can then use this command to access the database, as shown below: Insert image description here
3) Create a database and ordinary user for the current Zabbix server

The data collected by the zabbix server needs to be saved in the database, so you need to create a database in MariaDB to save Zabbix data, and create an ordinary user in the current system and give it permission to operate the Zabbix database.

Execute the following commands in sequence:

[root@server ~]# mysql -uroot -pmima        # 1.root用户访问数据库
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;                           
                                            # 2.创建名为zabbix的数据库,并设置数据库zabbix的字符编码格式为utf8
MariaDB [(none)]> show databases;           # 3.查看当前数据库中有没有我们刚刚创建的zabbix数据库(注意该命令的database后面有s和分号)
MariaDB [(none)]> create user zabbix@'192.168.134.%' identified by 'mima';                           
                                            # 4.在主机192.168.134.%上创建新用户zabbix,且密码为mima
MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'%' identified by 'mima';                           
                                            # 5.赋予密码为”mima“的用户zabbix在任意主机(%)上操作数据库zabbix中任意一张表(.*) 的全部权限(all)。因而,依次出现的2个zabbix分别表示数据库名和用户名。
MariaDB [(none)]> flush privileges;         # 6.刷新权限
MariaDB [(none)]> exit                      # 7.退出数据库              

[Note] Another way to create a zabbix user in the third step is:

useradd 用户名
passwd  密码

As shown in the figure below:
Insert image description here
4) Test zabbix user Insert image description here
As shown in the figure above, the configuration is successful! ~

At this point, the LAMP environment setup and Zabbix pre-configuration are complete, and then Zabbix can be installed and configured in the Linux system.

2.2 Zabbix-Server configuration

2.2.1 zabbix installation

2.2.1.1 Obtain the Zabbix5.0 installation package through the YUM source
cd /etc/yum.repos.d/                        # 1.进入etc/yum.repos.d目录,/etc/yum.repos.d/目录下存放默认的配置文件
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm 
                                            # 2.通过阿里云镜像下载zabbix5.0

[Note]: The package downloaded by yum will be stored in /var/cache/yum/x86_64/7/, such as zabbix:
Insert image description here

2.2.1.2 Use the yum command to install server-side software packages (including zabbix-server, zabbix-agent, and zabbix-get)

1) As shown below: Find the zabbix.repo file under the yum.repos.d folder.
Insert image description here2) Open it with a text editor and change the enabled value under [zabbix-frontend] to 1, as shown below:

[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1

vim /etc/yum.repos.d/zabbix.repoOr modify it directly
3) Enter the following download commands in sequence:

yum -y install zabbix-server-mysql zabbix-agent zabbix-get
yum -y install centos-release-scl            # 下载红帽软件集合
yum -y install zabbix-web-mysql-scl

Insert image description here
[Note]: A download failure error may occur:
[Solution]: Also modify the zabbix.repo file and change the baseurl in line 3 to the following command. The specific operation is as shown in the figure below:

baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=1

Insert image description here
Then execute the yum download command in step 3) to install normally, as shown in the figure below and it will be successful.
Insert image description hereInsert image description here

2.2.2 Configuring the database

Before using zabbix, you need to connect Zabbix to the database first

2.2.2.1 Import table structure:

Zabbix has customized the structure of the tables in the database. In order to ensure that MariaDB can store data in the form defined by Zabbix, the table structure of Zabbix should be imported into the database first)

Execute the following commands in sequence:

[root@server khalid]# cd /usr/share/doc/zabbix-server-mysql*/                                          
                                             # 1.先进入zabbix-server-mysql-5.0.34目录中
[root@zabbix-server ~]# zcat create.sql.gz | mysql -uzabbix -pmima zabbix                                       
                                             # 2.将数据导入zabbix库中                     
2.2.2.2 Change the configuration file zabbix-server.conf

Use the vi editor to open the file and set the corresponding options according to the following information:

[root@server ~]# vi /etc/zabbix/zabbix_server.conf 
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword= mima

[Note]: Some operations in the vi editor:
Insert image description here
Insert image description here
After modification, shift + : , then enter wq to save and exit.

2.2.2.3 Change the configuration file zabbix.conf (that is, change the front-end PHP time zone)

The main configuration file of Zabbix Server is zabbix.conf. This file is in the /etc/httpd/conf.d/ directory. Also use the vi editor to open the file and modify the option date.timezone . This option is used to configure the time zone of Zabbix. Zabbix has very high requirements for time accuracy, so the time zone needs to be changed to the local time zone, which is Shanghai.
[Note] If there is no such file in this directory, search globally for the zabbix.conf file in the graphical interface, as shown below:

Insert image description here
You can find that the zabbix.conf files here are under /etc/httpd/conf.d/ and etc/opt/rh/rh-php72/php-fpm.d . Modify them according to the following commands:

[root@server ~]# vi /etc/httpd/conf.d/zabbix.conf
                                             # 根据自身情况修改
php_value[date.timezone] = Asia/Shanghai  # 将时区设置为上海
2.2.2.4 Start abbix-server

At this point, the configuration of Zabbix-Server is basically completed. Use the following command to start:

   [root@server ~]# systemctl start zabbix-server                                 
                                                # 1.启动zabbix-server
   [root@server ~]# systemctl enable zabbix-server                                          
                                                # 2.设置自启动
2.2.2.5 zabbix access test
[root@zabbix-server ~]#  systemctl restart httpd mariadb rh-php72-php-fpm          
[root@zabbix-server ~]#  systemctl restart zabbix-server zabbix-agent 

[root@zabbix-server yum.repos.d]# netstat -anpt  | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      17381/zabbix_agentd 
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      17380/zabbix_server 
tcp6       0      0 :::10050                :::*                    LISTEN      17381/zabbix_agentd 
tcp6       0      0 :::10051                :::*                    LISTEN      17380/zabbix_server 

Open the Firefox browser, enter ip/zabbix, and press Enter to access the following image:
Insert image description here

2.2.2.6 Log in to Zabbix monitoring system

Login method:

  • Default account: Admin Default password: zabbix
  • Created account: zabbix Password: zabbix
2.2.2.7 Possible error situations

[Error 1] If this error is reported, the reason may be that the password is incorrect.
Insert image description here
Solution: Check the database user password , DBName, DBUse and DBPasswd in the zabbix_server.conf file , and whether the settings in
the zabbix.conf.php file are correct. Usually the password is set incorrectly. For details, please refer to Blog 5. The following is my zabbix.conf.php file information, which can be checked here.

// Zabbix GUI configuration file.

$DB['TYPE']				= 'MYSQL';
$DB['SERVER']			= '192.168.134.3';
$DB['PORT']				= '0';
$DB['DATABASE']			= 'zabbix';
$DB['USER']				= 'zabbix';
$DB['PASSWORD']			= 'zabbix';

[Error 2] If this error is reported, indicating that the front-end and zabbix database do not match, it is because the current database is version 5020000, and the required version is 4040000.
Insert image description here
Solution: Refer to Blog 6 , enter the database, and use the command as the zabbix user:

mysql -uroot -pmima
use zabbix;
updata dbversion set mandatory=4040000;        #mandatory的值应该根据提示的信息来确定,我这里是4040000

The whole process is shown in the figure below:
Insert image description here
[Error 3] 503 Service Unabvailable may appear if you have not logged in for a long time.
Solution: refer to Blog 7 , check the log, find the problem, and restart the service.
Each log storage path:
/var/log/zabbix/zabbix_server.log
/var/log/httpd/
/var/log/mariadb
[Error 4] The zabbix5.x login page reports an error SQL statement execution has failed “INSERT INTO auditlog (userid, clock, ip, action...
solution: refer to blog 8

2.3 Zabbix server front-end optimization

You can directly refer to Section 4.2 of the reference blog 1 here .
Please add something to the garbled Chinese font part.
As shown in the picture below, when we set zabbix to Chinese, some parts will appear garbled:

Insert image description here
[Solution]: We can use fonts in Windows to replace the default fonts in zabbix to solve this problem.
1) Specifically, we first use the command find / -name fontsto find all folders named fontsde in the virtual machine, as shown below:
Insert image description here
You can see that Zabbix fonts are stored in the usr/share/zabbix/assets/fonts directory.
2) Then, we find the Microsoft Yahei font file in the Windows directory C:\Windows\Fonts
Insert image description here
, as shown below: Copy it to the desktop, and three files will be generated (msyh.ttc, msyhl.ttc, msyhbd.ttc) .
3) Then upload msyh.ttc to /usr/share/zabbix/assets/fonts in the Zabbix server. The upload method is explained in detail below.
Upload method 1: Connect to the virtual machine through a USB flash drive, and use the USB flash drive as a carrier to copy the Microsoft font msyh.ttc to the target virtual machine.
Upload method 2: Connect to the virtual machine through remote control through xshell and xftp software.

  • First, download the xshell and xftp software
  • Then: open xshell, click New Session,
    Insert image description here
  • Click Connect in the new session properties box and enter the host name and host IP, as shown below:
    Insert image description here
  • Click User Authentication in the new session properties box and enter the user login name and password. It can be the root user or other users that have been created in the server, as shown below:Insert image description here
  • After a successful connection, you can click the Xftp icon in the toolbar to automatically open the Xftp software and establish a connection (similarly, you can also directly establish a connection with the server in Xftp without opening the Xshell software), as shown below:
    Insert image description here
  • Upload the msyh.ttc file, as shown below:
    Insert image description here

4) Finally, rename the Microsoft font msyh.ttc to graphfont.ttf. Enter the following command in the server terminal:

cd /usr/share/zabbix/assets/fonts/
mv graphfont.ttf graphfont.ttf.bak     # 备份一下
mv ./msyh.ttc ./graphfont.ttf          # 替换

Refresh the page and complete.

2.4 Deploy Zabbix-Agent

Here is a direct reference to Section 4.3 of Blog 1 .

2.5 Add monitoring device to Zabbix Server

Here is a direct reference to Section 5 of Blog 1 .

2.6 Reference

  1. Deploying Zabbix5.0 - Yum method (with theory)
  2. (30 messages) Detailed installation and deployment of Zabbix_zabbix installation and deployment_linux_yanbb's blog-CSDN blog
  3. (30 messages) Installation and deployment of zabbix under Centos7, setting up Chinese (nanny-level graphics and text) [Network Engineering]_centos7 installation of zabbix_discovered that you have gone far blog-CSDN blog
  4. (30 messages) centos7 installation and deployment of zabbix5.0 (super detailed)_Rookie Houlang's Blog-CSDN Blog
  5. Problem Solved - The zabbix login page displays Database: Error connecting to database: Access denied for user 'zabbix'…
  6. Zabbix upgrade version problem handling
  7. Remember that the zabbix web interface 503 prompt is unavailable due to the restart of the zabbix server.
  8. The zabbix5.x login page reports an error SQL statement execution has failed “INSERT INTO auditlog (userid,clock,ip,action…

Guess you like

Origin blog.csdn.net/lvyunkai0518/article/details/131616008