平时写的各种linux shell脚本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.9 KiB

7 years ago
#!/bin/bash
##### 一键安装Zabbix agent #####
##### Update:2019-05-19 #####
7 years ago
##### Author:xiaoz.me #####
#获取主机名
hostname=$(hostname)
#获取服务器IP
6 years ago
osip=$(curl https://api.ttt.sh/ip/qqwry/?type=ip)
7 years ago
#配置文件
zabbix_config="/etc/zabbix/zabbix_agentd.conf"
#配置zabbix agent
7 years ago
function setting(){
7 years ago
read -p "输入Zabbix server IP:" serverip
#备份配置
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
#设置Server name
7 years ago
sed -i "s/Hostname=Zabbix server/Hostname=$1/g" ${zabbix_config}
7 years ago
#设置连接IP
7 years ago
sed -i "s/# SourceIP=/SourceIP=$2/g" ${zabbix_config}
7 years ago
#设置Server IP
7 years ago
sed -i "s/Server=127.0.0.1/Server=${serverip}/g" ${zabbix_config}
7 years ago
echo "##### 设置成功 #####"
echo "Server IP:${serverip}"
7 years ago
echo "Agent:$2:10050"
7 years ago
echo "###############################"
}
#自动放行端口
function chk_firewall() {
if [ -e "/etc/sysconfig/iptables" ]
then
iptables -I INPUT -p tcp --dport 10050 -j ACCEPT
service iptables save
service iptables restart
else
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --reload
fi
}
7 years ago
#安装函数
function centos7(){
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
yum -y install zabbix-agent
#开机启动
systemctl enable zabbix-agent.service
}
function centos6(){
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-release-3.4-1.el6.noarch.rpm
yum -y install zabbix-agent
#开机启动
chkconfig zabbix-agent on
}
function debian8(){
wget http://repo.zabbix.com/zabbix/3.4/debian/pool/main/z/zabbix-release/zabbix-release_3.4-1+jessie_all.deb
dpkg -i zabbix-release_3.4-1+jessie_all.deb
apt-get update
apt-get install -y zabbix-agent
}
function debian7(){
wget http://repo.zabbix.com/zabbix/3.4/debian/pool/main/z/zabbix-release/zabbix-release_3.4-1+wheezy_all.deb
dpkg -i zabbix-release_3.4-1+wheezy_all.deb
apt-get update
apt-get install -y zabbix-agent
}
function zabbix4(){
6 years ago
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum -y install zabbix-agent
#开机启动
systemctl enable zabbix-agent.service
}
7 years ago
echo "----------------------------------"
echo "请选择系统:"
echo "1) CentOS 7(Zabbix agent v3.4)"
7 years ago
echo "2) CentOS 6"
echo "3) Debian 8"
echo "4) Debian 7"
echo "5) CentOS 7(Zabbix agent v4.0)"
7 years ago
echo "q) 退出"
echo "----------------------------------"
read -p ":" num
case $num in
7 years ago
1)
#安装
centos7
#设置
setting $hostname $osip
#放行端口
chk_firewall
#启动服务
7 years ago
systemctl start zabbix-agent.service
7 years ago
;;
2)
7 years ago
centos6
setting $hostname $osip
#放行端口
chk_firewall
service zabbix-agent start
7 years ago
;;
3)
echo "Debian 8"
;;
7 years ago
4)
7 years ago
echo "Debian 7"
;;
5)
zabbix4
#设置
setting $hostname $osip
#放行端口
chk_firewall
#启动服务
systemctl start zabbix-agent.service
;;
7 years ago
q)
exit
;;
esac