Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
Zabbix能监视各种网络参数,保证服务器系统的安全运营。并提供灵活的通知机制以让系统管理员快速定位、解决存在的各种问题。
首先配置Zabbix监控服务器端,需要能够上公网的环境

关闭SELINUX,配置好防火墙或者关闭防火墙

RPM安装LAMP,启动HTTPD
yum install -y httpd mysql mariadb-server php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash wget net-tools

vi /etc/httpd/conf/httpd.conf
     DirectoryIndex index.html index.php    //修改

vi /etc/php.ini
     date.timezone = PRC                 //修改为中国时区

systemctl start mariadb.service && systemctl enable mariadb.service  //启动mariadb服务

~~~~
#####初始化mysql数据库,并配置root用户密码

mysql_secure_installation

![这里直接回车](https://upload-images.jianshu.io/upload_images/16668695-3b3ff4daaae11207.gif?imageMogr2/auto-orient/strip)

![输入Y回车,设置root用户的密码](https://upload-images.jianshu.io/upload_images/16668695-217460f52b648279.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![其余选项N回车基本可以,出现All done这几句话设置完成](https://upload-images.jianshu.io/upload_images/16668695-21e560143dd2b391.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

#####创建zabbix数据库

mysql -u root -p                               //root用户登陆数据库
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;        //创建zabbix数据库(中文编码格式)
MariaDB [(none)]> GRANT all privileges on zabbix.* to zabbix@localhost identified by 'admin123';  //授予zabbix用户zabbix数据库的所有权限,密码admin123
MariaDB [(none)]> flush privileges;          //刷新权限
MariaDB [(none)]> quit                     //退出数据库        


#####开始部署Zabbix

yum install -y php-mbstring php-bcmath

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm
sed -i 's/repo.zabbix.com/mirrors.aliyun.com/zabbix/g' /etc/yum.repos.d/zabbix.repo
yum clean all

yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent

如果使用官方源,此处可能会出现如图的错误:![](https://upload-images.jianshu.io/upload_images/16668695-ee9bf69b14991876.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

可能是因为国际链路和国家防火墙的问题导致下载失败,我们可以手动把zabbix源修改到国内清华大学镜像站```vi /etc/yum.repos.d/zabbix.repo```,如图修改![](https://upload-images.jianshu.io/upload_images/16668695-dd95b0589989084d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.2/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://repo.zabbix.com/zabbix/4.2/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1

修改完毕后再次执行:```yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent```

#####导入数据库并修改Zabbix配置文件

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql zabbix -uzabbix -padmin123

以上为导入数据到数据库zabbix中,密码是用户zabbix数据库登陆密码admin123

vi  /etc/zabbix/zabbix_server.conf

DBPassword=admin123    //修改DB的密码为设置的admin123

配置数据库用户及密码,修改完后```grep -n '^'[A-Z] /etc/zabbix/zabbix_server.conf ```查看一下是否修改正确:![egrep -v '^#|^$'  /etc/zabbix/zabbix_server.conf](https://upload-images.jianshu.io/upload_images/16668695-76870be2881aee82.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#####修改Zabbix时区

vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai


#####启动 Zabbix 相关服务,并设置开机自启动

systemctl enable zabbix-server zabbix-agent httpd
systemctl start zabbix-server zabbix-agent httpd


#####浏览器打开Zabbix WEB界面
访问http://192.168.168.166/zabbix/          (IE浏览器打不开,最好用火狐或者谷歌等浏览器)
![](https://upload-images.jianshu.io/upload_images/16668695-060fa39b57ec6afa.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![](https://upload-images.jianshu.io/upload_images/16668695-da96bc12bf15b194.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![已经翻译了,设置数据库](https://upload-images.jianshu.io/upload_images/16668695-92c4fa5c1244e118.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

--------
#####附:一键安装脚本

!/bin/bash

检查操作系统版本,该脚本只能运行在 Centos 7.x 系统上

cat /etc/redhat-release |grep -i centos |grep '7.[[:digit:]]' >/dev/null
if [[ $? != 0 ]]
then

echo -e "不支持的操作系统,该脚本只适用于CentOS 7.x  x86_64 操作系统"
exit 1

fi

配置无人值守的安装,定义安装过程中需要用到的一些信息

DBPassword=admin123
CacheSize=256M
ZBX_SERVER_NAME=Zabbix-Server
http_port=80

配置 Zabbix 防火墙

firewall-cmd --permanent --zone=public --add-port=10051/tcp
firewall-cmd --permanent --zone=public --add-port=162/udp
firewall-cmd --permanent --zone=public --add-port=$http_port/tcp
firewall-cmd --reload

禁用服务器 SELinux

etenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux

配置 Zabbix 4.2 YUM 源

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm
sed -i 's/repo.zabbix.com/mirrors.aliyun.com/zabbix/g' /etc/yum.repos.d/zabbix.repo
yum clean all

安装 Zabbix 4.2 Server、Web、Agent、DB

yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent mysql mariadb-server wget

配置 Zabbix 数据库(创建账号,并导入zabbix库结构)

systemctl enable mariadb.service
systemctl start mariadb.service
mysql -e "create database zabbix character set utf8 collate utf8_bin;"
mysql -e "grant all privileges on zabbix.* to zabbix@localhost identified by '$DBPassword';"
mysql -e "flush privileges;"
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql zabbix

配置 Zabbix Web Server

sed -i 's/# php_value date.timezone Europe/Riga/php_value date.timezone Asia/Shanghai/' /etc/httpd/conf.d/zabbix.conf
sed -i 's/Listen 80/Listen '$http_port'/' /etc/httpd/conf/httpd.conf
cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php
sed -i "10c $DB[\"PASSWORD\"] = '$DBPassword';" /etc/zabbix/web/zabbix.conf.php
sed -i "16c $ZBX_SERVER_NAME = '$ZBX_SERVER_NAME';" /etc/zabbix/web/zabbix.conf.php

配置 Zabbix Server

sed -i "/^# DBPassword=/a DBPassword=$DBPassword" /etc/zabbix/zabbix_server.conf
sed -i "/^# CacheSize=8M/a CacheSize=$CacheSize" /etc/zabbix/zabbix_server.conf
sed -i "/^# StartPingers=1/a StartPingers=10" /etc/zabbix/zabbix_server.conf

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

systemctl enable zabbix-server zabbix-agent httpd
systemctl start zabbix-server zabbix-agent httpd

安装成功,提示访问方式

echo -e "\n您可以通过以下地址来访问 Zabbix Web Page\n"
for i in ip a | grep 'inet ' | awk 'print $2}' ( awk -F '/' '{print $1) ' ; do echo -e "\thttp://$i:$http_port/zabbix" ; done
echo -e "\n默认账号:Admin 密码:zabbix\n"