一键式部署zabbix 4.0

#!/bin/bash

YUM(){
#下载wget
yum install -y wget

#下载网络仓库
wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo  
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

#编写网络仓库
cat > /etc/yum.repos.d/zabbix.repo <<EOF
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/x86_64/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0  
EOF
#rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

#yum clean all && yum makecache

} 

SERVER(){
#安装zabbix的服务端
yum install -y zabbix-server-mysql

#安装数据库
yum install -y mariadb*
systemctl restart mariadb

#安装zabbix web网页显示服务
yum install -y zabbix-web-mysql

#进入数据库并创建zabbix库,创建用户zabbix
read -e -p "请输入数据库root登陆密码:" PASS
mysqladmin -uroot password "$PASS"
echo "创建zabbix数据库,和用户名密码"
echo "create database zabbix character set utf8 collate utf8_bin;" | mysql -uroot -p$PASS
echo "grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';" | mysql -uroot -p$PASS
echo "flush privileges;" | mysql -uroot -p$PASS


#回到终端导入初始数据到zabbix库中
zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz | mysql -uzabbix -pzabbix zabbix

#关闭防护墙
systemctl stop firewalld
setenforce 0

#对数据库做开机自启
systemctl enable mariadb

#修改配置文件
sed -i /DBHost=/c\DBHost=localhost /etc/zabbix/zabbix_server.conf
sed -i /DBPassword=/c\DBPassword=zabbix /etc/zabbix/zabbix_server.conf

#启动zabbix-server
systemctl restart zabbix-server
systemctl enable zabbix-server      

#为前端配置php(替换第20行的内容)
sed -i '20c php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf

#开启httpd服务
systemctl start httpd
systemctl enable httpd

}

AGENT(){
#安装zabbix-agent
yum install -y zabbix-agent
systemctl start zabbix-agent

#修改配置文件
read -e -p "请选择要指向的zabbix服务端:(xx.xx.xx.xx):" AA
sed -i /^Server=/c\Server=$AA /etc/zabbix/zabbix_agentd.conf

#重启zabbix服务
systemctl restart zabbix-agent
systemctl enable zabbix-agent

#关闭防火墙
systemctl stop firewalld
setenforce 0

}


#选择配置服务端或者是客户端
AGAIN(){ 
read -e -p "请选择部署zabbix的1.服务端还是2.客户端:" BB
}
AGAIN

if [[ $BB -eq 1 ]]
then
    YUM
    SERVER
elif [[ $BB -eq 2 ]]
then
   YUM
   AGENT
else
   echo "输入错误,请输入1或者2!"
   AGAIN
fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值