zabbix_agent端部署脚本

本脚本是zabbix_agent的自动安装脚本,在centos6.4测试通过,并用于生产环境,使用前请修改zabbix server的地址


#!/bin/bash/

# Author:

zhouguanjie

# Version 1.1

#模块化

# Description本脚本是zabbix_agent的自动安装脚本,在centos6.4测试通过,并用于生产环境,使用前请修改zabbix server的地址,

#以及InstallPath的路径,程序安装包的放置路径为tmp目录

#程序安装的路径

InstallPath=/usr/local/zabbix

DirPath="/tmp"

#检测是否是root用户执行脚本

[$(id -u)!="0"]&&echo"Error: You

must be root to run this script"&&exit1

#设置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

}

#关闭防火墙

functionclose_iptables(){

service iptables stop

}

#同步NTP服务器

#安装相关的软件包

functiontime_sync(){

`rpm -ql ntp`||yum install ntp-y

ntpdate cn.ntp.org.cn

#加入定时任务到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地址,根据zabbix服务端的地址设置

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

#安装依赖关系

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

#这个地方注意修改下,根据实际的位置

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

你可能感兴趣的:(zabbix_agent端部署脚本)