根据官网文档选择合适的zabbix版本和数据库版本
官方地址: https://www.zabbix.com/cn/download
zabbix6.0尽可能使用mysql8.0及以上版本,否则可能出现数据库版本不匹配等问题。
这里演示使用的系统镜像为rocky linux 8.6
话不多说现在开始
一、关闭防火墙及SELINUX(执行两遍完全关闭)
__set_config() {
firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
sed -i 's,^SELINUX=.*$,SELINUX=disabled,' /etc/selinux/config
}
__set_config
二、设置zabbix国内镜像源(清华大学开源镜像站为例)
按照官方文档来会容易出现连接超时等问题。所以尽量使用国内镜像站
1、进入 cd /etc/yum.repo下,手动创建zabbix.repo
[root@localhost ~]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
清除yum 缓存
dnf clean all
注意:如果想安装6.0以前及更早版本,记得修改yum源中zabbix版本号和系统版本!!!!!
三、安装zabbix部署服务(中间件使用apache)
dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2
提示:如果一起安装服务超时,建议分开安装服务以防止出错!!!
四、安装MySQL 数据库
dnf -y install mysql-server
1、初始化数据库
mysqld --initialize --console
1.1、赋予权限
chown -R mysql:mysql /var/lib/mysql
1.2、启动数据库
systemctl start mysqld
1.3、查看数据库初始化密钥
cat /var/log/mysql/mysqld.log | grep localhost
1.4、登录并修改密码
alter user 'root'@'localhost' identified by 'password';
# mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。
zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix
建议: 此处新创建密码建议和第一次初始化修改的密码保持一致
2、为Zabbix server配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=password
填写数据库密码,并取消注释
五、启动服务
启动Zabbix server和agent2进程
启动Zabbix server和agent2进程,并为它们设置开机自启:
systemctl restart zabbix-server zabbix-agent2 httpd php-fpm
systemctl enable zabbix-server zabbix-agent2 httpd php-fpm
六、连接zabbix前端
连接到新安装的Zabbix前端: http://server_ip_or_name/zabbix