zabbix_agent端部署腳本

本腳本是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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • #!/bin/bash #install_package #2016/10/28 by Chris_JD #Bas...
    宇信智臻sy閱讀 1,164評論 1 5
  • Linux 下RPM打包制作流程 開始前的準備 安裝rpmbuild軟件包 yum -y install rpm-...
    jony456123閱讀 1,548評論 0 1
  • 1 概述 LAMP 目前在CentOS6不支持php-fpm的安裝,安裝高版本的數(shù)據(jù)庫在centos6上也需要通過...
    ghbsunny閱讀 521評論 0 0
  • 開學(xué)兩周了 很忙很亂 但又覺得沒干什么 上周和室友進進出出 周末和老鄉(xiāng)觀光了健身房徒步了快十里路 周日和萱在楚河漢...
    噠戈正井典閱讀 343評論 0 0
  • 今天看了起點學(xué)院的一節(jié)課程,跟著老師的脈絡(luò)梳理出來,感覺這棵樹很完整很清晰,做競品分析時:確定自己想要通過分析了解...
    橙汁兒0_0閱讀 492評論 0 0

友情鏈接更多精彩內(nèi)容