1.添加zabbix仓库
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.0+ubuntu22.04_all.deb dpkg -i zabbix-release_latest_7.0+ubuntu22.04_all.deb apt update2.安装Zabbix相关软件包
apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent3.安装MySQL
apt install -y mysql-server-8.0 root@master:~# netstat -tnulp | grep 3306 tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 28248/mysqld tcp 0 0 127.0.0.1:33060 0.0.0.0:* LISTEN 28248/mysqld 这个是错的 在网页登陆zabbix一直登陆失败 MySQL 只监听在 127.0.0.1:3306(本地回环地址),而 Zabbix 配置的连接地址是 192.168.146.10(远程地址)。这是Zabbix安装过程中的数据库连接错误。核心问题是无法连接到MySQL数据库。
修改方法:vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到并修改: bind-address = 0.0.0.0 # 改为0.0.0.0允许所有IP连接 # 或 bind-address = 192.168.146.10 # 指定IP也可以这样就可以了
4.创建初始化数据库
mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 8.0.44-0ubuntu0.22.04.2 (Ubuntu) Copyright (c) 2000, 2025, 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> CREATE USER 'zabbix'@'%' IDENTIFIED BY 'root123'; Query OK, 0 rows affected (0.06 sec) mysql> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%'; Query OK, 0 rows affected (0.02 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye导入初始架构和数据,系统将提示您输入新创建的密码
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix Enter password: 我创建的密码是root123 输入的时候不显示 root@master:~# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.44-0ubuntu0.22.04.2 (Ubuntu) Copyright (c) 2000, 2025, 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> set global log_bin_trust_function_creators = 0; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> quit; Bye5.为zabbix server配置数据库
egrep '^DBHost|^DBName|^DBUser|^DBPassword' /etc/zabbix/zabbix_server.conf DBHost=192.168.146.10 DBName=zabbix DBUser=zabbix DBPassword=zabbix DBName=zabbix DBUser=zabbix6.为Zabbix前端配置PHP
cat /etc/zabbix/nginx.conf server { listen 8080; server_name 192.168.146.10; ......7.启动Zabbix server和agent进程
systemctl restart zabbix-server zabbix-agent nginx php8.1-fpm8.用192.168.146.10:8080访问zabbix
#列出所有已安装的语言 locale -a C C.utf8 en_AG sed -n '/zh_CN.UTF-8 UTF-8/p' /etc/locale.gen #zh_CN.UTF-8 UTF-8 sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen sed -n '/zh_CN.UTF-8 UTF-8/p' /etc/locale.gen #zh_CN.UTF-8 UTF-8 locale-gen systemctl restart zabbix-server zabbix-agent nginx php8.1-fpm换成中文:
9.web界面安装zabbix
10.访问web界面
192.168.146.10:8080
账号:Admin
密码:zabbix
监控主机
1.在需要监控的主机上安装zabbix-agent
apt -y install zabbix-agent2.修改zabbix-agent的配置文件
vim /etc/zabbix/zabbix_agentd.conf 找到并修改: Server=192.168.146.103.重启zabbix-agent服务
systemctl restart zabbix-agent.service4.添加成功