-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzabbix_agentd.sh
99 lines (90 loc) · 3.36 KB
/
zabbix_agentd.sh
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
90
91
92
93
94
95
96
97
98
99
##############################################################################################
# configuration of zabbix-agentd for client
# version 0.3 date:2014/05/28
# usage:Run this script,input the type of your system(32 or 64).
# Then,come back to zabbix-web,add your server-pc at configuration of hosts.It's so easy!
##############################################################################################
#! /bin/bash
mkdir -p /usr/local/zabbix
MY_IP=`ifconfig | grep '192.168.20.*' | cut -f 2 -d ":"|cut -f 1 -d " "`
ZABBIX_IP=192.168.20.12
MY_DIR1=/usr/local/src
MY_DIR2=/usr/local/zabbix
MY_DIR3=/usr/local/etc
MY_TAR32=zabbix_agents_32.tar.gz
MY_TAR64=zabbix_agents_64.tar.gz
function add_user_zabbix (){
useradd zabbix -s /bin/false
}
function install_zabbix (){
a=0
while [ $a -eq 0 ]
do
echo "Please input the type of your system (32 or 64): "
read yn
if [ "$yn" = "32" ]; then
cd $MY_DIR1
wget ftp://192.168.20.12/pub/i386/$MY_TAR32
tar -zvxf $MY_DIR1/$MY_TAR32 -C $MY_DIR2
a=1
elif [ "$yn" = "64" ]; then
cd $MY_DIR1
wget ftp://192.168.20.12/pub/x64/$MY_TAR64
tar -zvxf $MY_DIR1/$MY_TAR64 -C $MY_DIR2
a=1
else
a=0
fi
done
}
function add_zabbix_port (){
echo "zabbix-agent 10050/tcp # Zabbix Agent TCP" >> /etc/services
echo "zabbix-agent 10050/udp # Zabbix Agent UDP" >> /etc/services
}
function config_zabbix (){
ln -s $MY_DIR2/sbin/zabbix_agentd /usr/sbin/zabbix_agentd
cp $MY_DIR2/conf/zabbix_agentd.conf $MY_DIR3
sed -i '81s/.*/Server='$ZABBIX_IP'/' $MY_DIR3/zabbix_agentd.conf
sed -i '97s/.*/ListenIP='$MY_IP'/' $MY_DIR3/zabbix_agentd.conf
sed -i '106s/.*/StartAgents=5/' $MY_DIR3/zabbix_agentd.conf
sed -i '122s/.*/ServerActive='$ZABBIX_IP'/' $MY_DIR3/zabbix_agentd.conf
sed -i '133s/.*/Hostname='$MY_IP'/' $MY_DIR3/zabbix_agentd.conf
sed -i '242s/# //' $MY_DIR3/zabbix_agentd.conf
sed -i '243s/# //' $MY_DIR3/zabbix_agentd.conf
sed -i '255s/.*/UnsafeUserParameters=1/' $MY_DIR3/zabbix_agentd.conf
touch $MY_DIR3/zabbix_agentd.userparams.conf
mkdir -p $MY_DIR3/zabbix_agentd.conf.d
mkdir -p $MY_DIR3/scripts
cp $MY_DIR2/sbin/zabbix-agent /etc/init.d/
chmod +x /etc/init.d/zabbix-agent
}
function get_userparams (){
rm -f $MY_DIR3/zabbix_agentd.userparams.conf
wget -P $MY_DIR3 ftp://192.168.20.12/pub/zabbix/zabbix_agentd.userparams.conf
}
function get_scripts (){
wget -P $MY_DIR3/scripts ftp://192.168.20.12/pub/zabbix/scripts/*
chmod +x $MY_DIR3/scripts/*
touch $MY_DIR3/scripts/raid.log
chmod 775 $MY_DIR3/scripts/raid.log
}
function get_userparams_conf (){
wget -P /usr/local/etc/zabbix_agentd.conf.d/ ftp://192.168.20.12/pub/zabbix/zabbix_agentd.conf.d/*
}
function add_sudo (){
echo "Defaults:zabbix !requiretty" >> /etc/sudoers
echo "zabbix ALL=(ALL) NOPASSWD: /usr/sbin/MegaCli" >> /etc/sudoers
echo "zabbix ALL=(ALL) NOPASSWD: /usr/sbin/mpt-status" >> /etc/sudoers
echo "zabbix ALL=(ALL) NOPASSWD: /usr/sbin/sas2ircu" >> /etc/sudoers
}
add_user_zabbix
add_zabbix_port
install_zabbix
config_zabbix
get_userparams
get_userparams_conf
get_scripts
chmod a+r /var/log/auth.log
chown -R root:zabbix $MY_DIR3/*
add_sudo
/etc/init.d/zabbix-agent start