Zabbix 安装与配置
Zabbix 安装与配置
一、Zabbix 简介
Zabbix 是一款开源的企业级分布式监控系统,用于实时监控服务器、网络设备、应用程序等的状态。当设备出现异常(如 CPU 负载过高、磁盘空间不足、服务宕机等)时,Zabbix 能自动触发告警,并通过邮件、短信等方式通知管理员。同时,Zabbix 提供丰富的数据可视化功能,支持图表、仪表盘和报表,便于分析和趋势预测。
Zabbix 主要特性
- 数据采集:支持 Agent、SNMP、IPMI、JMX 等多种方式采集数据。
- 触发与告警:支持自定义触发条件和告警规则,支持多种通知方式。
- 数据存储:使用数据库(如 MySQL、PostgreSQL)存储配置和监控数据。
- 数据展示:提供 Web 界面、图表、地图、仪表盘等可视化功能。
Zabbix 架构组件
组件 | 说明 |
---|---|
Zabbix Server | 核心服务,负责数据处理、告警触发、通知发送 |
Zabbix Database | 存储配置信息与监控数据 |
Zabbix Web | 基于 Web 的管理界面 |
Zabbix Proxy | 可选的代理节点,用于分布式监控和负载分担 |
Zabbix Agent | 部署在被监控主机上,采集本地数据 |
二、安装环境准备
1、系统环境
- 操作系统:Rocky Linux 9(或其他 RHEL 系)
- 主机名:zabbix-server
- IP 地址:192.168.100.100(示例)
2、前置操作
关闭防火墙和 SELinux
安装常用工具和时钟同步服务
yum -y install lrzsz tar net-tools chrony
三、安装 Zabbix
1、安装 Zabbix 源
[root@zabbix-server ~]# rpm -Uvh zabbix-release-7.0-2.el9.noarch.rpm
2、替换为阿里镜像源
编辑 /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rocky/9/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/9/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-08EFA7DD
gpgcheck=1[zabbix-sources]
name=Zabbix Official Repository source code - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rocky/9/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1
3、安装 Zabbix 组件
[root@zabbix-server ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent
四、安装与配置数据库
1、安装 MariaDB
[root@zabbix-server ~]# yum -y install mariadb-server mariadb
[root@zabbix-server ~]# systemctl restart mariadb
[root@zabbix-server ~]# systemctl enable mariadb
2、初始化数据库安全设置
[root@zabbix-server ~]# mysql_secure_installation Switch to unix_socket authentication [Y/n] yYou already have your root account protected, so you can safely answer 'n'.Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!Remove anonymous users? [Y/n] yDisallow root login remotely? [Y/n] nRemove test database and access to it? [Y/n] yReload privilege tables now? [Y/n] yThanks for using MariaDB!
3、创建 Zabbix 数据库与用户
[root@zabbix-server ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.16-MariaDB MariaDB ServerCopyright (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 database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.000 sec)MariaDB [(none)]> create user zabbix@localhost identified by 'wiltjer';
Query OK, 0 rows affected (0.001 sec)MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.001 sec)MariaDB [(none)]> set global log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.000 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)MariaDB [(none)]> exit;
Bye
4、导入 Zabbix 数据库结构
[root@zabbix-server ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
Enter password:
5、关闭函数创建权限
[root@zabbix-server ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.5.16-MariaDB MariaDB ServerCopyright (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)]> set global log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.000 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)MariaDB [(none)]> exit;
Bye
五、配置 Zabbix Server
编辑 /etc/zabbix/zabbix_server.conf
ListenPort=10051
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=wiltjer
DBSocket=/var/lib/mysql/mysql.sock
ListenIP=0.0.0.0
六、配置 Web 前端
1、配置 Nginx
编辑 /etc/nginx/conf.d/zabbix.conf
listen 8080;
server_name 192.168.100.100;
2、启动服务
[root@zabbix-server ~]# systemctl restart zabbix-server.service zabbix-agent.service nginx php-fpm
[root@zabbix-server ~]# systemctl enable zabbix-server.service zabbix-agent.service nginx php-fpm
七、访问 Zabbix Web 安装向导
在浏览器中打开
默认账号为 Admin,密码为 zabbix
http://192.168.100.100:8080/setup.php
八、中文支持
从 Windows 系统复制 simkai.ttf
(楷体)
上传至服务器 /usr/share/zabbix/assets/fonts/
替换默认字体:
[root@zabbix-server ~]# cd /usr/share/zabbix/assets/fonts/
[root@zabbix-server fonts]# mv simkai.ttf graphfont.ttf
mv: overwrite 'graphfont.ttf'? y[root@zabbix-server ~]# systemctl restart zabbix-agent.service
[root@zabbix-server ~]# systemctl enable zabbix-agent.service
九、配置 Zabbix Agent(监控远程主机)
在被监控主机上执行
[root@zabbix-agent yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@zabbix-agent ~]# yum -y install zabbix-agent
编辑 /etc/zabbix/zabbix_agentd.conf
Server=192.168.100.100 # Zabbix Server IP
ServerActive=192.168.100.100
Hostname=zabbix-agent # 在 Zabbix Web 中配置的主机名
重启并启用 Agent
[root@zabbix-agent ~]# systemctl restart zabbix-agent
[root@zabbix-agent ~]# systemctl enable zabbix-agent
十、在 Zabbix Web 中添加主机
1、登录 Zabbix Web
监测 主机 创建主机