shell脚步部署--zabbix服务
作者:互联网
#!/bin/bash
echo "关闭防火墙,selinux"
systemctl stop firewalld && setenforce 0 &> /dev/null
echo "同步系统时间"
ntpdate pool.ntp.org
echo "写入阿里yum源"
cat> /etc/yum.repos.d/zabbix_Aliyun.repo<<\EOF
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=0
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0
EOF
echo ""
#安装mysql,zabbix
echo "正在安装mysql和zabbix,请稍候......"
yum -y install mariadb mariadb-server zabbix-server-mysql zabbix-web-mysql zabbix-agent &> /dev/null
rpm -qa|grep mariadb-server &> /dev/null
if [ $? -eq 0 ];then
echo "mysql安装成功"
else
echo "请重新安装mysql"
fi
rpm -qa |grep zabbix &> /dev/null
if [ $? -eq 0 ];then
echo "zabbix安装成功"
else
echo "请重新安装zabbix"
fi
echo "启动mysql,创建用户并授权!"
systemctl start mariadb
if [ $? -eq 0 ];then
echo "mysql已启动,请创建授权用户"
mysql -e "create database zabbix character set utf8 collate utf8_bin"
mysql -e "grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix'"
mysql -e "flush privileges"
else
echo "启动失败,请处理"
fi
echo "导入数据"
zcat /usr/share/doc/zabbix-server-mysql-4.4.7/create.sql.gz |mysql -uzabbix -pzabbix zabbix
if [ $? -eq 0 ];then
echo "修改zabbix配置文件"
sed -i '91s/# //' /etc/zabbix/zabbix_server.conf
sed -i '124c DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
echo "修改时区"
sed -i '20c \\t\php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
else
echo "导库失败,请处理"
fi
echo "启动zabbix服务,和httpd"
systemctl enable zabbix-server zabbix-agent httpd &> /dev/null
systemctl start zabbix-server zabbix-agent httpd
ss -ntl |grep 80 &> /dev/null
if [ $? -eq 0 ];then
echo "httpd已启动"
else
echo "请重启httpd"
fi
ss -ntl |grep 10051 &> /dev/null
if [ $? -eq 0 ];then
echo "zabbix-server已启动"
else
echo "请重启zabbix-server"
fi
ss -ntl |grep 10050 &> /dev/null
if [ $? -eq 0 ];then
echo "zabbix-agent已启动"
else
echo "请重启zabbix-agent"
fi
echo "zabbix-server部署成功,请在浏览器测试"
标签:shell,脚步,null,dev,server,zabbix,mysql,echo 来源: https://blog.csdn.net/xiaohuai0444167/article/details/105745723