菜鸟一枚,按照教程全网最新zabbix5教程(超哥带你学linux系列)_哔哩哔哩_bilibili执行的,已成功搭建Zabbix5.0。
阿里云镜像为CentOS7.6。
公网IP为120.76.xx.xx,
内网IP为172.22.xx.xx(实际上内网IP可以被认为在多个实例下才具备使用意义)
Zabbix版本及系统版本如下:
Zabbix版本:5.0 LTS
OS分布及版本:CentOS7.6
数据库:MySQL(实际未安装MySQL,用的是Mariadb)
Web Server:Apache
[root@izuminoa ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
//关闭selinux(永久关闭)(需要Reboot)
[root@izuminoa ~]# systemctl stop firewalld
[root@izuminoa ~]# systemctl disable firewalld
//关闭防火墙并禁止开机自启
[root@izuminoa ~]# getenforce
Disabled
//查看selinux状态(该命令可以不执行)
[root@izuminoa ~]# systemctl status firewalld
Active: inactive (dead)
//查看防火墙运行状态(该命令可以不执行)
[root@izuminoa ~]# iptables -L
Chain INPUT (policy ACCEPT)
Chain FORWARD (policy ACCEPT)
Chain OUTPUT (policy ACCEPT
//查看当前的iptables规则,均为ACCEPT(该命令可以不执行)
[root@izuminoa ~]# free -m
//查看当前内存占用情况(该命令可以不执行)
获取Zabbix下载源(官方源)
[root@izuminoa ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@izuminoa ~]# ls /etc/yum.repos.d/
//可以看到zabbix.repo(该命令可以不执行)
[root@izuminoa ~]# yum clean all
//清空缓存
安装Zabbix服务器及代理
[root@localhost ~]# yum install zabbix-server-mysql zabbix-agent -y
安装SCL
[root@izuminoa ~]# yum install centos-release-scl -y
//SCL是一个Linux平台的软件多版本共存解决方案
修改Zabbix-frontend前端
[root@izuminoa ~]# vim /etc/yum.repos.d/zabbix.repo
-----
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1 //此处将0改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
安装Zabbix前端环境
[root@izuminoa ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
安装数据库Mariadb
[root@izuminoa ~]# yum install mariadb-server -y
//Mariadb可兼容MySQL
[root@izuminoa ~]# systemctl enable --now mariadb
//配置Mariadb服务开机自启
[root@izuminoa ~]# systemctl status mariadb
//查看Mariadb服务状态(该命令可以不执行)
[root@izuminoa ~]# netstat -tunlp
//查看3306端口(该命令可以不执行)
初始化数据库
[root@izuminoa ~]# mysql_secure_installation
Set root password? [Y/n] y
//设置root密码******
Remove anonymous users? [Y/n] y
//移除匿名用户
Disallow root login remotely? [Y/n] n
//不禁止用户远程登录
Remove test database and access to it? [Y/n]y
//是否移除默认数据库y
Reload privilege tables now? [Y/n] y
//是否刷新数据表
添加数据库用户以及Zabbix所需的数据库信息
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
//设置zabbix数据库及编码
MariaDB [(none)]> create user zabbix@localhost identified by '******';
Query OK, 0 rows affected (0.00 sec)
//创建一个zabbix用户,账户为"zabbix",允许本机登录,密码为******。
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)
//授予该用户所有权限
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
//刷新授权表
MariaDB [(none)]> exit;
Bye
//退出
导入数据库信息
[root@izuminoa ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
//使用zcat命令读取create.sql.gz的内容然后导入至数据库中。
(mysql -u用户名 -p数据库名)
修改Zabbix配置文件,修改数据库密码
[root@izuminoa ~]# mysql -uzabbix -p******
//进入后show databases;可以看到zabbix数据库
MariaDB [(none)]> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]>
//切换用户
MariaDB [zabbix]> show tables;
166 rows in set (0.00 sec)
//查看导入是否成功(该命令可以不执行)
MariaDB [zabbix]> exit;
Bye
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
DBUser=zabbix
### Option: DBPassword
# Database password.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=****** //在此处修改密码
[root@izuminoa ~]# grep 'DBPassword' /etc/zabbix/zabbix_server.conf
### Option: DBPassword
# DBPassword=******
//查看修改是否成功(该命令可以不执行)
修改Zabbix的php配置文件
[root@izuminoa ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
-----
;php_value[date.timezone] = Europe/Riga
改为
php_value[date.timezone] = Asia/Shanghai(记得去掉前边的分号)
//修改时区
[root@izuminoa ~]# grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
//查看修改是否成功(该命令可以不执行)
启动Zabbix相关服务器
[root@izuminoa ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@izuminoa ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
web界面输入120.76.xx.xx/zabbix 艹 走 忽略!
至此,基本的安装就完成了(虽然在本文中省略了许多坎坷的过程……) ,希望能够帮到大家。
(这位就是izuminoa)