-
Notifications
You must be signed in to change notification settings - Fork 0
CentOS7 上 Zabbix3.2.4 客户端一键安装脚本
xiangzi edited this page Sep 20, 2018
·
3 revisions
#!/usr/bin/env bash
set -e
set -x
SRC='/usr/local/src'
CONF='/usr/local/zabbix/etc/zabbix_agentd.conf'
#以交互的方式设置zabbix_server 服务器IP地址
read -p "Please input the zabbix server ip address: " SRVIP
#安装必要的工具
yum install -y gcc gcc-c++ wget ntpdate
#设置时区
yes |cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#在线同步下时间
ntpdate time.windows.com
#下载zabbix
wget -O ${SRC}/zabbix-3.2.4.tar.gz https://master.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.4/zabbix-3.2.4.tar.gz
#解压:
tar zxf ${SRC}/zabbix-3.2.4.tar.gz -C ${SRC}/
#进入解压目录:
cd ${SRC}/zabbix-3.2.4
#配置编译参数
./configure --prefix=/usr/local/zabbix --enable-agent
#编译及安装
make && make install
#添加zabbix 用户
useradd -s /bin/bash zabbix
#修改配置文件:
sed -i "s@^# PidFile=/tmp/zabbix_agentd.pid@PidFile=/tmp/zabbix_agentd.pid@" ${CONF}
sed -i "s@^Server=127.0.0.1@Server=${SRVIP}@" ${CONF}
sed -i "s@^ServerActive=127.0.0.1@ServerActive=${SRVIP}@" ${CONF}
sed -i "s@^Hostname=Zabbix server@Hostname=$(echo $HOSTNAME)@" ${CONF}
#设置启动脚本:
cat << eof > /etc/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
WorkingDirectory=/usr/local/zabbix
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
User=zabbix
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=mixed
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c \$CONFFILE
ExecStop=/bin/kill -s QUIT $MAINPID
EeecReload=/bin/kill -s HUP $MAINPID
[Install]
WantedBy=multi-user.target
eof
#启动客户端:
systemctl start zabbix-agent
#设置随机启动:
systemctl enable zabbix-agent