设为首页收藏本站我的广告

运维网

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
总共321条微博

每日一博

查看: 9995|回复: 0

【站长推荐】自动安装Zabbix Agent的linux 脚本【顶】

[复制链接]

该用户从未签到

dfger2000 发表于 2018-6-13 13:12:43 | 显示全部楼层 |阅读模式
【站长推荐】安装Zabbix代理的脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#the zabbix path you want to install
PREFIX="/usr/local/zabbix"
ConfigFile="/etc/zabbix/zabbix_agentd.conf"
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
Server="serverName"
#Required for active checks and must match hostname as configured on the server.
Hostname=`hostname`
function checkReturn {
  if [ $1 -ne 0 ]; then
     echo "fail: $2"
     echo "$3"
     exit
  else
     echo "pass: $2"
  fi
  sleep 3
}
[ -n "$(pidof -s zabbix_agentd)" ] && {
  echo "zabbix_agentd process is already running....."
  exit 1
}
[ -n "$(which zabbix_agentd 2> /dev/null)" ] && {
  echo "zabbix_agentd program has been installed....."
  exit 1
}
# check selinux
if [ "`/usr/sbin/sestatus|awk '/status/{print $3}'`" == "enabled" ]; then
   checkReturn 1 "Disable SELinux and then retry"
fi
rpm -q gcc make || {
yum install gcc make
RETVAL=$?
checkReturn $RETVAL "Package install"
}
if [ -z "$(id -u zabbix 2> /dev/null)" ]
then
    useradd zabbix -s /sbin/nologin
fi
wget http://sourceforge.net/projects/ ... zabbix-2.0.8.tar.gz
RETVAL=$?
checkReturn $RETVAL "downloading source" "check mirror might be down"
tar xvf zabbix-2.0.8.tar.gz
cd zabbix-2.0.8
./configure --prefix=${PREFIX} --enable-agent
RETVAL=$?
checkReturn $RETVAL "Configure"
make
RETVAL=$?
checkReturn $RETVAL "Compile"
make install
RETVAL=$?
checkReturn $RETVAL "make install"
echo "zabbix agentd install ok....!"
mkdir -p /var/log/zabbix
chown zabbix.zabbix /var/log/zabbix
echo "configure zabbix startup script.....!"
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
chmod 755 /etc/init.d/zabbix_agentd
sed -i 's#BASEDIR=/usr/local#&/zabbix#' /etc/init.d/zabbix_agentd
chkconfig --level 345 zabbix_agentd on
echo "copy the configuration file to zabbix installion directory.....!"
if [ -d ${PREFIX}/etc ]
     then
        /bin/rm -rf ${PREFIX}/etc/*
        cp conf/zabbix_agentd.conf ${PREFIX}/etc
fi
echo "add link file.....!"
ln -s /usr/local/zabbix/etc /etc/zabbix
ln -s /usr/local/zabbix/bin/* /usr/bin/
ln -s /usr/local/zabbix/sbin/* /usr/sbin/
[ -f "$ConfigFile" ] && {
sed -i "/^Server=/s#.*#Server=$Server#" $ConfigFile
sed -i "/^ServerActive/s#.*#ServerActive=$Server:10051#" $ConfigFile
sed -i '/^LogFile=/s#.*#LogFile=/var/log/zabbix/zabbix_agentd.log#' $ConfigFile
sed -i '/UnsafeUserParameters=0/aUnsafeUserParameters=1' $ConfigFile
if [ -n $Hostname ]
   then
    sed -i "/^Hostname=/cHostname=${Hostname}" $ConfigFile
fi
}
echo '/etc/services add service port.....!'
cat >> /etc/services << EOF
#zabbix agentd
zabbix-agent    10050/tcp                       #Zabbix Agent
zabbix-agent    10050/udp                       #Zabbix Agent
zabbix-trapper  10051/tcp                       #Zabbix Trapper
zabbix-trapper  10051/udp                       #Zabbix Trapper
EOF




*将下面的改为自己的zabbix的服务器
1
Server="serverName"


运维网 感谢您的阅读
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|sitemap|手机版|小黑屋|Archiver|运维网 ( 京ICP备16008201号  

GMT+8, 2018-11-15 20:52 , Processed in 0.123573 second(s), 29 queries , XCache On.

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表