在 CentOS6 上安裝 Zabbix3.0 Agent 並開啟客戶端自動註冊

三角形發表於2016-04-28
 1 #!/bin/bash
 2 
 3 #
 4 #    1、配置yum源
 5 #
 6 
 7 cat /etc/redhat-release |grep -i centos |grep '6.[[:digit:]]' &>/dev/null
 8 
 9 if [[ $? != 0 ]] 
10 then
11     echo -e "不支援的作業系統,該指令碼只適用於CentOS 6.x 作業系統"
12     exit 1
13 fi
14 
15 os_m=$(uname -m)
16 za_rpm=$(curl -s http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/6/$os_m/ |grep release  |awk -F '>|<' '{print $3}')
17 rpm -i --force http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/6/$os_m/$za_rpm
18 
19 if [[ $? != 0 ]] 
20 then
21     echo -e "yum源配置失敗,請檢查網路或者其他原因"
22     exit 1
23 fi
24 
25 sed -i 's@repo.zabbix.com@mirrors.aliyun.com/zabbix@' /etc/yum.repos.d/zabbix.repo
26 
27 #
28 #    2、使用yum安裝Zabbix
29 #
30 
31 yum install -y zabbix-agent zabbix-sender
32 chkconfig zabbix-agent on
33 iptables -I  INPUT -m state --state NEW -p tcp  --dport 10050 -j ACCEPT 
34 /etc/init.d/iptables save
35 
36 ping -c 1 $1 &>/dev/null
37 
38 if [[ $? == 0 ]]
39 then
40     sed -i 's/^Server=127.0.0.1/Server='$1'/' /etc/zabbix/zabbix_agentd.conf
41     sed -i 's/^ServerActive=127.0.0.1/ServerActive='$1'/' /etc/zabbix/zabbix_agentd.conf
42     sed -i 's/^Hostname=Zabbix server/Hostname='`hostname`'/' /etc/zabbix/zabbix_agentd.conf
43     sed -i '/^# HostMetadataItem=/a HostMetadataItem=system.uname' /etc/zabbix/zabbix_agentd.conf
44 
45     /etc/init.d/zabbix-agent start
46 else
47     sed -i 's/^Hostname=Zabbix server/Hostname='`hostname`'/' /etc/zabbix/zabbix_agentd.conf
48     sed -i '/^# HostMetadataItem=/a HostMetadataItem=system.uname' /etc/zabbix/zabbix_agentd.conf
49 
50     echo -e "\n\t請手動修改 '/etc/zabbix/zabbix_agentd.conf' 檔案\n\n\t\tServer=Zabbix-Server_IP\n\t\tServerActive=Zabbix-Server_IP\n\n\t然後執行 '/etc/init.d/zabbix-agent start' 啟動Zabbix-agent\n"
51 fi

 

相關文章