安MariaDB
sudo apt-get install apt-transport-https curl
sudo curl -o /etc/apt/trusted.gpg.d/mariadb_release_signing_key.asc 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo sh -c "echo 'deb https://mirrors.aliyun.com/mariadb/repo/10.10/debian buster main' >>/etc/apt/sources.list"
sudo apt-get update
sudo apt-get install mariadb-server
systemctl start mariadb
#如果你的MariaDB是10.4.6以下的版本,输入如下命令
mysql_secure_installation
#如果你的MariaDB是10.5.2以上的版本,输入如下命令
mariadb-secure-installation
#重启数据库
systemctl restart mariadb
#重新授权root用户:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' with grant option;
FLUSH PRIVILEGES;
#删除host为localhost的root用户:----->删除后必须刷新表的权限才生效
delete from mysql.user where host='localhost';
FLUSH PRIVILEGES;
安装配置Zabbix
a. 添加zabbix仓库
wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-4+debian10_all.deb
#官方源很慢,这里使用阿里云镜像
wget https://https://mirrors.aliyun.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-4+debian10_all.deb
dpkg -i zabbix-release_6.0-4+debian10_all.deb
#修改zabbix镜像源
sed -i "s/repo\.zabbix\.com/mirrors\.aliyun\.com\/zabbix/g" /etc/apt/sources.list.d/zabbix.list
sed -i "s/repo\.zabbix\.com/mirrors\.aliyun\.com\/zabbix/g" /etc/apt/sources.list.d/zabbix-agent2-plugins.list
apt update
b. 安装 Zabbix server, frontend, agent
apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent
c. 创建数据库
使用root登录
create database zabbix_proxy character set utf8mb4 collate utf8mb4_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost;
set global log_bin_trust_function_creators = 1;
quit
将Zabbix server初始化数据导入数据库,这里使用的是上面创建的zabbix用户,需要输入zabbix的登录密码
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix_proxy
Disable log_bin_trust_function_creators option after importing database schema,使用root登录.
set global log_bin_trust_function_creators = 0;
quit;
d. Configure the database for Zabbix server
#修改或者添加以下几项,其它按需处理
vi /etc/zabbix/zabbix_server.conf
ListenPort=10051
#ip改为本机ip
SourceIP=172.17.165.75
#密码为mariadb创建的zabbix用户密码
DBPassword=password
DBPort=3306
e. 开启Zabbix server 和agent服务(进程)
systemctl restart zabbix-server zabbix-agent apache2
systemctl enable zabbix-server zabbix-agent apache2
f. 开放防火墙打开浏览器访问输入本机ip/zabbix进行访问
如http://172.17.165.75/zabbix
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
iptables -I INPUT -p tcp --dport 10050 -j ACCEPT
#或者
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --add-port=10050/tcp --permanent
firewall-cmd --reload
配置Agent
1、安装Zabbix Agent
apt install zabbix-agent
2、配置 Zabbix Agent
vi /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
DenyKey=system.run[*]
Server=172.17.165.80
ListenPort=10050
Hostname=prod server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
3、启动 Zabbix Agetn
sudo systemctl start zabbix-agent.service
4、页面添加监控
http://172.17.165.80/zabbix