文章目录
一、环境要求
Centos 7.8
PHP 7.2 (从Zabbix 5.0开始)
MariaDB或者Mysql5.7版本以上
更新 Centos7:
yum update
二、关闭防火墙和 selinux 并重启
1、sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
2、systemctl disable --now firewalld
3、reboot
代码如下(示例):
三.安装 Zabbix rpm 源使用阿里云 Zabbix 源
代码如下(示例):
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum clean all
四.安装 zabbix server 和 agent
yum install zabbix-server-mysql zabbix-agent -y
五.安装 Software Collections
yum install centos-release-scl -y
启用 zabbix 前端源,修改vi /etc/yum.repos.d/zabbix.repo,将[zabbix-frontend]下的 enabled 改为 1
六.安装 zabbix 前端和相关环境
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
七.数据库安装
yum install mariadb-server -y
1、启动数据库,并配置开机自动启动
systemctl enable --now mariadb
2、使用以下命令初始化 mariadb 并配置 root 密码
mysql_secure_installation
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, 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 MariaDB
root user without the proper authorisation.
Set root password? [Y/n]
New password: 设置数据库密码
Re-enter new password: 重新输入密码
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] n
... skipping.
By default, MariaDB 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]
- 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 MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@localhost ~]#
[root@localhost ~]#
3、使用 root 用户进入 mysql
mysql -root -p
4、建立 zabbix 数据库
创建zabbix数据库(中文编码格式)
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
授予zabbix用户 zabbix 数据库的所有权限,密码 zabbix
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbbix';
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
使用以下命令导入 zabbix 数据库,zabbix 数据库用户为 zabbix,密码为 password
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p zabbix
八.修改 Zabbix 配置
修改 zabbix server 配置文件vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的数据库用户和密码
DBHost=localhost 去掉前面的 #
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix 去掉前面的 #输入你配置的密码
DBPort=3306
DBSocket=/var/lib/mysql/mysql.sock
修改 zabbix 的 php 配置文件vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的时区,改成 Asia/Shanghai
php_value[date.timezone] = Asia/Shanghai
启动相关服务,并配置开机自动启动
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
使用浏览器访问http://ip/zabbix 即可访问 zabbix 的 web 页面
默认账号:Admin
默认密码;zabbix