本腳本是zabbix_agent的自動安裝腳本忠寻,在centos6.4測試通過,并用于生產(chǎn)環(huán)境簇宽,使用前請修改zabbix server的地址
#!/bin/bash/
# Author:
zhouguanjie
# Version 1.1
#模塊化
# Description本腳本是zabbix_agent的自動安裝腳本苔巨,在centos6.4測試通過槐脏,并用于生產(chǎn)環(huán)境店乐,使用前請修改zabbix server的地址艰躺,
#以及InstallPath的路徑,程序安裝包的放置路徑為tmp目錄
#程序安裝的路徑
InstallPath=/usr/local/zabbix
DirPath="/tmp"
#檢測是否是root用戶執(zhí)行腳本
[$(id -u)!="0"]&&echo"Error: You
must be root to run this script"&&exit1
#設(shè)置selinux為permissive模式
functionclose_selinux(){
[`getenforce`=="Enforcing"]&&setenforce 0
sed -i's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config
}
#更換yum源
functionmod_yum(){
if!which wget&>/dev/null;thenyum install
wget;fi
#備份并將源改為阿里源
if[ -e/etc/yum.repos.d/CentOS-Base.repo ]
then
mv /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup&&\
wget -O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.163.com/.help/CentOS6-Base-163.repo
wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo
fi
#使用which查看rpm包是否安裝眨八,未安裝就安裝
if[!`which rpm`]
then
yum install rpm -y
yum install wget -y
fi
#添加EPEL源
if[!`find
/etc/yum.repos.d/ -name "epel.repo"`]
then
wgethttp://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
fi
yum clean all&&yum list
}
#關(guān)閉防火墻
functionclose_iptables(){
service iptables stop
}
#同步NTP服務(wù)器
#安裝相關(guān)的軟件包
functiontime_sync(){
`rpm -ql ntp`||yum install ntp-y
ntpdate cn.ntp.org.cn
#加入定時任務(wù)到root
if[`grep ntpdate
/var/spool/cron/root|wc -l`-lt 1 ]
then
echo"0 23 * * 6
/usr/sbin/ntpdate cn.ntp.org.cn">>/var/spool/cron/root
else
echo"netdate
has added"
fi
}
#安裝zabbix
functionzabbix_install(){
#zabbix server端IP地址,根據(jù)zabbix服務(wù)端的地址設(shè)置
zabbix_serverIP="192.168.238.152"
#zabbix_serverIP="10.32.4.151"
echo-e“zabbix_serverIP is $zabbix_serverIP
#zabbix軟件安裝包的小版本號
VER=3.2.0
#添加zabbix帳號
echo-e"add user
zabbix"
if!`id zabbix&>/dev/null`
then
groupadd zabbix
useradd -M-g zabbix -s /sbin/nologin zabbix
fi
#安裝依賴關(guān)系
yum -y groupinstall"Development
tools"
if!which whiptail&>/dev/null;thenyum install
newt;fi
# if ! which wget &>/dev/null;
then yum install wget;fi
#切換腺兴,解壓縮軟件包安裝
echo-e"prepare
install zabbix_agent"
cd$DirPath
[ -f zabbix-$VER.tar.gz ]&&tar xfzabbix-$VER.tar.gz
if[ $?!= 0 ]
then
echo"The file
zabbix.tar.gz dose not exit"
exit1
fi
#change the directory
cd$DirPath/zabbix-$VER&&echo'change the
directory into zabbix,ok'
echo"intall the
zabbix-agent"
#編譯安裝
./configure --prefix=$InstallPath--enable-agent
make
make install
ret=$?
echo$ret
if[ $ret == 0 ]
then
echo"install
zabbix finish"
fi
if[ $ret -eq 0 ]
then
#read-p "please inputzabbix_serverIP:"zabbix_serverIP
sed -i's/Server=127.0.0.1/Server='$zabbix_serverIP'/'$InstallPath/etc/zabbix_agentd.conf
sed -i's/ServerActive=127.0.0.1/ServerActive='$zabbix_serverIP'/'$InstallPath/etc/zabbix_agentd.conf
sed -i's/Hostname=Zabbix
server/Hostname='$HOSTNAME'/'$InstallPath/etc/zabbix_agentd.conf
#這個地方注意修改下,根據(jù)實際的位置
sed -ri's@# Include=/usr/local/etc/zabbix_agentd.conf.d/$@Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/@'$InstallPath/etc/zabbix_agentd.conf
echo"zabbix
install success,you need set hostname: $HOSTNAME"
else
echo"install
failed,please check"
fi
#start the zabbix_agentd
/usr/local/zabbix/sbin/zabbix_agentd
#add start option to rc.local
if[ $ret -eq 0 ]
then
echo"set
zabbix_agentd start with system"
echo"/usr/local/zabbix/sbin/zabbix_agentd">>/etc/rc.d/rc.local
else
echo"start
zabbix_agentd faild,please check"
fi
}
functionmain(){
mod_yum
zabbix_install
}
main