Location>code7788 >text

Zabbix Build

Popularity:596 ℃/2024-08-02 16:16:36

catalogs
  • zabbix build
    • 1. Pre-environmental preparation
      • 1.1 Build LNMP
    • 2. zabbix preparation
      • 2.1 Installing the php module and compiling the required tools
      • 2.2 Modify php configuration
      • 2.3 Compiling and installing zabbix
        • 2.3.1 Downloading the tarball
        • 2.3.2 Decompression
        • 2.3.3 Creating users/groups
        • 2.3.4 Starting installation
        • 2.3.5 Configuring the database
    • 3. Configuring zabbix
      • 3.1 Modification of configuration files
      • 3.2 Web interface deployment
    • 4. Installation of agent
    • 5. Adding hosts

zabbix build

synopsis

Zabbix is an open source monitoring solution for monitoring various network services, servers and other network hardware. It is able to collect all kinds of monitoring data and provide powerful alarms and reports.

1. Pre-environmental preparation

We use the compile and install method, you need to prepare a LNMP or LAMP environment in advance

1.1 Build LNMP

[root@oe01 ~]# yum install nginx php php-fpm -y

By default, php-fpm uses socker to communicate after installation. Let's change it to listen on port 9000.

[root@oe01 ~]# vim /etc//
38 listen = /run/php-fpm/
39 listen = 127.0.0.1:9000
[root@oe01 ~]# systemctl restart php-fpm

Just add one more line, after installing php he will generate 2 nginx configuration files for us by default, we don't need him. Rename it

[root@oe01 ~]# mv /etc/nginx// /etc/nginx//
[root@oe01 ~]# mv /etc/nginx// /etc/nginx//

Then we rewrite a configuration file for nginx

[root@oe01 ~]# cp /etc/nginx/ /etc/nginx/
cp: overwrite '/etc/nginx/'? y
[root@oe01 ~]# vim /etc/nginx/
 43         location / {
 44             root   /data/zabbix;
 45             index    ;
 46         }

 65         location ~ \.php$ {
 66             root           /data/zabbix;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  ;
 69             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }

Your line numbers may not be the same as mine, probably something along these lines. Then restart nginx

[root@oe01 ~]# mkdir -p /data/zabbix
[root@oe01 ~]# systemctl restart nginx

Next, they go to test whether the php can be parsed normally. If so, then our LNMP environment is complete. Next, start to build monitoring. If you can't parse it, look at the root directory of the site in the/data/zabbixDon't misplace it.

2. zabbix preparation

Now let's start installing the php module

2.1 Installing the php module and compiling the required tools

root@oe01 ~]# yum install php-gd php-mbstring php-bcmath php-xml php-ldap php-mysqlnd mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel gcc make -y

2.2 Modify php configuration

The default php configuration won't allow zabbix to run properly, so we need to change the

[root@oe01 ~]# sed -i "s/post_max_size = 8M/post_max_size = 16M/g" /etc/
[root@oe01 ~]# sed -i "s/max_execution_time = 30/max_execution_time = 300/g" /etc/
[root@oe01 ~]# sed -i "s/max_input_time = 60/max_input_time = 300/g" /etc/
[root@oe01 ~]# systemctl restart php-rpm

These configurations must be changed, because if you don't change them, they will not pass the environment test when you install them later.

2.3 Compiling and installing zabbix

2.3.1 Downloading the tarball

[root@oe01 opt]# wget /zabbix/sources/oldstable/6.2/zabbix-6.2.
[root@oe01 opt]# ls zabbix-6.2. 
zabbix-6.2.

2.3.2 Decompression

[root@oe01 opt]# tar -zxvf zabbix-6.2.

2.3.3 Creating users/groups

[root@oe01 opt]# groupadd --system zabbix
[root@oe01 opt]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix User" zabbix

2.3.4 Starting installation

[root@oe01 zabbix-6.2.8]# ./configure --sysconfdir=/etc/zabbix --enable-server --enable-agent --with-mysql --with-ssh2 --with-zlib --with-libpthread --with-libevent --with-libpcre --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-openssl --with-ldap

