欢迎光临范阳布衣的运维博客
分享工作和学习中的知识、技术

YUM快速部署Zabbix 5.0

YUM快速部署Zabbix 5.0 LTS-CentOS 7.6

CentOS 7.6 [最小化安装] 部署Zabbix 5.0 LTS

zabbix 5.0 版本于 5 月 11 日正式发布,是最新的 LTS(长期支持)版本,5.0 带来很多功能和特性.
详见官网文档:
https://www.zabbix.com/documentation/current/manual/installation/requirements

1.关闭防火墙和 selinux 并重启

[root@zabbix ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@zabbix ~]# systemctl disable --now firewalld
[root@zabbix ~]# reboot

2.安装 zabbix rpm 源

[root@zabbix ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@zabbix ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo #鉴于国内网络情况,使用阿里云 zabbix 源
[root@zabbix ~]# yum clean all

3.安装 zabbix server 和 agent

[root@zabbix ~]# yum install zabbix-server-mysql zabbix-agent -y
[root@zabbix ~]#yum install centos-release-scl -y

启用 zabbix 前端源,将[zabbix-frontend]下的 enabled 改为 1
修改/etc/yum.repos.d/zabbix.repo

[root@zabbix ~]# vim /etc/yum.repos.d/zabbix.repo

[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

安装 zabbix 前端和相关环境

[root@zabbix ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

4.使用 yum 安装 centos7 默认的 mariadb 数据库

[root@zabbix ~]# yum install mariadb-server -y    #由于使用 yum 安装 zabbix,不自动依赖安装数据库,因此需要手动安装数据库
[root@zabbix ~]# systemctl enable --now mariadb    #启动数据库,并配置开机自动启动
[root@zabbix ~]# mysql_secure_installation    #初始化 mariadb 并配置 root 密码
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):<–初次运行直接回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n]    #是否设置root用户密码,输入y并回车或直接回车
New password:               #设置root用户的密码
Re-enter new password:      #再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]   #是否删除匿名用户,生产环境建议删除,所以直接回车
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] #是否删除test数据库,直接回车
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] #是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@zabbix ~]# mysql -uroot -p    #使用 root 用户进入 mysql,并建立 zabbix 数据库,注意数据库编码
Enter password:
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> create user zabbix@localhost identified by 'zabbix@123';
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
#MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit

导入 zabbix 数据库,zabbix 数据库用户为 zabbix,密码为zabbix

[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p
Enter password:

Zabbix导入数据库时报错

使用如下命令导入Zabbix数据库时报错

zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p
Enter password: 
ERROR 1046 (3D000) at line 1: No database selected
解决办法:

//1,先把原始的数据库压缩包备份
cp /usr/share/doc/zabbix-server-mysql/create.sql.gz{,.bak}
cd /usr/share/doc/zabbix-server-mysql
//2,解压数据库
gunzip create.sql.gz
//3,安装nano编辑数据库信息
yum -y install nano
nano create.sql
//在第一行加上
USE zabbix;
//然后重新导入库即可
cat create.sql | mysql -uroot -p


修改配置文件zabbix_server.conf里的数据库密码,

/etc/zabbix/zabbix_server.conf

[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf
DBPassword=zabbix@123

5.修改 zabbix 的 php 配置文件里的时区

/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

[root@zabbix ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai

启动相关服务,并配置开机自动启动

[root@zabbix ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@zabbix ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

6浏览器测试访问zabbix 的 web 页面,格式http://ip/zabbix

未经允许不得转载:范阳布衣 » YUM快速部署Zabbix 5.0