Zabbix 6.0 graphic installation and deployment explanation---LNMP environment

Introduction

Zabbix mainly consists of the following components:

Zabbix Server : Zabbix server is the core component of Zabbix. It is responsible for receiving monitoring data and triggering alarms, and is also responsible for persisting monitoring data to the database.

Zabbix Agent : Zabbix client, deployed on the monitored device, is responsible for collecting monitoring data, and the collected data is sent to Zabbix Server for processing. Zabbix Agent currently has two versions: Zabbix agent and Zabbix agent 2. The former is developed in C language and supports almost all mainstream platforms. The latter is developed by Go, and its advantages include: it can effectively reduce the number of TCP connections; it supports higher concurrency; and it is easy to expand. The goal is to replace the Zabbix agent, currently only supports Linux and Windows platforms.

Zabbix Proxy : Instead of Zabbix Server, it receives monitoring data and performs preprocessing. The preprocessed data is sent to Zabbix Server in batches, which can reduce the pressure on Zabbix Server.

Web page : You can manage and maintain the configuration information of the monitored device, view monitoring data, configure alarms, etc. through the Web page.

Database : responsible for storing configuration information and monitoring data of monitored devices. Supported databases are: MySQL (Percona, MariaDB), Oracle, PostgreSQL, TimescaleDB for PostgreSQL, SQLite

Environmental requirements

The database Mysql needs to be version 8.0.x or above. PHP does not support PHP8.0 version. For details, please refer to –> Official Documentation .
The installation environment of this article : Centos 7.4, Nginx 1.20, Mysql 8.0.30, PHP 7.2, Zabbix-Server 6.0. 1
insert image description here
insert image description here

deployment environment

Turn off the system firewall

[root@zabbix-40 ~]# systemctl stop firewalld
[root@zabbix-40 ~]# systemctl disable firewalld
[root@zabbix-40 ~]# vim /etc/selinux/config
SELINUX=disabled

1. Mysql8.0.30 deployment

Download and install the bundled package, solve dependency-related problems, and avoid trouble. CentOS7 can choose the package of Red Hat Enterprise Edition 7 –> download address

[root@zabbix-40 ~]# cd /usr/local/src/
[root@zabbix-40 /usr/local/src]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
# 解压
[root@zabbix-40 /usr/local/src]# tar -xvf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
# 忽略依赖检查强制安装,因为捆绑包里已经带依赖了,所以只要全部安装就可以,检查的话分先后顺序很麻烦的
[root@zabbix-40 /usr/local/src]# sudo rpm -ivh mysql-community-*  --force --nodeps
#创建数据存储目录
[root@zabbix-40 ~]# mkdir -p /data/mysql
[root@zabbix-40 ~]# chown mysql:mysql /data/mysql
#修改配置文件
[root@zabbix-40 ~]# vim /etc/my.cnf
[root@zabbix-40 ~]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
port=3306
lower_case_table_names=1
max_connections=500

start database

#先查看libaio包是否有安装(安装了则不用管,未安装可能出现启动失败缺包的情况)
#我这里使用的是aliyun的yum源(需要的可以在文档最底部查看)
[root@zabbix-40 ~]# yum install libaio
[root@zabbix-40 ~]# systemctl enable mysqld
[root@zabbix-40 ~]# systemctl start mysqld
#启动失败的话可以查看日志 /var/log/mysqld.log

Get the password to log in to Mysql

[root@zabbix-40 /data]# cat /var/log/mysqld.log | grep password
2022-12-15T09:31:52.061965Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: z-Tp1q+/8J.7
[root@zabbix-40 /data]# mysql -uroot -pz-Tp1q+/8J.7
mysql> alter user 'root'@'localhost' identified by 'Oyst@655';
mysql> flush privileges;
#由于MySQL8.0 有密码验证组件,若希望设置简单的密码,需要修改服务验证条件
# 密码检查等级,0/LOW、1/MEDIUM、2/STRONG
mysql> set global validate_password.policy=0;
# 密码的最短长度
mysql> set global validate_password.length=6;
# 密码至少要包含的小写字母个数和大写字母个数
mysql> set global validate_password.mixed_case_count=0;
#创建zabbix库(这里zabbix对库的编码格式有需求)
mysql> create database zabbix character set utf8 collate utf8_bin;
#创建用户(指定使用的身份验证插件)
mysql> create user 'zabbix'@'localhost' identified with mysql_native_password by '123123';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> flush privileges;

Two, nginx deployment

[root@zabbix-40 ~]# rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.0-1.el7.ngx.x86_64.rpm

