zabbix 6.2版本部署

该博客详细介绍了如何在CentOS Stream release 9上部署Zabbix 6.2,包括安装http服务、配置php-fpm、搭建MySQL数据库,以及解决编译和页面乱码问题。步骤涵盖从安装httpd、php-fpm到创建数据库,再到源码编译安装Zabbix,最后配置Zabbix服务端和agentd。
摘要由CSDN通过智能技术生成

操作系统版本 CentOS Stream release 9
数据库版本 mysql 8.0.31
Linux + HTTP + PHP + MYSQL

一. 安装 http

yum -y install httpd

1.1 编译http配置文件

[root@zabbix-server conf]# cd /etc/httpd/conf.d/
[root@zabbix-server conf.d]# ll
总用量 16
-rw-r--r--. 1 root root 2916  722 19:42 autoindex.conf
-rw-r--r--. 1 root root  400  722 19:43 README
-rw-r--r--. 1 root root 1252  722 19:41 userdir.conf
-rw-r--r--. 1 root root  653  722 19:41 welcome.conf
[root@zabbix-server conf.d]# find / -name *vhosts.conf
/usr/share/doc/httpd-core/httpd-vhosts.conf

1.2 复制一份httpd-vhosts.conf 到 /etc/httpd/conf.d/ 目录下并添加以下内容

[root@zabbix-server conf.d]# cp /usr/share/doc/httpd-core/httpd-vhosts.conf .
[root@zabbix-server conf.d]# ll
总用量 20
-rw-r--r--. 1 root root 2916  722 19:42 autoindex.conf
-rw-r--r--. 1 root root 1477 126 11:01 httpd-vhosts.conf
-rw-r--r--. 1 root root  400  722 19:43 README
-rw-r--r--. 1 root root 1252  722 19:41 userdir.conf

[root@zabbix-server conf.d]# vim httpd-vhosts.conf 
#添加内容如下
<VirtualHost *:80>
    DocumentRoot "/var/www/html/zabbix.example.com"
    ServerName zabbix.example.com
    ProxyRequests off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/zabbix.example.com/$1
    <Directory "/var/www/html/zabbix.example.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
    ErrorLog "/var/log/httpd/zabbix.example.com-error_log"
    CustomLog "/var/log/httpd/zabbix.example.com-access_log" common
</VirtualHost>

