安装部署 zabbix5.0

# 设置环境变量和参数

export LANG=en_US.utf8

sed -i '1a export LANG=en_US.utf8' /etc/bashrc

IP=$(ip -4 a |grep ens33 |grep inet |awk '{print $2}' |cut -d/ -f1)

部署环境如下:

IP:192.168.121.30

系统:CentOS7.7 

web:Nginx

php version:7.2

数据库:mariadb5.5

部署 zabbix 过程如下:

# 1. 关闭防火墙

systemctl disable firewalld --now

# 2. 设置 SELinux

vim 编辑 /etc/selinux/config 文件将 SELinux 类型改为 disabled 模式并重启生效

sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

setenforce 0

# 3. 从 zabbix 官网下载 zabbix 的源

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

# 4. 修改 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

# 5. 配置前端源,并安装下载依赖

yum -y install centos-release-scl

# 6. 安装 server 服务
yum -y install zabbix-server-mysql

# 7. 安装前端组件
yum -y install zabbix-web-mysql-scl zabbix-nginx-conf-scl

# 8. 安装并启动 mariadb 数据库

yum -y install mariadb-server

systemctl enable mariadb --now

# 9. 进入 mariadb 并创建 zabbix 业务库、给 zabbix 用户授权(mysql_secure_installation 命令给数据库初始化并给 root 数据库账号设置密码)

使用 mysql 命令进入数据库 shell 后输入以下命令

create database zabbix character set utf8 collate utf8_bin;

grant all on zabbix.* to zabbix@'%' identified by 'zabbix';

flush privileges;

可以将以上命令写至文件中作为 mysql 命令的输入

即为:

cat >zabbix-sql.txt <<EOF

create database zabbix character set utf8 collate utf8_bin;

grant all on zabbix.* to zabbix@'%' identified by 'zabbix';

flush privileges;

exit

EOF

mysql <zabbix-sql.txt

# 10. 导入业务到 zabbix 库

path1=`rpm -ql zabbix-server-mysql |grep create.sql.gz`

zcat $path1 |mysql zabbix

# 11. 查看并配置 zabbix_server 连接数据库(zabbix_server.conf 配置文件中必须要有 DBName、DBUser、DBPassword 参数)

target2=`egrep -v "^#|^$" /etc/zabbix/zabbix_server.conf -n |grep DBUser |cut -d: -f1`

sed -i "${target2}a DBPassword=zabbix" /etc/zabbix/zabbix_server.conf

# 12. 修改 zabbix-nginx 相关配置文件(将 server_name 后面改为本机 IP)

path2=`rpm -ql zabbix-nginx-conf-scl`

sed -i "2,3s/#//; s/example.com/$IP/" $path2

# 13. 配置 php(将 listen.acl_users=apache 后面加上 nginx,并把时区改为亚洲上海)

path3=`find /etc -name zabbix.conf |grep php`

target3=`grep -n "^listen.acl.users" $path3 |cut -d: -f1`

target4=`grep -n "timezone" path3 |cut -d: -f1`

sed -i -e "${target3}s/apache/apache,nginx/" -e "${target}s/; //" -e "${target4}s#=.*#= Asia/Shanghai#" $path3

# 14. 重启服务并设置开机启动

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 页面,如下图所示:

 

posted @ 2021-11-29 18:55  demoduan  阅读(574)  评论(0)    收藏  举报