#!/bin/bash
#请确定zabbix的rpm安装包放在/root下
read -ep "请确定zabbix的rpm安装包和字体包放在/root下(yes/no):" ok
if [ $ok = yes ];then
#关闭防火墙及selinux
systemctl stop firewalld.service && setenforce 0
#同步服务器时间
#安装同步时间工具
yum -y install ntpdate &> /dev/null
if [ $? -eq 0 ];then
echo "同步时间工具安装成功,开始同步时间!"
ntpdate pool.ntp.org &> /dev/null
else
echo "同步时间安装失败,请重试!"
fi
#######################################################
#############安装zabbix所需web服务#####################
#安装Apache,PHP,mariadb
yum -y install httpd php php-devel php-mysql php-gd mariadb mariadb-server &> /dev/null
if [ $? -eq 0 ];then
echo "zabbix所需web服务安装成功,开始配置web环境!"
else
echo "zabbix所需web服务安装失败,请重试!"
fi
#启动数据库并授权zabbix用户及创建zabbix所需数据库
systemctl start mariadb
if [ $? -eq 0 ];then
echo "数据库启动成功,开始授权zabbix用户及创建zabbix所需数据库!"
mysql -e "create database zabbix charset utf8;"
mysql -e "grant all on *.* to zabbix@'localhost' identified by 'zabbix';"
mysql -e " flush privileges;"
echo "授权zabbix用户及创建zabbix所需数据库成功!"
else
echo "数据库启动失败,请重试!"
fi
#启动Apache
systemctl start httpd
echo "请测试网页,Apache启动成功!"
#开始安装zabbix
rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm &> /dev/null
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent &> /dev/null
if [ $? -eq 0 ];then
echo "zabbix相关服务安装成功,开始配置zabbix"
#导入数据库
echo "开始导入数据库"
cd /usr/share/doc/zabbix-server-mysql-3.4.15/
zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
if [ $? -eq 0 ];then
echo "数据库导入成功!"
else
echo "数据库导入失败,请重试!"
fi
#修改zabbix配置文件
echo "开始修改zabbix配置文件"
sed -i '91s/#//' /etc/zabbix/zabbix_server.conf
sed -i '124c DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
#修改时区
echo "开始修改时区"
sed -i '1a date.timezone = Asia/Shanghai' /etc/php.ini
#zabbix乱码修改
cp /root/simkai.ttf /usr/share/zabbix/fonts/
sed -i "54c define('ZBX_GRAPH_FONT_NAME', 'simkai');" /usr/share/zabbix/include/defines.inc.php
echo "字体修改成功"
#zabbix安装成功,重启Apache
systemctl restart httpd
if [ $? -eq 0 ];then
echo "Apache重启成功,zabbix已部署成功,开始启动zabbix-server"
systemctl start zabbix-server
echo "访问本机IP测试!"
else
echo "Apache重启失败,请重试!"
fi
else
echo "zabbix相关服务安装失败,请重试!"
fi
else
echo "请传入zabbix的rpm安装包!"
fi
zabbix 脚本安装
最新推荐文章于 2023-02-20 17:51:35 发布