Wait for the execution to complete, if there is an error report check the previous installation is not missing something

After normal execution it should look like this

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <>                    *
***********************************************************

Then we execute themake install

[root@oe01 zabbix-6.2.8]# make install
Making install in misc
make[1]: Entering directory '/opt/zabbix-6.2.8/misc'
make[2]: Entering directory '/opt/zabbix-6.2.8/misc'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/opt/zabbix-6.2.8/misc'
make[1]: Leaving directory '/opt/zabbix-6.2.8/misc'
make[1]: Entering directory '/opt/zabbix-6.2.8'
make[2]: Entering directory '/opt/zabbix-6.2.8'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/opt/zabbix-6.2.8'
make[1]: Leaving directory '/opt/zabbix-6.2.8'

The execution finishes like this

2.3.5 Configuring the database

We didn't mention the database installation earlier because the M in LNMP is MySQL/Mariadb, so you can just install it on your own, I'll install it anyway

[root@oe01 zabbix-6.2.8]# yum remove mariadb-server # This step is not necessary, I am trying to restore the database.
[root@oe01 zabbix-6.2.8]# yum install mariadb-server
[root@oe01 zabbix-6.2.8]# systemctl restart mariadb
[root@oe01 zabbix-6.2.8]# mysql_secure_installation

Log in to the database after completing the initialization

[root@oe01 zabbix-6.2.8]# mysql -uroot -p
MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create user 'zabbix'@'%' identified by '123';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'%';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

Next, import the data into the database

[root@oe01 zabbix-6.2.8]# cd database/mysql/
[root@oe01 mysql]# mysql -uroot -p123 zabbix <  
[root@oe01 mysql]# mysql -uroot -p123 zabbix <  
[root@oe01 mysql]# mysql -uroot -p123 zabbix <  
[root@oe01 mysql]# mysql -uroot -p123 zabbix <  
[root@oe01 mysql]# mysql -uroot -p123 zabbix < history_pk_prepare.sql

Be careful not to get the order wrong. If it is wrong, the import will fail and report an error

At this point, all preparations for zabbix are complete

3. Configuring zabbix

3.1 Modification of configuration files

[root@oe01 ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=192.168.200.179 # change to database address
DBPassword=123 # Change the password to the database.
DBPort=3306 # The port of the database.
ListenPort=10051 # Uncomment this line.

Then we start zabbix

[root@oe01 ~]# zabbix_server -c /etc/zabbix/zabbix_server.conf

3.2 Web interface deployment

[root@oe01 ~]# cd /data/zabbix/
[root@oe01 zabbix]# cp -r /opt/zabbix-6.2.8/ui/* .
[root@oe01 zabbix]# chown nginx:nginx -R /data/zabbix/

Access to the browser for subsequent operations

Language Select Simplified Chinese

Time Select Beijing Time

Here's the error we can click to download the configuration file and transfer it to the server

After passing it around and clicking Finish, you'll be prompted that zabbix has been configured

The default login username isAdminThe password iszabbix

The server side is done.

4. Installation of agent

agent is installed on the monitored node

[root@oe01 ~]# rpm -Uvh /zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-3.
[root@oe01 ~]# yum install zabbix-agent2 -y

Then we modify the relevant configuration file

[root@oe01 ~]# vim /etc/zabbix/zabbix_agent2.conf
Server=192.168.200.179
[root@oe01 ~]# systemctl restart  

Change server here to the address of zabbix-server

5. Adding hosts

Point into the host here when you will find that there is no display of Chinese, we need to upload the font on windows to the server

Windows font pathC:\Windows\Fonts\

[root@oe01 fonts]# pwd
/data/zabbix/assets/fonts

Upload fonts to this directory

[root@oe01 fonts]# ls
  
[root@oe01 fonts]# mv  
[root@oe01 fonts]# mv  

Backup the original font file, then change the font we uploaded to the same file name as before, go back to the webpage and refresh it!

The fonts are already out.