1.3 查看是否有IncludeOptional conf.d/*.conf

[root@zabbix-server httpd]# cat /etc/httpd/conf/httpd.conf | grep IncludeOptional
IncludeOptional conf.d/*.conf

1.4 修改配置文件httpd.conf

[root@zabbix-server conf.d]# cd ..
[root@zabbix-server httpd]# vim conf/httpd.conf 
#搜索/DirectoryIndex,添加index.php
#DirectoryIndex: sets the file that Apache will serve if a directory
#is requested.
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

#//搜索AddType,添加以下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps  

1.5 创建测试页面

注意:测试页面需要安装php后才可以正常访问。

[root@zabbix-server httpd]# mkdir /var/www/html/zabbix.example.com
[root@zabbix-server httpd]# vim /var/www/html/zabbix.example.com/index.php
<?php
   phpinfo();
?>

1.6 开启httpd服务

[root@zabbix-server ~]# systemctl enable --now httpd

二、安装php-fpm

2.1 安装 php-fpm软件

[root@zabbix-server ~]#  yum install -y php-cli php-common php-mbstring php-fpm php-xml php-json
.....
已安装:
  nginx-filesystem-1:1.20.1-13.el9.noarch   oniguruma-6.9.6-1.el9.5.x86_64   php-cli-8.0.20-3.el9.x86_64
  php-common-8.0.20-3.el9.x86_64            php-fpm-8.0.20-3.el9.x86_64      php-mbstring-8.0.20-3.el9.x86_64
  php-xml-8.0.20-3.el9.x86_64

完毕!

[root@zabbix-server conf]# rpm -qa | grep php*
libmspack-0.10.1-0.7.alpha.el9.x86_64
php-common-8.0.20-3.el9.x86_64
php-fpm-8.0.20-3.el9.x86_64
php-mbstring-8.0.20-3.el9.x86_64
php-cli-8.0.20-3.el9.x86_64
php-xml-8.0.20-3.el9.x86_64

2.2 修改php-fpm配置文件

[root@zabbix-server ~]# vim /etc/php-fpm.d/www.conf
#把如下配置改为
;listen = /run/php-fpm/www.sock
#改后
;Note: This value is mandatory.
listen = 0.0.0.0:9000
[root@zabbix-server]# systemctl start php-fpm
[root@zabbix-server]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2022-12-06 17:07:29 CST; 15s ago
   Main PID: 15393 (php-fpm)
     Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 6 (limit: 10940)
     Memory: 8.9M
        CPU: 28ms
     CGroup: /system.slice/php-fpm.service
             ├─15393 "php-fpm: master process (/etc/php-fpm.conf)"
             ├─15394 "php-fpm: pool www"
             ├─15395 "php-fpm: pool www"
             ├─15396 "php-fpm: pool www"
             ├─15397 "php-fpm: pool www"
             └─15398 "php-fpm: pool www"

12月 06 17:07:29 zabbix-server systemd[1]: Starting The PHP FastCGI Process Manager...
12月 06 17:07:29 zabbix-server systemd[1]: Started The PHP FastCGI Process Manager.

[root@zabbix-server]# ss -anlt
State        Recv-Q       Send-Q             Local Address:Port             Peer Address:Port      Process
LISTEN       0            511                      0.0.0.0:9000                  0.0.0.0:*
LISTEN       0            128                      0.0.0.0:22                    0.0.0.0:*
LISTEN       0            128                         [::]:22                       [::]:*
LISTEN       0            511                            *:80                          *:*

2.3 关闭防火墙、selinux

[root@localhost php-fpm.d]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost php-fpm.d]# setenforce 0
[root@localhost php-fpm.d]# vim /etc/selinux/config
[root@localhost php-fpm.d]# cat /etc/selinux/config | grep SELINUX=
#SELINUX= can take one of these three values:
SELINUX=disabled

2.4 测试页面

打开浏览器访问 http://ip:80
出现php页面说明http+php-fpm搭建成功。
在这里插入图片描述

三、数据库搭建

3.1 单独加个磁盘给到安装mysql目录

[root@zabbix-server httpd]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   100G  0 disk
├─sda1        8:1    0     1G  0 part /boot
└─sda2        8:2    0    99G  0 part
  ├─cs-root 253:0    0  65.2G  0 lvm  /
  ├─cs-swap 253:1    0     2G  0 lvm  [SWAP]
  └─cs-home 253:2    0  31.8G  0 lvm  /home
sr0          11:0    1 116.7M  0 rom
sr1          11:1    1  1024M  0 rom

3.2 磁盘扫描

注意:加了之后识别不出来,需要进行磁盘扫描

[root@zabbix-server httpd]# echo "- - -" > /sys/class/scsi_host/host0/scan &&
echo "- - -" > /sys/class/scsi_host/host1/scan &&
echo "- - -" > /sys/class/scsi_host/host2/scan &&
echo "- - -" > /sys/class/scsi_host/host3/scan &&
echo "- - -" > /sys/class/scsi_host/host4/scan &&
echo "- - -" > /sys/class/scsi_host/host5/scan &&
echo "- - -" > /sys/class/scsi_host/host6/scan &&
echo "- - -" > /sys/class/scsi_host/host7/scan &&
echo "- - -" > /sys/class/scsi_host/host8/scan &&
echo "- - -" > /sys/class/scsi_host/host9/scan
-bash: /sys/class/scsi_host/host3/scan: 没有那个文件或目录
[root@zabbix-server httpd]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   100G  0 disk
├─sda1        8:1    0     1G  0 part /boot
└─sda2        8:2    0    99G  0 part
  ├─cs-root 253:0    0  65.2G  0 lvm  /
  ├─cs-swap 253:1    0     2G  0 lvm  [SWAP]
  └─cs-home 253:2    0  31.8G  0 lvm  /home
sdb           8:16   0    60G  0 disk
sr0          11:0    1 116.7M  0 rom
sr1          11:1    1  1024M  0 rom

3.3 对新增的磁盘进行分区

[root@zabbix-server httpd]# fdisk /dev/sdb

欢迎使用 fdisk (util-linux 2.37.4)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

设备不包含可识别的分区表。
创建了一个磁盘标识符为 0xcebe133d 的新 DOS 磁盘标签。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (0 primary, 0 extended, 4 free)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):

将使用默认回应 p。
分区号 (1-4, 默认  1):
第一个扇区 (2048-125829119, 默认 2048):
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (2048-125829119, 默认 125829119):

创建了一个新分区 1,类型为“Linux”,大小为 60 GiB。

命令(输入 m 获取帮助):w
分区表已调整。
将调用 ioctl() 来重新读分区表。
正在同步磁盘。

[root@zabbix-server httpd]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@zabbix-server httpd]# vgcreate vg_data /dev/sdb1
  Volume group "vg_data" successfully created
[root@zabbix-server httpd]# lvcreate -l +100%free -n lv_data vg_data
  Logical volume "lv_data" created.

3.4 格式化新建的分区

[root@zabbix-server httpd]# mkfs.xfs /dev/mapper/vg_data-lv_data
meta-data=/dev/mapper/vg_data-lv_data isize=512    agcount=4, agsize=3931904 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=15727616, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=7679, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@zabbix-server httpd]#

3.5 创建data目录并挂载

[root@zabbix-server httpd]# mkdir /data
[root@zabbix-server httpd]# mount /dev/mapper/vg_data-lv_data /data
[root@zabbix-server httpd]# cat /etc/fstab

# /etc/fstab
# Created by anaconda on Tue Dec  6 02:21:08 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cs-root     /                       xfs     defaults        0 0
UUID=39129efa-4d0e-48e6-8579-9741a509e079 /boot                   xfs     defaults        0 0
/dev/mapper/cs-home     /home                   xfs     defaults        0 0
/dev/mapper/cs-swap     none                    swap    defaults        0 0
 /dev/mapper/vg_data-lv_data    /data   xfs     defaults        0 0

3.6 设置limits.conf

[root@zabbix-server ]# cat /etc/security/limits.conf
...
mysql soft nofile 65535 
mysql hard nofile 65535 
mysql soft nproc unlimited
mysql hard nproc unlimited

3.7 在data目录下创建数据库相应的目录

mkdir -p /data/mysql8.0.31/3307_3307/
cd /data/mysql8.0.31/3307_3307
mkdir {data,binlog,log,conf,relaylog}

3.8 将下载好的mysql软件解压重命名为install

[root@zabbix-server ]# cd /data
[root@zabbix-server data]# tar -Jxvf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
[root@zabbix-server data]# mv mysql-8.0.31-linux-glibc2.12-x86_64/ /data/mysql8.0.31/install

3.9 编译my.cnf配置文件conf 目录下

cat /data/mysql8.0.31/3307_3307/conf/my.cnf
#######################################################
[client]
socket                             = /data/mysql8.0.31/3307_3307/data/mysql.sock
port                               = 3307
host=localhost
user=root
password=

[mysql]
no-auto-rehash

[mysqld]
############# GENERAL #############
autocommit                         = ON
character_set_server               = utf8mb4
collation-server                   = utf8mb4_general_ci
lower_case_table_names             = 1
port                               = 3307
transaction_isolation              = REPEATABLE-READ
pid-file                           = /data/mysql8.0.31/3307_3307/data/mysql.pid
default-time-zone        = '+8:00'

tmp_table_size  =32M
max_heap_table_size =32M

############### PATH ##############
basedir                            = /data/mysql8.0.31/install
tmpdir                             = /data/mysql8.0.31/3307_3307/data/
datadir                            = /data/mysql8.0.31/3307_3307/data/
socket                             = /data/mysql8.0.31/3307_3307/data/mysql.sock
log_error                          = /data/mysql8.0.31/3307_3307/log/error.log
slow_query_log_file                = /data/mysql8.0.31/3307_3307/log/slow.log
log_bin                            = /data/mysql8.0.31/3307_3307/binlog/mysql-bin
log_bin_index                      = /data/mysql8.0.31/3307_3307/binlog/mysql-bin.index
relay_log                          = /data/mysql8.0.31/3307_3307/relaylog/mysql-relay
relay_log_index                    = /data/mysql8.0.31/3307_3307/relaylog/mysql-relay.index

####### CACHES AND LIMITS #########
max_allowed_packet                 = 32M
max_connect_errors                 = 10000
max_connections                    = 5000
wait_timeout                       = 28800
slave_net_timeout                  = 100
#interactive_timeout               = 100
sort_buffer_size                   = 1M
table_open_cache                   = 4000  ###SHOW GLOBAL STATUS-->Open_tables
table_open_cache_instances         = 4

############# SAFETY ##############
log_bin_trust_function_creators    = true
skip_name_resolve                  = ON

############# LOGGING #############
general_log                        = OFF
log_queries_not_using_indexes      = ON
log_slow_admin_statements          = ON
long_query_time                    = 5
slow_query_log                     = ON

############# INNODB #############

innodb_flush_method                = O_DIRECT
innodb_buffer_pool_size            = 12288M
innodb_log_file_size               = 512M
innodb_log_files_in_group          = 3
innodb_log_buffer_size             = 16M
innodb_read_io_threads             = 8
innodb_write_io_threads            = 8
innodb_strict_mode                 = ON
innodb_io_capacity                 = 2000
innodb_lock_wait_timeout           = 50
innodb_open_files                  =  16384
innodb_data_home_dir               = /data/mysql8.0.31/3307_3307/data/
binlog_format                      = 'ROW'
#innodb_additional_mem_pool_size    =  20M
innodb_log_group_home_dir          =  /data/mysql8.0.31/3307_3307/data/
innodb_thread_concurrency          =  48

############# MyISAM #############
key_buffer_size                 =       500M
myisam_sort_buffer_size         =       64M
thread_cache_size               =       100

############# REPLICATION #############
binlog_format                      = ROW
expire_logs_days                   = 7
max_binlog_size                    = 512M
server_id                          = 723307
innodb_flush_log_at_trx_commit     = 2
sync_binlog                        = 100
log_slave_updates                  = ON

3.10 创建mysql用户

groupadd mysql
useradd -g mysql -d /home/mysql mysql
echo "test_2022" | passwd --stdin mysql
chown -R mysql:mysql /data
chmod -R 775 /data

3.11 初始化mysql数据库

/data/mysql8.0.31/install/bin/mysqld --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf  --initialize --user=mysql --log_error_verbosity --explicit_defaults_for_timestamp

3.11 以上命令执行无误后启动数据库

[root@zabbix-server 3307_3307]# cat start_mysql.sh
 nohup /data/mysql8.0.31/install/bin/mysqld_safe --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf &

3.12 创建启动数据库、登录数据库、停止数据库三个脚本

[root@zabbix-server 3307_3307]# cat start_mysql.sh
 nohup /data/mysql8.0.31/install/bin/mysqld_safe --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf &

登录mysql数据库

[root@zabbix-server 3307_3307]# cat login_mysql.sh 
/data/mysql8.0.31/install/bin/mysql --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf -uroot -p

停止mysql数据库

[root@zabbix-server 3307_3307]# cat stop_mysql.sh
/data/mysql8.0.31/install/bin/mysqladmin --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf -uroot -p shutdown

3.13 注意:登录数据库需查看root密码

[root@zabbix-server 3307_3307]# cat log/error.log | grep password
2022-12-07T16:46:59.854527Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: jko(edWft0mE

3.14 登录时报错缺少libtinfo.so.5

[root@zabbix-server 3307_3307]# sh login_mysql.sh
/data/mysql8.0.31/install/bin/mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

3.15 解决方法

ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.5
ln -s /usr/lib64/libncurses.so.6 /lib64/libtinfo.so.5

3.16 重新登录

[root@zabbix-server 3307_3307]# sh login_mysql.sh
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

3.17 修改密码并授权

mysql> alter user 'root'@'localhost' identified by "test";
Query OK, 0 rows affected (1.93 sec)

mysql> create user 'root'@'%' identified by "test";
Query OK, 0 rows affected (0.10 sec)

mysql> grant all privileges on *.* to 'root'@'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

四、zabbix 6.2 部署

4.1 zabbix服务端安装

官方网站下载地址
https://www.zabbix.com/cn/download_sources
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

4.2 下载zabbix软件,本次使用源码编译安装

[root@zabbix-server 3307_3307]# cd /usr/src/
[root@zabbix-server src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
--2022-12-08 01:43:55--  https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
正在解析主机 cdn.zabbix.com (cdn.zabbix.com)... 172.67.69.4, 104.26.6.148, 104.26.7.148, ...
正在连接 cdn.zabbix.com (cdn.zabbix.com)|172.67.69.4|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:34995538 (33M) [application/octet-stream]
正在保存至: “zabbix-6.2.2.tar.gz”

zabbix-6.2.2.tar.gz     100%[===============================>]  33.37M  3.52MB/s  用时 10s

2022-12-08 01:44:06 (3.28 MB/s) - 已保存 “zabbix-6.2.2.tar.gz” [34995538/34995538])

[root@zabbix-server src]# ll
总用量 34176
drwxr-xr-x. 2 root root        6  810  2021 debug
drwxr-xr-x. 2 root root        6  810  2021 kernels
-rw-r--r--. 1 root root 34995538  829 15:28 zabbix-6.2.2.tar.gz

4.3 安装依赖包

[root@zabbix-server src]# yum -y install net-snmp-devel libevent-devel

4.4 解压安装包并创建zabbix用户

[root@zabbix-server src]# tar -zxvf zabbix-6.2.2.tar.gz
[root@zabbix-server src]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
[root@zabbix-server src]# mkdir -p /usr/lib/zabbix
[root@zabbix-server src]# chmod 770 /usr/lib/zabbix
[root@zabbix-server src]# chown -R zabbix.zabbix /usr/lib/zabbix

4.5 创建zabbix数据库

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.32 sec)

mysql> create user 'zabbix'@'localhost' identified by "test";
Query OK, 0 rows affected (1.76 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.10 sec)

mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.08 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.11 sec)

4.6 导入schema、data、images 数据到zabbix库中

[root@zabbix-server 3307_3307]# cd /usr/src/zabbix-6.2.2/database/mysql/
[root@zabbix-server mysql]# /data/mysql8.0.31/install/bin/mysql --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf -uzabbix -ptest zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix-server mysql]# /data/mysql8.0.31/install/bin/mysql --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf -uzabbix -ptest zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix-server mysql]# /data/mysql8.0.31/install/bin/mysql --defaults-file=/data/mysql8.0.31/3307_3307/conf/my.cnf -uzabbix -ptest zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql> use zabbix;
Database changed
mysql> show tables;
.....
| users_groups               |
| usrgrp                     |
| valuemap                   |
| valuemap_mapping           |
| widget                     |
| widget_field               |
+----------------------------+
176 rows in set (0.30 sec)

mysql> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4.7 安装源码编译zabbix所需要的依赖包,并编译zabbix包

[root@zabbix-server zabbix-6.2.2]# pwd
/usr/src/zabbix-6.2.2
[root@zabbix-server zabbix-6.2.2]# yum -y install gcc gcc-c++ libxml2-devel libcurl-devel pcre-devel openssl openssl-devel golang-bin make

[root@zabbix-server zabbix-6.2.2]# ./configure --prefix=/usr/lib/zabbix --enable-server --enable-agent --enable-agent2 --enable-ipv6 --enable-proxy --with-net-snmp --with-mysql --with-libcurl --with-libxml2 --with-unixodbc

注意编译–with-unixodbc时,系统需要安装unixODBC-devel
安装步骤:https://blog.csdn.net/qq_41270538/article/details/128249793

4.8 编译时报错及处理方法

configure: error: MySQL library not found

原因是缺少mysql-devel依赖包
本次使用的mysql版本是8.0以上,mysql-devel也使用8.0以上的

官方yum源
https://dev.mysql.com/downloads/repo/yum/

[root@zabbix-server zabbix-6.2.2]# wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
--2022-12-08 11:36:10--  https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 104.82.33.201, 2600:140b:2:99d::2e31, 2600:140b:2:99c::2e31
正在连接 dev.mysql.com (dev.mysql.com)|104.82.33.201|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm [跟随至新的 URL]
--2022-12-08 11:36:12--  https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.3.109.33
正在连接 repo.mysql.com (repo.mysql.com)|23.3.109.33|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:10534 (10K) [application/x-redhat-package-manager]
正在保存至: “mysql80-community-release-el9-1.noarch.rpm”

mysql80-community-release-el9 100%[=================================================>]  10.29K  --.-KB/s  用时 0s

2022-12-08 11:36:13 (155 MB/s) - 已保存 “mysql80-community-release-el9-1.noarch.rpm” [10534/10534])

[root@zabbix-server zabbix-6.2.2]# rpm -ivh mysql80-community-release-el9-1.noarch.rpm
警告:mysql80-community-release-el9-1.noarch.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql80-community-release-el9-1  ################################# [100%]
[root@zabbix-server zabbix-6.2.2]# yum repolist | grep mysql
mysql-connectors-community           MySQL Connectors Community
mysql-tools-community                MySQL Tools Community
mysql80-community                    MySQL 8.0 Community Server

[root@zabbix-server zabbix-6.2.2]# yum -y install mysql-devel
MySQL 8.0 Community Server                                                              210 kB/s | 419 kB     00:01
MySQL Connectors Community                                                              9.6 kB/s | 9.2 kB     00:00
MySQL Tools Community                                                                    81 kB/s | 128 kB     00:01
依赖关系解决。
========================================================================================================================
 软件包                                    架构              版本                    仓库                          大小
========================================================================================================================
安装:
 mysql-community-devel                     x86_64            8.0.31-1.el9            mysql80-community            2.1 M
安装依赖关系:
 mysql-community-client-plugins            x86_64            8.0.31-1.el9            mysql80-community            1.4 M
 mysql-community-common                    x86_64            8.0.31-1.el9            mysql80-community            538 k
 mysql-community-libs                      x86_64            8.0.31-1.el9            mysql80-community            1.5 M

事务概要
========================================================================================================================
安装  4 软件包

总下载:5.5 M
安装大小:40 M
下载软件包:
(1/4): mysql-community-common-8.0.31-1.el9.x86_64.rpm                                   326 kB/s | 538 kB     00:01
(2/4): mysql-community-client-plugins-8.0.31-1.el9.x86_64.rpm                           677 kB/s | 1.4 MB     00:02
(3/4): mysql-community-devel-8.0.31-1.el9.x86_64.rpm                                    936 kB/s | 2.1 MB     00:02
(4/4): mysql-community-libs-8.0.31-1.el9.x86_64.rpm                                     1.9 MB/s | 1.5 MB     00:00
------------------------------------------------------------------------------------------------------------------------
总计                                                                                    2.3 MB/s | 5.5 MB     00:02
MySQL 8.0 Community Server                                                              3.0 MB/s | 3.1 kB     00:00
导入 GPG 公钥 0x3A79BD29:
 Userid: "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 指纹: 859B E8D7 C586 F538 430B 19C2 467B 942D 3A79 BD29
 来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                         1/1
  安装    : mysql-community-common-8.0.31-1.el9.x86_64                                                              1/4
  安装    : mysql-community-client-plugins-8.0.31-1.el9.x86_64                                                      2/4
  安装    : mysql-community-libs-8.0.31-1.el9.x86_64                                                                3/4
  运行脚本: mysql-community-libs-8.0.31-1.el9.x86_64                                                                3/4
  安装    : mysql-community-devel-8.0.31-1.el9.x86_64                                                               4/4
  运行脚本: mysql-community-devel-8.0.31-1.el9.x86_64                                                               4/4
  验证    : mysql-community-client-plugins-8.0.31-1.el9.x86_64                                                      1/4
  验证    : mysql-community-common-8.0.31-1.el9.x86_64                                                              2/4
  验证    : mysql-community-devel-8.0.31-1.el9.x86_64                                                               3/4
  验证    : mysql-community-libs-8.0.31-1.el9.x86_64                                                                4/4

已安装:
  mysql-community-client-plugins-8.0.31-1.el9.x86_64             mysql-community-common-8.0.31-1.el9.x86_64
  mysql-community-devel-8.0.31-1.el9.x86_64                      mysql-community-libs-8.0.31-1.el9.x86_64

完毕!

4.9 再次编译

[root@zabbix-server zabbix-6.2.2]# ./configure --prefix=/usr/lib/zabbix --enable-server --enable-agent --enable-agent2 --enable-ipv6 --enable-proxy --with-net-snmp --with-mysql --with-libcurl --with-libxml2 --with-unixodbc

......
  Enable agent 2:        yes

  Enable web service:    no

  Enable Java gateway:   no

  LDAP support:          no
  IPv6 support:          no

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@zabbix-server zabbix-6.2.2]# make install 

4.10 报错内容及解决方法

go: git.zabbix.com/ap/plugin-support@v0.0.0-20220608100211-35b8bffd7ad0: Get "https://proxy.golang.org/git.zabbix.com/ap/plugin-support/@v/v0.0.0-20220608100211-35b8bffd7ad0.mod": dial tcp 172.217.160.113:443: connect: connection refused
make[3]: *** [Makefile:634:install-zabbix.com/cmd/zabbix_agent2] 错误 1
make[3]: 离开目录“/usr/src/zabbix-6.2.2/src/go”
make[2]: *** [Makefile:514:install-am] 错误 2
make[2]: 离开目录“/usr/src/zabbix-6.2.2/src/go”
make[1]: *** [Makefile:512:install-recursive] 错误 1
make[1]: 离开目录“/usr/src/zabbix-6.2.2/src”
make: *** [Makefile:549:install-recursive] 错误 1

zabbix 编译成功后,make install报错,原因 proxy.golang.org国内无法访问
解决办法:使用代理

#打开 Go modules
go env -w GO111MODULE=on
#设置 GOPROXY
go env -w GOPROXY=https://goproxy.cn,direct

4.11 重新安装

make install
.......
make[2]: 离开目录“/usr/src/zabbix-6.2.2/man”
make[1]: 离开目录“/usr/src/zabbix-6.2.2/man”
Making install in misc
make[1]: 进入目录“/usr/src/zabbix-6.2.2/misc”
make[2]: 进入目录“/usr/src/zabbix-6.2.2/misc”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/usr/src/zabbix-6.2.2/misc”
make[1]: 离开目录“/usr/src/zabbix-6.2.2/misc”
make[1]: 进入目录“/usr/src/zabbix-6.2.2”
make[2]: 进入目录“/usr/src/zabbix-6.2.2”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/usr/src/zabbix-6.2.2”
make[1]: 离开目录“/usr/src/zabbix-6.2.2”

GOPROXY:

这个环境变量主要是用于设置 Go 模块代理,它的值是一个以英文逗号 “,” 分割的 Go module proxy 列表,默认是proxy.golang.org,国内访问不了。这里要感谢盛傲飞和七牛云为中国乃至全世界的 Go 语言开发者提供免费、可靠的、持续在线的且经过CDN加速Go module proxy(goproxy.cn)。

其实值列表中的 “direct” 为特殊指示符,用于指示 Go 回源到模块版本的源地址去抓取(比如 GitHub 等),当值列表中上一个 Go module proxy 返回 404 或 410 错误时,Go 自动尝试列表中的下一个,遇见 “direct” 时回源,遇见 EOF 时终止并抛出类似 “invalid version: unknown revision…” 的错误。

**修改 zabbix-server.conf 配置文件

[root@zabbix-server etc]# pwd
/usr/lib/zabbix/etc
[root@zabbix-server etc]# cat zabbix_server.conf | grep '^[a-Z]'
ListenPort=10051
LogFile=/usr/lib/zabbix/logs/zabbix_server.log
PidFile=/usr/lib/zabbix/logs/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
DBPassword=test
DBSocket=/data/mysql8.0.31/3307_3307/data/mysql.sock
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

4.12 配置 systemctl 文件,使用 systemctl 方式启动 zabbix-server

[root@zabbix-server system]# pwd
/usr/lib/systemd/system
[root@zabbix-server system]# cat zabbix_server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service

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

[Install]
WantedBy=multi-user.target
chmod 777 zabbix_server.service
systemctl daemon-reload
systemctl start zabbix_server.service
[root@zabbix-server system]# !ss
ss -anlt
State        Recv-Q       Send-Q             Local Address:Port                Peer Address:Port       Process
LISTEN       0            128                      0.0.0.0:22                       0.0.0.0:*
LISTEN       0            4096                     0.0.0.0:10051                    0.0.0.0:*
LISTEN       0            511                      0.0.0.0:9000                     0.0.0.0:*
LISTEN       0            511                            *:80                             *:*
LISTEN       0            128                         [::]:22                          [::]:*
LISTEN       0            4096                           *:3307                           *:*

4.13 zabbix服务端web界面安装与配置

[root@zabbix-server system]# cd /usr/src/zabbix-6.2.2
[root@zabbix-server zabbix-6.2.2]# cp -a ui/* /var/www/html/zabbix.example.com/
cp:是否覆盖'/var/www/html/zabbix.example.com/index.php'yes

#修改所属组
[root@zabbix-server zabbix-6.2.2]# ll /var/www/
总用量 0
drwxr-xr-x. 2 root root  6  722 19:43 cgi-bin
drwxr-xr-x. 3 root root 32 126 15:47 html
[root@zabbix-server zabbix-6.2.2]# chown -R apache:apache /var/www/html/
[root@zabbix-server zabbix-6.2.2]# ll /var/www/
总用量 0
drwxr-xr-x. 2 root   root    6  722 19:43 cgi-bin
drwxr-xr-x. 3 apache apache 32 126 15:47 html
[root@zabbix-server zabbix-6.2.2]# ll /var/www/html/
总用量 4
drwxr-xr-x. 13 apache apache 4096 128 15:45 zabbix.example.com

4.14 修改 php.ini 配置文件 并重启

//修改/etc/php.ini的配置并重启php-fpm

sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini

systemctl restart php-fpm

# 安装php页面所需要的依赖包
yum -y install php-bcmath php-gd php-mysqlnd

4.15 中文安装需要的环境

yum -y install glibc-common langpacks-zh_CN.noarch

4.16 测试页面,并登录zabbix

在这里插入图片描述
告警先忽略
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

默认的账号名Admin 密码zabbix
在这里插入图片描述
在这里插入图片描述
本次zabbix-server部署完成

4.17 安装zabbix-agentd服务

[root@zabbix-server zabbix-6.2.2]# cd /usr/lib/zabbix/etc/
[root@zabbix-server etc]# cat zabbix_agentd.conf | grep "^[a-Z]"
PidFile=/usr/lib/zabbix/logs/zabbix_agentd.pid
LogFile=/usr/lib/zabbix/logs/zabbix_agentd.log
Server=192.168.111.137
ListenIP=0.0.0.0
ServerActive=192.168.111.137
Hostname=zabbix-server
Include=/usr/lib/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1

4.18 配置 systemctl 文件使用 systemctl 启动 zabbix-agentd

[root@zabbix-server etc]# cd /usr/lib/systemd/system
[root@zabbix-server system]# cat zabbix_agentd.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

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

[Install]
WantedBy=multi-user.target

[root@zabbix-server system]# systemctl daemon-reload
[root@zabbix-server system]# systemctl start zabbix_agentd.service

[root@zabbix-server etc]# ss -anult
Netid      State       Recv-Q      Send-Q           Local Address:Port              Peer Address:Port      Process
udp        UNCONN      0           0                    127.0.0.1:323                    0.0.0.0:*
udp        UNCONN      0           0                        [::1]:323                       [::]:*
tcp        LISTEN      0           128                    0.0.0.0:22                     0.0.0.0:*
tcp        LISTEN      0           4096                   0.0.0.0:10050                  0.0.0.0:*
tcp        LISTEN      0           4096                   0.0.0.0:10051                  0.0.0.0:*
tcp        LISTEN      0           511                    0.0.0.0:9000                   0.0.0.0:*
tcp        LISTEN      0           511                          *:80                           *:*
tcp        LISTEN      0           128                       [::]:22                        [::]:*
tcp        LISTEN      0           4096                         *:3307                         *:*

4.19 配置服务开机自启

#编写配置文件
[root@localhost ~]# vim /etc/rc.local
#!/bin/bash  #直接在下面添加然后保存
zabbix_server
zabbix_agentd
...

#查看执行的文件然后授予执行权限,然后运行
ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Dec  2  2020 /etc/rc.local -> rc.d/rc.local
chmod +x /etc/rc.d/rc.local 
ll /etc/rc.d/rc.local 
-rwxr-xr-x. 1 root root 502 Sep  4 14:47 /etc/rc.d/rc.local
source /etc/rc.d/rc.local 

或者

systemctl enable --now zabbix_server
systemctl enable --now zabbix_agentd

五、zabbix 页面乱码

上传simlt.ttf文件到zabbix-server

[root@zabbix-server ~]# ll
总用量 9560
-rw-------. 1 root root     819 126 10:24 anaconda-ks.cfg
drwxr-xr-x  3 root root      17 128 12:21 go
-rw-r--r--  1 root root 9223160  420  2016 simlt.ttf

[root@zabbix-server ~]# mv simlt.ttf /var/www/html/zabbix.example.com/assets/fonts/
[root@zabbix-server ~]# cd /var/www/html/zabbix.example.com/assets/fonts/
[root@zabbix-server fonts]# ll
总用量 9748
-rw-r--r-- 1 apache apache  756072  725 16:06 DejaVuSans.ttf
-rw-r--r-- 1 root   root   9223160  420  2016 simlt.ttf

[root@zabbix-server fonts]# chown apache:apache simlt.ttf
[root@zabbix-server fonts]# ll
总用量 9748
-rw-r--r-- 1 apache apache  756072  725 16:06 DejaVuSans.ttf
-rw-r--r-- 1 apache apache 9223160  420  2016 simlt.ttf
[root@zabbix-server fonts]# ln -s /var/www/html/zabbix.example.com/assets/fonts/simlt.ttf /etc/alternatives/zabbix-web-font
[root@zabbix-server fonts]# ln -s /var/www/html/zabbix.example.com/assets/fonts/simlt.ttf /var/www/html/zabbix.example.com/assets/fonts/graphfont.ttf

[root@zabbix-server fonts]# ll
总用量 9748
-rw-r--r-- 1 apache apache  756072  725 16:06 DejaVuSans.ttf
lrwxrwxrwx 1 root   root        55 1213 11:39 graphfont.ttf -> /var/www/html/zabbix.example.com/assets/fonts/simlt.ttf
-rw-r--r-- 1 apache apache 9223160  420  2016 simlt.ttf

[root@zabbix-server fonts]# ll /etc/alternatives/zabbix-web-font
lrwxrwxrwx 1 root root 55 1213 10:45 /etc/alternatives/zabbix-web-font -> /var/www/html/zabbix.example.com/assets/fonts/simlt.ttf

[root@zabbix-server zabbix.example.com]# find / -name "defines.inc.php"
/var/www/html/zabbix.example.com/include/defines.inc.php

[root@zabbix-server zabbix.example.com]# vim /var/www/html/zabbix.example.com/include/defines.inc.php
.......
define('ZBX_FONTPATH',                          realpath('assets/fonts')); // where to search for font (GD > 2.0.18)
#define('ZBX_GRAPH_FONT_NAME',          'DejaVuSans'); // font file name
define('ZBX_GRAPH_FONT_NAME',           'graphfont');
define('ZBX_GRAPH_LEGEND_HEIGHT',       120); // when graph height is less then this value, some legend will not show up

[root@zabbix-server sbin]# systemctl restart httpd
[root@zabbix-server sbin]# systemctl restart php-fpm
[root@zabbix-server sbin]# systemctl restart zabbix_server
[root@zabbix-server sbin]# systemctl restart zabbix_agentd

刷新页面

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值