1. zabbix
1.1 简介
zabbix:服务器监控系统。
zabbix的技术名词
-
模板
-
触发器
-
监控线
-
主机
zabbix的版本划分
tls是长期支持版本,所以我们学习长期支持版本的 zabbix服务。
zabbix的服务模式
zabbix的服务架构是 lamp 即:
liunx apache mysql php
zabbix的服务是 zabbix:server/agent 模式,即 服务端/客户端
zabbix的一些组件
-
zabbix-agent web7
-
zabbix-agent db51
-
zabbix-ui
1.2 zabbix 安装
1.2.1配置yum仓库
https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/
配置yum的repo仓库
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@localhost ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm 获取https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm 警告:/var/tmp/rpm-tmp.nFeos0: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:zabbix-release-4.0-1.el7 ################################# [100%]
[root@localhost yum.repos.d]# pwd /etc/yum.repos.d [root@localhost yum.repos.d]# ls CentOS-Base.repo docker-ce.repo zabbix.repo
-
本地配置zabbix仓库
vim /etc/yum.repos.d/zabbix.repo
[root@localhost yum.repos.d]# cat zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=http://repo.zabbix.com/zabbix/4.0/rhel/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1
1.2.2 安装zabbix-server 服务端 以及组件
-
yum install -y zabbix-server-mysql
以mysql为开发的zabbix的服务端程序 -
yum install -y zabbix-web-mysql
以mysql开发的php的web页面 -
yum install -y zabbix-agent
采集客户端数据的核心数据 -
yum install -y mariadb-server
安装mysql服务端程序
yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server
1.2.3 启动 mysql 并进行初始化数据
systemctl start mariadb # 启动 systemctl status mariadb # 查看服务状态 systemctl enable mariadb # 设置开机启动
[root@localhost ~]# systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: inactive (dead) [root@localhost ~]# systemctl start mariadb [root@localhost ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@localhost ~]# systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since 二 2025-07-22 11:43:24 CST; 8s ago Main PID: 8544 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─8544 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─8710 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.... 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: MySQL manual for more instructions. 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: Please report any problems at http://mariadb.org/jira 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: The latest information about MariaDB is available at http://mariadb.org/. 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: You can find additional information about the MySQL part at: 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: http://dev.mysql.com 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: Consider joining MariaDB's strong and vibrant community: 7月 22 11:43:22 localhost.localdomain mariadb-prepare-db-dir[8455]: https://mariadb.org/get-involved/ 7月 22 11:43:22 localhost.localdomain mysqld_safe[8544]: 250722 11:43:22 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 7月 22 11:43:22 localhost.localdomain mysqld_safe[8544]: 250722 11:43:22 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 7月 22 11:43:24 localhost.localdomain systemd[1]: Started MariaDB database server.
mariadb数据库,启动后,默认是无密码的。我们可以通过mysqladmin 去设置密码
mysqladmin password aidong # 设置密码为 aidong
验证登录方式
mysql -uroot -paidong # 注意中间不要加空格 -p后面直接输入密码
创建数据库 zabbix
mysql -uroot -paidong -e 'CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;'
[root@localhost ~]# mysql -uroot -paidong -e 'CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;' [root@localhost ~]# mysql -uroot -paidong -e 'show databases ;' +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | zabbix | +--------------------+
创建用户 zabbix
授权 zabbix用户可以访问 zabbix数据库
CREATE USER 'zabbix'@'%' IDENTIFIED BY 'zabbix'; GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%'; FLUSH PRIVILEGES;
[root@localhost ~]# mysql -uroot -paidong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 19 Server version: 5.5.68-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE USER 'zabbix'@'%' IDENTIFIED BY 'zabbix'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
导入zabbix服务需要的数据库内容
yum下载的的zabbix所需要的数据库文件再 /usr/share/doc/zabbix-server-mysql-xxx
目录下
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.50/ [root@localhost zabbix-server-mysql-4.0.50]# ls AUTHORS ChangeLog COPYING create.sql.gz NEWS README [root@localhost zabbix-server-mysql-4.0.50]# pwd /usr/share/doc/zabbix-server-mysql-4.0.50
zcat create.sql.gz | mysql -uroot -paidong zabbix
[root@localhost zabbix-server-mysql-4.0.50]# zcat create.sql.gz | mysql -uroot -paidong zabbix [root@localhost zabbix-server-mysql-4.0.50]# mysql -uroot -paidong Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 21 Server version: 5.5.68-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use zabbix ; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [zabbix]> show tables ; +----------------------------+ | Tables_in_zabbix | +----------------------------+ | acknowledges | | actions | | alerts | | application_discovery | | application_prototype |
看到zabbix数据库中有多张表,即导入成功
1.3.4 配置zabbix-server 服务
vim /etc/zabbix/zabbix_server.conf
修改zabbix-server的配置,进行配置
LogFile=/var/log/zabbix/zabbix_server.log # 日志配置 LogFileSize=0 # 日志轮转配置,为0 则不轮转,1 则1mb 轮转一次 PidFile=/var/run/zabbix/zabbix_server.pid # 服务pid存放位置 SocketDir=/var/run/zabbix # socket配置 DBName=zabbix # 数据库名称 DBUser=zabbix # 数据库用户 DBPassword=aidong # 数据库密码 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log #snmp 日志信息 Timeout=4 # 超时时间 #定义 告警脚本(Alert Scripts) 的存储目录。 #当触发器(Trigger)触发告警时,Zabbix Server 会执行该目录下的脚本(如发送邮件、短信、微信通知等)。 AlertScriptsPath=/usr/lib/zabbix/alertscripts #定义 外部检查脚本(External Checks) 的存储目录。 #用于 Zabbix Server 主动执行的监控脚本(如自定义采集逻辑)。 ExternalScripts=/usr/lib/zabbix/externalscripts LogSlowQueries=3000 # 记录慢sql查询
我们一般只修改 DBxx即可,修改数据库连接信息
关闭seliunx 否则会出现创建 socket目录无权限问题
临时禁用
sudo setenforce 0 # 将SELinux切换到Permissive模式(只记录不拦截) sudo getenforce # 检查状态,应显示"Permissive"
# 1. 修改配置文件 sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config # 2. 重启系统生效 sudo reboot # 3. 验证(重启后) sestatus # 应显示 "SELinux status: disabled"
启动
[root@localhost system]# systemctl start zabbix-server [root@localhost system]# systemctl status zabbix-server ● zabbix-server.service - Zabbix Server Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled; vendor preset: disabled) Active: active (running) since 二 2025-07-22 13:05:11 CST; 4min 18s ago Process: 39899 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=0/SUCCESS) Process: 39903 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 39905 (zabbix_server) CGroup: /system.slice/zabbix-server.service ├─39905 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf ├─39910 /usr/sbin/zabbix_server: configuration syncer [synced configuration in 0.006355 sec, idle 60 sec] ├─39913 /usr/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.008544 sec during 5.008702 sec] ├─39914 /usr/sbin/zabbix_server: alerter #1 started ├─39915 /usr/sbin/zabbix_server: alerter #2 started ├─39917 /usr/sbin/zabbix_server: alerter #3 started ├─39918 /usr/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 2 values, idle 5.977903 sec during 5.978023 sec] ├─39919 /usr/sbin/zabbix_server: preprocessing worker #1 started ├─39920 /usr/sbin/zabbix_server: preprocessing worker #2 started ├─39921 /usr/sbin/zabbix_server: preprocessing worker #3 started
1.3.5 配置zabbix前端
vim /etc/httpd/conf.d/zabbix.conf
Alias /zabbix /usr/share/zabbix <Directory "/usr/share/zabbix"> Options FollowSymLinks AllowOverride None Require all granted <IfModule mod_php5.c> php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value max_input_vars 10000 php_value always_populate_raw_post_data -1 php_value date.timezone Asia/shanghai </IfModule> </Directory> <Directory "/usr/share/zabbix/conf"> Require all denied </Directory> <Directory "/usr/share/zabbix/app"> Require all denied </Directory> <Directory "/usr/share/zabbix/include"> Require all denied </Directory> <Directory "/usr/share/zabbix/local"> Require all denied </Directory>
我们只需修改时区为中国即可,其他无需修改
启动
[root@localhost conf.d]# systemctl start httpd [root@localhost conf.d]# ss -tnlpu | grep 80 tcp LISTEN 0 128 [::]:80 [::]:* users:(("httpd",pid=57791,fd=4),("httpd",pid=57790,fd=4),("httpd",pid=57789,fd=4),("httpd",pid=57788,fd=4),("httpd",pid=57787,fd=4),("httpd",pid=57785,fd=4))
遇到小坑:
/etc/zabbix/web # 此目录必须给到 apache用户权限,否则无法访问前端页面
[root@localhost web]# ll 总用量 8 -rw-r--r--. 1 apache apache 1036 10月 30 2023 maintenance.inc.php -rw-------. 1 apache apache 429 7月 22 14:15 zabbix.conf.php
进行访问
http:ip:prot/zabbix
进行检查,需要都ok才可以下一步
设置数据库地址
设置本机信息
一直下一不到登录页面.
默认账号密码
Admin zabbix
1.3.6 进入页面配置中文

1.3.7 配置zabbix的图形文字
yum install -y wqy-microhei-fonts -y # 下载好文字在 [root@localhost wqy-microhei]# ls /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/wqy-microhei/wqy-microhei.ttc # 进行覆盖给zabbix [root@localhost wqy-microhei]# cp /usr/share/fonts//wqy-microhei/wqy-microhei.ttc /usr/share/zabbix/assets/fonts/graphfont.ttf cp:是否覆盖"/usr/share/zabbix/assets/fonts/graphfont.ttf"? y