Zabbix 软件能够监控众多网络参数和服务器的健康度、完整性。Zabbix 使用灵活的告警机制,允许用
户为几乎任何事件配置基于邮件的告警。这样用户可以快速响应服务器问题。Zabbix 基于存储的数据
提供出色的报表和数据可视化功能。这些功能使得 Zabbix 成为容量规划的理想选择。
Zabbix 支持主动轮询(polling)和被动捕获(trapping)。Zabbix所有的报表、统计数据和配置参数
都可以通过基于 Web 的前端页面进行访问。基于 Web 的前端页面确保您可以在任何地方访问您监控的
网络状态和服务器健康状况。适当的配置后,Zabbix 可以在监控 IT 基础设施方面发挥重要作用。无论
是对于有少量服务器的小型组织,还是拥有大量服务器的大企业而言,同样适用。
阿里源
5.0
https://mirrors.aliyun.com/zabbix/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/
6.4
wget https://mirrors.aliyun.com/zabbix/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb
下载上传对应版本
安装
dpkg -i zabbix-release_5.0-2+ubuntu22.04_all.deb
apt list|grep zabbix
dpkg -L zabbix-release #查看包的配置文件
如果是zabbix的源,要替换为阿里的源,但旧版的阿里的源缺少包
sed -i.bak ‘s#repo.zabbix.com#mirrors.aliyun.com/zabbix#’ /etc/apt/sources.list.d/zabbix.list
安装
apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent
官方安装步骤链接
https://www.zabbix.com/cn/download?zabbix=6.4&os_distribution=ubuntu&os_version=22.04&components=server_frontend_agent&db=mysql&ws=apache
配置源
root@server02:~/nginx/nginx-1.24.0# cat /etc/apt/sources.list.d/zabbix.list
# Zabbix main repository
deb https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/ubuntu jammy main
deb-src https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/ubuntu jammy main
apt update
重新安装源先卸载: dpkg --purge zabbix-release
安装Zabbix server,Web前端,agent
apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent
c. 创建初始数据库
# mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by '123456';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
mysql -uroot -p
password
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit
set global log_bin_trust_function_creators = 0; 是一个MySQL服务器的配置选项。当设置为0时,它禁用了对于具有DEFINER权限的存储过程和函数的二进制日志记录。这意味着在进行主从复制时,这些存储过程和函数将不会被复制到从服务器上。这个选项通常用于解决在主从复制中出现的一些权限相关的问题。
不配置在导入会提示:
ERROR 1419 (HY000) at line 2091: You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
为Zabbix server配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=password
启动Zabbix server和agent进程
systemctl restart zabbix-server zabbix-agent apache2
systemctl enable zabbix-server zabbix-agent apache2
安装中文语言包
apt -y install language-pack-zh-hans
systemctl restart apache2
查看端口
root@server02:/etc/zabbix# netstat -antp|grep 10051
访问IP/zabbix
配置后登录
Admin/zabbix
源码编译安装
官方文档https://www.zabbix.com/documentation/6.0/zh/manual/installation/install
apt -y install apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core fping libapache2-mod-php libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libfontconfig1 libgd3 libiksemel3 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libodbc1 libopenipmi0 libsensors5 libsnmp-base libsnmp40 libsodium23 libssh2-1 libtiff5 libwebp7 libxpm4 php-bcmath php-common php-gd php8.1-common php8.1-gd php8.1-ldap php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline libxml2-dev libxml2 snmp libsnmp-dev libevent-dev openjdk-8-jdk libcurl4-openssl-dev php8.1-xml snmpd ssl-cert fonts-dejavu libmysqlclient-dev
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
make -j6 &&sudo make install
root@server01:/usr/local/zabbix/sbin# ln -s /usr/local/zabbix/sbin/* /usr/sbin/
root@server01:/usr/local/zabbix/sbin# ln -s /usr/local/zabbix/bin/* /usr/sbin/
编译找不到,参考https://support.zabbix.com/browse/ZBX-12324
checking for pkg-config... no
configure: error: LIBXML2 library not found
安装pkg-config即可解决:
apt install pkg-config -y
创建数据库
mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by '123456';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
导入数据
cd database/mysql
sudo mysql -u zabbix -p zabbix < schema.sql
sudo mysql -u zabbix -p zabbix < images.sql
sudo mysql -u zabbix -p zabbix < data.sql
修改配置
root@server01:/usr/local/zabbix/etc# grep '^[^#]' zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=120.77.146.92
DBName=zabbix
DBUser=zabbix
DBPassword= 123456
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
StatsAllowedIP=127.0.0.1是MySQL服务器配置文件中的一个选项,它指定了允许访问MySQL统计信息的IP地址。在这种情况下,只有IP地址为127.0.0.1的客户端可以访问MySQL统计信息。
查看日志
tail -f /tmp/zabbix_server.log
580816:20230830:235251.515 [Z3001] connection to database ‘zabbix’ failed: [2002] Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
580816:20230830:235251.515 database is down: reconnecting in 10 seconds
580816:20230830:235301.516 [Z3001] connection to database ‘zabbix’ failed: [2002] Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
zabbix文件指定mysql的socket位置
root@server01:/apps/zabbix/zabbix-6.0.21# find / -name mysql.sock*
/data/mysql/mysql.sock
还是报错
使用socket文件不能用localhost连接,修改zabbix配置文件为本机地址
DBHost=172.29.21.67
root@server01:/usr/local/zabbix/etc# vi zabbix_server.conf
root@server01:/usr/local/zabbix/etc# ps -ef|grep zab
zabbix 580931 1 0 Aug30 ? 00:00:00 zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
root 580986 564313 0 Aug30 pts/3 00:00:00 tail -f /tmp/zabbix_server.log
root 581184 575792 0 00:06 pts/4 00:00:00 grep --color=auto zab
root@server01:/usr/local/zabbix/etc# kill -9 580931
root@server01:/usr/local/zabbix/etc# !zabbix
root@server01:/usr/local/zabbix/etc# netstat -antp |grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 581188/zabbix_serve
root@server01:/usr/local/zabbix/etc# vi zabbix_server.conf
修改后启动成功
root@server01:/usr/local/zabbix/etc# grep '^[^#]' zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=172.29.21.67
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/data/mysql/mysql.sock
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
配置php和初始化登录WEB页面
root@server01:/apps/zabbix/zabbix-6.0.21/ui# cp -a /apps/zabbix/zabbix-6.0.21/ui/* /var/www/html/zabbix/
启动apahe2
修改php配置后重启
systemctl restart apache2
vim /etc/php/8.1/apache2/php.ini
下载配置文件并上传至目录/var/www/html/zabbix/conf/