自动安装Zabbix Agent的linux 脚本

简介:

安装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/files/ZABBIX %20Latest%20Stable /2 .0.8 /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=/c\Hostname=${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"




本文转自 bannerpei 51CTO博客,原文链接:http://blog.51cto.com/281816327/1618036,如需转载请自行联系原作者
相关文章
|
25天前
|
Linux Shell
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
78 1
|
28天前
|
Linux Shell Python
Linux执行Python脚本
Linux执行Python脚本
27 1
|
2月前
|
存储 安全 Linux
|
2月前
|
监控 关系型数据库 Linux
|
3月前
|
Shell Linux Perl
将 Linux 系统中 UID 大于等于 1000 的普通用户都删除shell脚本
将 Linux 系统中 UID 大于等于 1000 的普通用户都删除shell脚本
42 1
|
3月前
|
Linux Shell
Linux文件解压脚本实现
Linux文件解压脚本实现
26 0
|
3月前
|
Linux Shell Perl
Linux脚本实现文件系统使用率大于90%报警
Linux脚本实现文件系统使用率大于90%报警
30 0
|
3月前
|
Shell Linux
linux shell脚本判断当前登录用户是否为root
linux shell脚本判断当前登录用户是否为root
52 1
|
4天前
|
Linux Shell Android开发
自动化脚本之GPIO/LED相关适用于Android/Linux
自动化脚本之GPIO/LED相关适用于Android/Linux
13 0
|
24天前
|
Ubuntu Unix Linux
【Linux/Ubuntu】Linux/Ubuntu运行python脚本
【Linux/Ubuntu】Linux/Ubuntu运行python脚本