部署环境如下:
主机IP:192.168.121.30
系统:此文章以CentOS7.7为例
web应用:Nginx
进程:php7.2
数据库:mariadb5.5
部署zabbix过程如下:
1.检查并关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
2.设置SELinux
即使用vim编辑/etc/selinux/config文件将SELinux类型改为disabled模式并重启生效
脚本格式为:
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
3.安装nginx,但centos的yum源里默认没有nginx的二进制包,因此需要先安装epel-release,即fedora的yum源,fedora的源被誉为最全最完善的yum源
yum -y install epel-release
yum -y install nginx
安装后启动并设置下次开机启动systemctl start nginx && systemctl enable nginx
可以使用nginx -v查看安装后的nginx版本
4.从zabbix官网下载zabbix的源
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
5.修改zabbix源,使其前端仓库开机自启
即使用vim编辑器将/etc/yum.repos.d/zabbix.repo中的zabbix-frontend前端的源改为开机自启
脚本格式为:
target1=`cat -n /etc/yum.repos.d/zabbix.repo | grep -A5 "zabbix-frontend" |grep "enabled" | awk '{print $1}'`
sed -i "${target1}s/0/1/" /etc/yum.repos.d/zabbix.repo
6.配置前端源,并安装下载依赖
yum -y install centos-release-scl
7.安装server服务
yum -y install zabbix-server-mysql
8.安装前端组件
yum -y install install zabbix-web-mysql-scl zabbix-nginx-conf-scl
9.安装并启动mariadb数据库
yum -y install mariadb-server
systemctl start mariadb && systemctl enable mariadb
10.使用mysql命令进入mariadb并创建zabbix业务库、给zabbix用户授权
create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
可以将以上命令写至文件中作为mysql命令的输入
即为:
cat >zabbix.txt <<EOF
create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
exit
EOF
mysql <zabbix.txt
rm -f zabbix.txt
11.导入业务到zabbix库
path1=`rpm -ql zabbix-server-mysql |grep create.sql.gz`
zcat $path1 |mysql zabbix
12.查看并配置zabbix_server连接数据库
egrep -v "^#|^$" /etc/zabbix/zabbix_server.conf
echo 'DBPassword=zabbix' >>/etc/zabbix/zabbix_server.conf
13.查看zabbix-nginx相关配置文件
path2=`rpm -ql zabbix-nginx-conf-scl`
sed -i 's/#//; s/example.com/192.168.121.30/' $path2
14.配置php
path3=`find /etc -name zabbix.conf |grep php`
target2=`grep "^listen.acl_users" $path3 -n |cut -d: -f1`
target3=`grep "timezone" -n $path3 |cut -d: -f1`
sed -i "${target2}s/apache/apache,nginx/" $path3
sed -i "${target3}s/; //" $path3
sed -i "${target3}s#=.*#= Asia/Shanghai#" $path3
15.重启服务并设置开机启动
systemctl restart zabbix-server rh-nginx116-nginx.service rh-php72-php-fpm.service
systemctl enable zabbix-server rh-nginx116-nginx.service rh-php72-php-fpm.service
执行成功后即可使用IP地址访问搭建好的zabbix页面,如下图所示: