Browse Source

zabbix agent

master
xiaoz 7 years ago
parent
commit
ff79845f2b
  1. 40
      zabbix_agent.sh

40
zabbix_agent.sh

@ -7,6 +7,39 @@
hostname=$(hostname) hostname=$(hostname)
#获取服务器IP #获取服务器IP
osip=$(curl http://https.tn/ip/myip.php?type=onlyip) osip=$(curl http://https.tn/ip/myip.php?type=onlyip)
#配置文件
zabbix_config="/etc/zabbix/zabbix_agentd.conf"
#配置zabbix agent
function setting($hostname,$osip){
read -p "输入Zabbix server IP:" serverip
#备份配置
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
#设置Server name
sed -i "s/Hostname=Zabbix server/Hostname=${hostname}/g" ${zabbix_config}
#设置连接IP
sed -i "s/# SourceIP=/SourceIP=${osip}/g" ${zabbix_config}
#设置Server IP
sed -i "s/ServerActive=127.0.0.1/ServerActive=${serverip}/g" ${zabbix_config}
echo "\n"
echo "##### 设置成功 #####"
echo "Server IP:${serverip}"
echo "Agent:${osip}:10050"
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
}
#安装函数 #安装函数
function centos7(){ function centos7(){
@ -48,7 +81,10 @@ echo "----------------------------------"
read -p ":" num read -p ":" num
case $num in case $num in
1) 1)
echo "CentOS 7" centos7()
setting($hostname,$osip)
chk_firewall()
systemctl start zabbix-agent.service
;; ;;
2) 2)
echo "CentOS 6" echo "CentOS 6"
@ -56,7 +92,7 @@ case $num in
3) 3)
echo "Debian 8" echo "Debian 8"
;; ;;
1) 4)
echo "Debian 7" echo "Debian 7"
;; ;;
q) q)

Loading…
Cancel
Save