[root@zabbix-40 ~]# mkdir /data/web
[root@zabbix-40 ~]# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
#修改nginx的配置文件,要修改的主要是server{} ,也可以复制过去直接覆盖原来的配置文件
[root@zabbix-40 /etc/nginx]# vim /etc/nginx/nginx.conf 
user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    
    
    worker_connections  1024;
}

http {
    
    
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    server {
    
    
      listen       80;
      server_name  localhost;
      root         /data/web;
      location / {
    
    
        index  index.php index.html index.htm;
      }
      location ~ \.php$ {
    
    
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
      }
    }
}

[root@zabbix-40 ~]# systemctl  enable nginx 
[root@zabbix-40 ~]# systemctl  start nginx 

#验证端口(能看到nginx的 80 端口开始监听了)
[root@zabbix-40 ~]# netstat -ntlp
Proto Recv-Q  Send-Q   Local Address   Foreign Address      State        PID/Program name
tcp    0       0       0.0.0.0:80      0.0.0.0:*            LISTEN      2507/nginx: master  

3. PHP deployment

[root@zabbix-40 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@zabbix-40 ~]# yum -y install epel-release
[root@zabbix-40 ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@zabbix-40 ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#webtatic源,一个web服务的源
#安装php7及其它依赖软件
[root@zabbix-40 ~]# yum -y install gcc gcc-c++ php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd
[root@zabbix-40 ~]# vim /etc/php.ini 
368:max_execution_time = 300
378:max_input_time = 300
656:post_max_size = 16M
[root@zabbix-40 ~]# cd /data/web/
[root@zabbix-40 ~]# vim index.php   #创建php测试页面
<?php
phpinfo();
?>
[root@zabbix-40 ~]# systemctl  enable php-fpm
[root@zabbix-40 ~]# systemctl  start php-fpm

#验证端口(能看到php的 9000 端口开始监听了)
[root@zabbix-40 ~]# netstat -ntlp
Proto Recv-Q  Send-Q   Local Address      Foreign Address      State        PID/Program name
tcp    0      0        127.0.0.1:9000       0.0.0.0:*          LISTEN      8450/php-fpm: maste

Here you can use a browser to verify Nginx and PHP (directly enter the IP in the intranet)
![Insert picture description here](https://img-blog.csdnimg.cn/262b36c094ae475f90b976bbacb4eb86.png
# If you can access this PHP page here, it means that your nginx and php configurations are normal, and you are only a little away from victory
The configuration of nginx is directly configured in nginx.conf. If you need to configure it in conf.d, you can study it yourself.

Four, zabbix-server deployment

#创建用户
[root@zabbix-40 ~]# groupadd zabbix
[root@zabbix-40 ~]# useradd -g zabbix -M -s /sbin/nologin zabbix
#下载安装
[root@zabbix-40 ~]# cd /usr/local/src
[root@zabbix-40 /usr/local/src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.1.tar.gz
[root@zabbix-40 /usr/local/src]# tar -xf zabbix-6.0.1.tar.gz
[root@zabbix-40 /usr/local/src]# cd zabbix-6.0.1/
#安装依赖
[root@zabbix-40 /usr/local/src/zabbix-6.0.1]# yum -y install  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
#编译安装
[root@zabbix-40 /usr/local/src/zabbix-6.0.1]# ./configure --sysconfdir=/etc/zabbix --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre
[root@zabbix-40 /usr/local/src/zabbix-6.0.1]# make install

#修改配置文件(前面的数字代表的是要修改属性字段的行数 例如 12:)
[root@zabbix-40 ~]# vim /etc/zabbix/zabbix_server.conf
[root@zabbix-40 ~]# grep -n '^[a-Z]' /etc/zabbix/zabbix_server.conf
12:ListenPort=10051
38:LogFile=/tmp/zabbix_server.log
87:DBHost=localhost
99:DBName=zabbix
115:DBUser=zabbix
123:DBPassword=123123
507:Timeout=4
593:LogSlowQueries=3000
708:StatsAllowedIP=127.0.0.1

#向数据库中导入zabbix的库表及数据(注意导入的顺序)
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/schema.sql
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/images.sql
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/data.sql

#移动zabbix前端页面到网站根目录
[root@zabbix-40 ~]# cp -rp /usr/local/src/zabbix-6.0.1/ui/* /data/web/
cp:是否覆盖"/data/web/index.php"? y

#配置zabbix系统启停命令(注意这个文件是新增的)
[root@zabbix-40 ~]# vim /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server with MySQL DB
After=syslog.target network.target mysqld.service
[Service]
Type=simple
ExecStart=/usr/local/sbin/zabbix_server -f
User=zabbix
[Install]
WantedBy=multi-user.target

#重新加载system文件
[root@Zabbix mysql]# systemctl daemon-reload
[root@Zabbix mysql]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix.service.
[root@Zabbix mysql]# systemctl start zabbix-server

5. Web side initialization

  1. Enter the IP and jump directly to the zabbix webpage
    ![Insert picture description here](https://img-blog.csdnimg.cn/2d3ce5ec1a2d4909983060905f60f545.png
    1.1. If you can’t jump to the zabbix UI interface in this step, you can check the forwarding of the configuration file configuration at the end of .conf in the /etc/nginx/ and /etc/nginx/conf.d/ directories Address and whether port 80 is enabled and occupied
  2. The PHP configuration file has been adjusted here. If you still have problems, you can edit /etc/php.ini and adjust the value of the corresponding field.
    ![Insert picture description here](https://img-blog.csdnimg.cn/48e0d7b4275e4f13aafdcc007f4c3728.png
  3. Configure DB connection
    insert image description here

3.1 The server requested an authentication method unknown to the client.
insert image description here
Reason: Because Mysql 8 default authentication plug-in for creating users is caching_sha2_password, so we need to specify the authentication plug-in as mysql_native_password when creating zabbix users.

#解决办法
mysql> drop user zabbix@localhost;
mysql> create user 'zabbix'@'localhost' identified with mysql_native_password by '123123';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> flush privileges;

3.2 Unable to determine current Zabbix database version: table 'dbversion' not found.
insert image description here
Reason: The table required by zabbix was not imported into mysql

#解决办法
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/schema.sql
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/images.sql
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/data.sql

3.3 The character set or collation of the table is not supported
insert image description here
Reason: The encoding method needs to be specified when creating the zabbix library (similar to the first question)

#解决办法
mysql> drop database zabbix;
mysql> create database zabbix character set utf8 collate utf8_bin;
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/schema.sql
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/images.sql
[root@zabbix-40 ~]# mysql -uzabbix -p123123 zabbix < /usr/local/src/zabbix-6.0.1/database/mysql/data.sql
  1. You can customize the Zabbix host name here
    insert image description here
    insert image description here
  2. Installation
    insert image description here
    Either download the configuration file, upload it and authorize it to zabbix, or
    do the following:
[root@zabbix-40 ~]# cp /data/web/conf/zabbix.conf.php.example /data/web/conf/zabbix.conf.php
[root@zabbix-40 ~]# chown zabbix:zabbix /data/web/conf/zabbix.conf.php
[root@zabbix-40 ~]# vim /data/web/conf/zabbix.conf.php
#只修改PASSWORD的密码
$DB['PASSWORD']			= '123123';

insert image description here
Default account password: Admin zabbix
insert image description here

6. Solve the problem of Chinese garbled characters in zabbix 6.0

Copy the ttf file in italics from the C:\Windows\Fonts path of Windows to the /data/web/assets/fonts directory of Linux,

#目录下有simkai.ttf这个新上传的文件
[root@zabbix-40 ~]# ll /data/web/assets/fonts
总用量 12252
-rw-r--r-- 1 zabbix zabbix   756072 228 2022 DejaVuSans.ttf
-rw-r--r-- 1 root   root   11787328 1219 16:57 simkai.ttf
#替换配置文件中的默认字体
[root@zabbix-40 ~]# sed -i 's/DejaVuSans/simkai/g' /data/web/include/defines.inc.php
#如果这里之前是修改了网页路径的话,到自己的路径下找include/defines.inc.php即可

Note that there is another problem of garbled characters that may be sent (it will not take effect when the host is renamed with Chinese characters)
Zabbix does not support Chinese characters in the host name. To make the zabbix host name support Chinese, you need to modify the zabbix php configuration file

[root@zabbix-40 ~]# vim /data/web/include/defines.inc.php
#将下面的字段(大概在1198 行)
define('ZBX_PREG_INTERNAL_NAMES', '([0-9a-zA-Z_\. \-]+)');
改成
define('ZBX_PREG_INTERNAL_NAMES', '([0-9a-zA-Z_\. \-\x{80}-\x{ff}]+)');

#改完重启一些zabbix-server
[root@zabbix-40 ~]# systemctl restart zabbix-server

The source of Alibaba Cloud can view the zabbix-agent rapid deployment article in the personal homepage –> link

Supongo que te gusta

Origin blog.csdn.net/weixin_52906737/article/details/128331225
Recomendado
Clasificación