Java教程

自动安装zabbix-agentd脚本 s

本文主要是介绍自动安装zabbix-agentd脚本 s,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

install_zabbix_agent.sh

#/bin/bash
# auther by wangxp

ZABBIX_AGENT_DIR="/u01/zabbix"
ZABBIX_AGENT_FILE_NAME="zabbix_agent-5.2.7-linux-3.0-amd64-static.tar.gz"
SERVER_IP=192.168.1.1
#LOG_FILE=

echo "检查安装文件..."
sleep 1
if test -f "$ZABBIX_AGENT_FILE_NAME"
then
    echo "当前目录找到安装文件:$ZABBIX_AGENT_FILE_NAME"
else
    ls `pwd`
    echo "当前目录找不到:$ZABBIX_AGENT_FILE_NAME ,脚本退出"
    exit 1
fi

echo "检查安装目录..."
sleep 1
if test -d $ZABBIX_AGENT_DIR
then
    echo "存在安装路径:$ZABBIX_AGENT_DIR"
else
    echo "创建安装路径:$ZABBIX_AGENT_DIR"
    mkdir -pv $ZABBIX_AGENT_DIR
fi

echo "创建zabbix用户..."
sleep 1
grep "zabbix" /etc/passwd
if [ $? -ne 0 ];
then
    useradd zabbix -s /sbin/nologin
fi
#检测函数
check(){
if [ $? -ne 0 ];
then
echo "Error,Please check again."
exit 1
fi
}

echo "开始解压缩文件..."
sleep 1
tar -zxvf $ZABBIX_AGENT_FILE_NAME -C $ZABBIX_AGENT_DIR
check

echo “创建软链接”
sleep 1
if test ! -L '/usr/bin/zabbix_sender'
then
ln -s $ZABBIX_AGENT_DIR/bin/zabbix_sender /usr/bin
else 
echo "/usr/bin/zabbix_sender 已经存在"
fi
if test ! -L '/usr/bin/zabbix_get'
then
ln -s $ZABBIX_AGENT_DIR/bin/zabbix_get /usr/bin
else
echo "/usr/bin/zabbix_get 已经存在"
fi
if test ! -L '/usr/sbin/zabbix_agentd'
then
ln -s $ZABBIX_AGENT_DIR/sbin/zabbix_agentd /usr/sbin
else
echo "/usr/sbin/zabbix_agentd 已经存在"
fi

echo "修改zabbix_agent配置..."
sleep 1
sed -r -i s/^Server=127.0.0.1/Server=$SERVER_IP/g  $ZABBIX_AGENT_DIR/conf/zabbix_agentd.conf
check
sed -r -i s/^ServerActive=127.0.0.1/ServerActive=$SERVER_IP/g $ZABBIX_AGENT_DIR/conf/zabbix_agentd.conf
check
sed -r -i s/'^Hostname=Zabbix server'/Hostname=`hostname`/g $ZABBIX_AGENT_DIR/conf/zabbix_agentd.conf
check

echo -e  "zabbix_agent基本配置:"
cat $ZABBIX_AGENT_DIR/conf/zabbix_agentd.conf | egrep '^Server|^ServerActive|^Hostname'

echo -e "添加zabbix_agent启停脚本。。。"
sleep 1
if test ! -f zabbix_agent.sh
then
echo -e  "
#/bin/bash
# chkconfig: 2345 22 78
# description:\n
ZABBIX_AGENT_DIR=$ZABBIX_AGENT_DIR
ZABBIX_AGENT=$ZABBIX_AGENT_DIR/sbin/zabbix_agentd
ZABBIX_AGENT_CONF=$ZABBIX_AGENT_DIR/conf/zabbix_agentd.conf
" > zabbix_agentd.sh
echo '
function stop(){
kill -15 `cat /tmp/zabbix_agentd.pid`
} 
case $1 in 
start) 
$ZABBIX_AGENT -c $ZABBIX_AGENT_CONF
;;
stop)
stop
;;
restart)
stop
$ZABBIX_AGENT -c $ZABBIX_AGENT_CONF
;;
*) 
echo "Usage:service zabbix_agentd start|stop|restart"
;; 
esac'>>zabbix_agentd.sh
chmod u+x zabbix_agentd.sh
else
echo "当前目录已经存在zabbix_agent.sh脚本。"
fi

echo "zabbix_agent添加到init进程..."
sleep 1
if test ! -f /etc/init.d/zabbix-agentd;then
cp zabbix_agentd.sh /etc/init.d
mv /etc/init.d/zabbix_agentd.sh /etc/init.d/zabbix-agentd
chmod a+x /etc/init.d/zabbix-agentd
else 
echo "/etc/init已经存在zabbix-agentd服务"
fi
check

echo "zabbix_agent开机启动设置"
chkconfig --add zabbix-agentd
chkconfig zabbix-agentd on
if test -z "ss -ntlp|grep zabbix_agentd|grep -v grep"
then 
echo "zabbix-agentd 启动中..."
service zabbix-agentd start
sleep 1
fi

if test ! -z "ss -ntlp |grep zabbix-agentd|grep -v grep"
then
echo "zabbix_agentd服务已经启动"
else
echo "zabbix_agentd服务启动失败!"
fi

 

这篇关于自动安装zabbix-agentd脚本 s的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!