Compile and install Zabbix6.2 from CentOS7 source code, tune it, and integrate it with grafana

Zabbix6.2 does not support installation using yum on CentOS7. If it is CentOS8/9, Rocky, etc., it can be installed directly using the dnf (yum) package. Although it is not as flexible as source code compilation, it is simple and fast and can meet the needs of most usage scenarios. At the same time, since Zabbix6.2 requires the use of MySQL8 database, and other systems that are not compatible with MySQL8 are also deployed on the server planned for deployment, PostgreSQL is used as the Zabbix server database here.

  • Zabbix architecture information:

1. zabbix-server

The server side of zabbix is ​​responsible for receiving monitoring data sent by the agent and providing all core functions of zabbix.

2. database

Database used to store monitoring data and configuration information. Currently, there are two commonly used databases: mysql and postgresql.

3. zabbix-web

The UI side of zabbix provides functions such as operation console and monitoring display.

4. zabbix-java-gateway

Used to monitor the JVM status of Java programs. Zabbix itself cannot directly obtain monitoring indicators from the JVM, so this gateway needs to be used to achieve this.

5. zabbix-agent

The agent of zabbix is ​​deployed on the target host to collect monitoring data of the host and provide it to the zabbix server.

  • Installation Environment

  • 1.Install php74

    #查看系统自带php包
    rpm -qa | grep php
    
    #卸载php,注意先卸载依赖包
    rpm -e <包名>
    
    #安装PHP74
    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    rpm -Uvh epel-release-latest-7.noarch.rpm
    rpm -Uvh remi-release-7.rpm
    yum install yum-utils
    yum-config-manager --enable remi-php74
    yum install php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd php-pgsql
    yum -y install curl-devl libxml2 libxml2-devel
    systemctl enable  php74-php-fpm.service
    systemctl start php74-php-fpm.service
    
    #如果php命令找不到,创建软连接
    ln -s /opt/remi/php74/root/usr/bin/php /usr/bin/php
    
    #修改php参数
    vim /etc/php.ini
    #修改post_max_size为16M
    #修改max_execution_time为300
    #修改max_input_time为300
    systemctl restart httpd php74-php-fpm.service

    2. Install postgresql 15

    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libzstd-1.5.2-1.el7.x86_64.rpm
    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-devel-5.0.1-7.el7.x86_64.rpm
    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-5.0.1-7.el7.x86_64.rpm
    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-libs-5.0.1-7.el7.x86_64.rpm
    yum install -y ./libzstd-1.5.2-1.el7.x86_64.rpm
    yum install -y centos-release-scl-rh llvm5*
    yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    yum install postgresql15-server postgresql15-devel
    postgresql-15-setup  initdb
    systemctl enable postgresql-15
    systemctl start postgresql-15
    
    #修改postgres用户密码
    passwd postgres
    systemctl restart postgresql-15
    
    #修改数据库密码
    sudo -u postgres psql
    \password
    #退出psql命令行
    \q

  • Source code compilation and deployment Zabbix6.2:

1. Download the ZABBIX source code installation package (tar.gz) from the official website

2. Unzip

cd /home/cgyxt/workspace/zabbix
tar -zxvf zabbix-6.2.6.tar.gz

3.Create user

groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

3. Import the database

chmod -R 777 /home/cgyxt/workspace/zabbix/

#Create database user zabbix

sudo -u postgres createuser --pwprompt zabbix

#Create database

sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix

#Import database

cd /home/cgyxt/workspace/zabbix/zabbix-6.2.6/database/postgresql
cat schema.sql | sudo -u zabbix psql zabbix
cat images.sql | sudo -u zabbix psql zabbix
cat data.sql | sudo -u zabbix psql zabbix

4. Install dependencies as needed

yum install -y net-snmp-devel OpenIPMI-devel libevent-devel curl-devel java-1.6.0-openjdk-devel libssh2-devel go fping openldap openldap-devel unixODBC unixODBC-devel freetds mysql-connector-odbc

If you need to use the modbus protocol to transmit data: source code installation depends on libmodbus

tar -zxvf libmodbus-3.1.6.tar.gz
cd libmodbus-3.1.6/
./configure
make install

5. Compile and install

cd /home/cgyxt/workspace/zabbix/zabbix-6.2.6/

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-postgresql=/usr/pgsql-15/bin/pg_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-zlib --with-libpthread --with-libevent --with-libpcre --with-libmodbus=/usr/local --with-openipmi --with-ssh2 --with-unixodbc --with-ldap --with-openssl --with-iconv --enable-java --enable-webservice

