#!/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
一键式部署zabbix 4.0
最新推荐文章于 2024-04-18 03:52:42 发布