安装
这里选用了如上的配置
1. 安装 Zabbix repository
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
sudo dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.deb
sudo apt update
2. 安装 Zabbix server,Web 前端,agent
apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
3. 创建初始数据库
create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost;
4. 导入初始架构和数据
zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix
5. 配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=password
6. 配置前端 php
编辑配置文件 /etc/zabbix/nginx.conf
# 配置文件中移除如下的注释
listen 80;
server_name example.com;
7. 启动 Zabbix server 和 agent 进程
systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm
systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm
8. 配置 Zabbix
访问对应的 web 管理页,按照提示设置即可。
配置完成之后,登录的默认密码为 Admin
zabbix
监控
监控 mysql
1. 创建模板
或者直接在 /etc/zabbix/zabbix_agentd.d
目录中创建 template_db_mysql.conf
文件,然后输入如下内容:
#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default)
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user='zbx_monitor'
#password='<password>'
#
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
2. 创建监控需要的用户
CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';
GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';
3. 配置
在 /var/lib/zabbix
目录中创建 .my.cnf
文件,文件内容如下:
[client]
user='zbx_monitor'
password='<password>'
监控 nginx
这里使用官方提供的 Nginx by http 的方式,原理是定时拉取 ngx_http_stub_status_module
的数据。
首先确认,nginx 中已经集成这个模块,nginx -V 2>&1 | grep -o with-http_stub_status_module
。
配置请求接口
在 nginx 配置文件中配置即可,这里配置在 /etc/nginx/sites-available/default
中。
location = /basic_status {
stub_status;
allow <IP of your Zabbix server/proxy>;
deny all;
}