Centos7 搭建 Zabbix 5.0 从零到一


一、环境要求

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
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值