hq8501 发表于 2019-1-23 10:12:28

zabbix 客户端安装脚本

  #/bin/bash
#by innocence_caosm
#源码自动安装zabbix客户端脚本。
#需要把zabbix安装包放在/tmp/ 下面执行。
#安装gcc cc插件
#此脚本已在centos6.5以及6.8版本测试过,其他版本慎用。
yum install -y gcc cc
  #需要注意修改的参数
server_ip=133.1.11.103
version=zabbix-3.2.7
  #检查zabbix用户是否存在
user=zabbix
group=zabbix
  #create group if not exists
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
groupadd $group
fi
  #create user if not exists
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
useradd -g $group $user -s /sbin/nologin
echo zabbix |passwd --stdin $user >& /dev/null
fi
  #检查原有zabbix服务,如果有则停掉
ps -ef |grep zabbix|grep -v grep
if [ $? -eq 0 ]
then
/etc/init.d/zabbix-agent stop || /etc/init.d/zabbix-agentd stop
fi
#编译安装
tar -zxvf /tmp/$version.tar.gz -C /usr/local/src/;cd /usr/local/src/$version/
./configure --prefix=/usr/local/$version/ --enable-agent
make&&make install
  #修改配置文件
sed -i.bak 's/127.0.0.1/$server_ip/g' /usr/local/$version/etc/zabbix_agentd.conf
hostname=cat /etc/sysconfig/network | sed -n '2p' | awk -F'=' '{print $2}'
sed -i "s/Hostname=Zabbix server/Hostname="$hostname"/g"/usr/local/$version/etc/zabbix_agentd.conf
  #配置init.d启动
cp /usr/local/src/$version/misc/init.d/fedora/core/zabbix_agentd/etc/init.d/zabbix_agentd
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/$version/g'/etc/init.d/zabbix_agentd
#配置开机启动
chkconfig--add zabbix_agentd
chkconfigzabbix_agentd on
/etc/init.d/zabbix_agentd start
#查看zabbix启动
netstat -lnp |grep zabbix
if [ $? -eq 0 ]
then
echo "Zabbix agent install have completed."
fi



页: [1]
查看完整版本: zabbix 客户端安装脚本