Note: You can also use gnutls instead of openssl encryption:

yum install gnutls.x86_64 gnutls-c++.x86_64 gnutls-dane.x86_64  gnutls-devel.x86_64 gnutls-utils.x86_64 -y

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-postgresql=/usr/pgsql-15/bin/pg_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-zlib --with-libpthread --with-libevent --with-libpcre --with-libmodbus=/usr/local --with-openipmi --with-ssh2 --with-unixodbc --with-ldap --with-gnutls --with-iconv --enable-java --enable-webservice

make install

6. Modify configuration file

vim /usr/local/zabbix/etc/zabbix_server.conf
DBPassword=<password>
CacheSize=1024M   #增大zabbix_server缓存空间,避免主机较多时缓存用尽导致服务停止

7. Create startup script

#创建环境变量,用于直接用zabbix_server命令启动服务
echo "export PATH=$PATH:/usr/local/zabbix/sbin" >> ~/.bashrc


#创建zabbix_server守护文件
vim /lib/systemd/system/zabbix-server.service


[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
#EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutStopSec=10s

[Install]
WantedBy=multi-user.target


chmod 754 /lib/systemd/system/zabbix-server.service



#创建zabbix_agentd守护文件
vim /usr/lib/systemd/system/zabbix-agent.service

[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
#EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

chmod 754 /lib/systemd/system/zabbix-agent.service

8. Move the front-end files to the Apache service directory

mkdir /var/www/html/zabbix/
cp -r /home/cgyxt/workspace/zabbix/zabbix-6.2.6/ui/* /var/www/html/zabbix/
chmod -R 777 /var/www/html/zabbix/

9. Start the service

systemctl daemon-reload
systemctl enable zabbix-server.service
systemctl start zabbix-server.service
systemctl enable zabbix-agent.service
systemctl start zabbix-agent.service
#查看进程检查结果
ps -ef | grep zabbix

#检查服务运行情况
systemctl -a | grep zabbix

10. Install according to the wizard in the Web interface

11.Fix Chinese garbled characters

#从电脑fonts文件夹中拷贝出微软雅黑字体,放入zabbix字体文件夹中
cp /home/cgyxt/workspace/zabbix/msyh.ttc /var/www/html/zabbix/assets/fonts/

#备份原有字体
mv /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf.bak

#建立软连接
ln -s /var/www/html/zabbix/assets/fonts/msyh.ttc /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf
#或直接覆盖:mv /var/www/html/zabbix/assets/fonts/msyh.ttc /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf

11. Set passwordless sudo permissions for the zabbix user to facilitate subsequent script writing

vim /etc/sudoers
#添加:zabbix  ALL=(ALL)       NOPASSWD:ALL


## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
zabbix  ALL=(ALL)       NOPASSWD:ALL
  • yum install zabbix agent2

rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/7/x86_64/zabbix-release-6.2-3.el7.noarch.rpm
yum clean all
yum install zabbix-agent2 zabbix-agent2-plugin-* -y
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
  • Install grafana and integrate with Zabbix

1. Download the rpm package and install it

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.2-1.x86_64.rpm
yum -y install grafana-enterprise-9.3.2-1.x86_64.rpm
systemctl start grafana-server && systemctl enable grafana-server

Browser access IP: 3000, username/password: admin

2. Download and install the Zabbix plug-in

(1) Method 1

Browser opens:

 ​https://grafana.com/api/plugins/alexanderzobnin-zabbix-app

Search for "downloadurl" and add " Grafana Visit the download page and redirect to the download address:

https://storage.googleapis.com/plugins-community/alexanderzobnin-zabbix-app/release/4.2.10/alexanderzobnin-zabbix-app-4.2.10.zip

#After the download is completed, upload it to the server, copy it to the /var/lib/grafana/plugins folder and unzip it

cp alexanderzobnin-zabbix-app-4.2.10.zip /var/lib/grafana/plugins/
cd /var/lib/grafana/plugins/
unzip alexanderzobnin-zabbix-app-4.2.10.zip

(2) Method 2

grafana-cli plugins install alexanderzobnin-zabbix-app

3. Restart grafana-server and enter the web interface to enable installation of the Zabbix plug-in.

systemctl restart grafana-server

Web interface Configuration>Plugins>Zabbix, click enable

4. Configure zabbix data source

#Configuration>Datasources, add, select zabbix

Fill in the zabbix server address and username and password to test.

Guess you like

Origin blog.csdn.net/N71FS1/article/details/130026855