在 CentOS6 上安装 Zabbix3.0 Agent 并开启客户端自动注册

 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

 

posted @ 2016-04-28 02:32  三角形  阅读(1223)  评论(0编辑  收藏  举报