# 操作系统:CentOS7
01 配置阿里yum源
在/etc/yum.repos.d目录下面建立一个文件,文件名为ali.repo,下面是配置文件
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
02 配置阿里epel源
# 目录全都在/etc/yum.repos.d目录下
# 安装 epel 配置包
wget https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
# 将 repo 配置中的地址替换为阿里云镜像站地址
sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
# 安装epel.repo文件
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
03 清除和建立缓存
# 清除缓存
yum clean all
# 建立缓存
yum makecache
# 查看可用的软件包
yum repolist
图1 可用软件包
04 Zabbix下载
# Zabbix官网
https://www.zabbix.com/cn
图2 点击Zabbix下载
# Zabbix下载网站
https://www.zabbix.com/cn/download
# 可以直接用这个网站
https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=7&components=server_frontend_agent&db=mysql&ws=apache
图3 选择的内容如图所示
# 注意:在这里我们不使用官方的repo源,而使用阿里的repo
# 阿里Zabbix镜像官网
https://mirrors.aliyun.com/zabbix/?spm=a2c6h.13651104.d-4016.8.39a5352dCmVKS6
图4 选择Zabbix
图5 选择5.0版本
图6 选择RHEL
图7 因为操作系统的版本是7,所以选择7
图8 选择x86_64/
# 创建Zabbix.repo文件(在/etc/yum.repos.d目录下)
[zabbix0]
name=ali zabbix
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/
gpgcheck=0
enabled=1
[zabbix1]
name=ali zabbix frontend
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/
gpgcheck=0
enabled=1
图9 repo文件写法(图片上有一部分被遮挡住了)
# 清除缓存
yum clean all
# 建立缓存
yum makecache
# 查看可用的软件包
yum repolist
图10 比之前多了Zabbix
# 进入到这个网站
https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=7&components=server_frontend_agent&db=mysql&ws=apache
图11 进入网站查看安装步骤
# 安装Zabbix数据库和客户端
yum install -y zabbix-server-mysql zabbix-agent
图12 安装Zabbix主要组件
图13 安装 SCL源
图14 但是安装完SCL源之后使用yum会出现报错
图15 发现多了两个文件
# 修改 /etc/yum.repos.d 目录下的 CentOS-SCLo-scl-rh.repo 文件
# 删除CentOS-SCLo-scl.repo 文件
rm -rf CentOS-SCLo-scl.repo
# 把文件内容全删除,用下面这个替换
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=http://vault.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=1
[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
# 清除缓存
yum clean all
# 建立缓存
yum makecache
# 查看可用的软件包
yum repolist
图16 查看YUM源的时候多了个SCL源
图17 这回安装软件正常了
# 接下来安装Zabbix前端一些组件
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
图18 前端组件安装成功
Make sure you have database server up and running.
# 官网说必须要有数据库并保证数据库的开启
# 这里数据库我们用MariaBD替代
# yum install -y mariadb mariadb-server
# 查看服务是否启动
systemctl status mariadb.service
# 启动服务
systemctl start mariadb.service
图19 启动服务
# 进入到数据库中
mysql -u root
图20 进入到数据库中
# 在数据库执行下列命令
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by '123123';
grant all privileges on zabbix.* to zabbix@localhost;
set global log_bin_trust_function_creators = 1;
quit;
图21 在数据库设置Zabbix数据库
# 导入初始架构和数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
图22 导入初始架构和数据
# 导入数据库后禁用 log_bin_trust_function_creators 选项
# mysql -uroot
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
图23 禁用 log_bin_trust_function_creators 选项
# 编辑 /etc/zabbix/zabbix_server.conf 文件
# 先创建一个备份文件
# cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
# 删除空行和注释行
# sed -i '/^#/d; /^$/d' /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBName=zabbix
DBUser=zabbix
DBUser=zabbix
DBPassword=123123
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
图24 编辑Zabbix配置文件,可以直接复制上面配置文件
# 改成下面这样的
# php_value[date.timezone] = Asia/Shanghai
图25 去掉注释,修改时区
# 启动服务并设置开机自启
# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm zabbix-server.service mariadb.service
# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm zabbix-server.service mariadb.service
# 在浏览器输入
http://本机IP地址/zabbix/
图26 进入到浏览器操作
图27 默认登录用户名和密码,区分大小写
图28 安装成功
图29 设置中文