#!/bin/bash
#clsn
# 本shell基于centos7.7 1980 zabbix4.4
# 2024/02/23

#安装zabbix源、aliyun YUM源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo &> /dev/null
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm &> /dev/null
yum repolist all &> /dev/null

#安装zabbix 
echo "------------------- 正在安装zabbix-server中... -------------------"
yum install -y mariadb-server zabbix-server-mysql zabbix-web-mysql  &> /dev/null

#安装启动 mariadb数据库
systemctl enable --now mariadb.service &> /dev/null

echo "------------------- 安装zabbix-server完成... -------------------"

#创建数据库
echo "------------------- 正在配置zabbix-server... -------------------"
mysql -e 'create database zabbix charset utf8 collate utf8_bin;'
mysql -e "CREATE USER 'zbuser'@'localhost' IDENTIFIED BY 'redhat';"
mysql -e 'grant all on zabbix.* to 'zbuser'@'localhost';'
mysql -e 'flush privileges;'

#导入数据
zcat /usr/share/doc/zabbix-server-mysql-4.4.10/create.sql.gz | mysql -uzbuser -predhat zabbix

#配置zabbixserver连接mysql
cp -a zabbix_server.conf zabbix_server.conf.bak
sed -ri 's|# DBHost=localhost|DBHost=localhost|' /etc/zabbix/zabbix_server.conf
sed -ri 's|DBUser=zabbix|DBUser=zbuser|' /etc/zabbix/zabbix_server.conf
sed -ri 's|# DBPassword=|DBPassword=redhat|' /etc/zabbix/zabbix_server.conf
sed -ri 's|# DBSocket=|DBSocket=/var/lib/mysql/mysql.sock|' /etc/zabbix/zabbix_server.conf


#添加时区
sed -ri 's|# php_value date.timezone Europe/Riga|php_value date.timezone Asia/Shanghai|' /etc/httpd/conf.d/zabbix.conf

#解决中文乱码:
yum -y install wqy-microhei-fonts
\cp -a /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

#启动服务
echo "------------------- 正在启动zabbix服务... -------------------"
systemctl enable --now zabbix-server.service 
systemctl enable --now httpd
echo "------------------- zabbix-server启动完成... -------------------"

#输出信息
echo "------------------- zabbix-server部署完成!!! -------------------"
echo "请打开浏览器访问以下网址"
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"
分类: Linux 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录