zabbix-agent自动安装脚本
Posted 小怪獣55
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix-agent自动安装脚本相关的知识,希望对你有一定的参考价值。
1.准备文件
zabbix-4.0.35.tar.gz
zabbix_agentd.conf
zabbix-agent.service
zabbix-agent-install.sh
1.1.zabbix_agentd.conf
root@ubuntu:/data# grep ^[a-Z] zabbix_agentd.conf
---------------------------------------------------------
PidFile=/apps/zabbix_agent/run/zabbix_agentd.pid
LogFile=/apps/zabbix_agent/run/zabbix_agentd.log
EnableRemoteCommands=1
Server=192.168.47.51
StartAgents=3
ServerActive=192.168.47.51
Hostname=
Timeout=30
AllowRoot=1
User=root
Include=/apps/zabbix_agent/conf.d/*.conf
UnsafeUserParameters=1
1.2.zabbix-agent.service
root@ubuntu:/data# cat zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/apps/zabbix_agent/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/default/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/apps/zabbix_agent/run/zabbix_agentd.pid
KillMode=control-group
ExecStart=/apps/zabbix_agent/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
1.3.zabbix-agent-install.sh
grep "Kernel" /etc/issue >> /dev/null
if [ $? -eq 0 ];then
yum install vim iotop bc gcc gcc-c++ glibc glibc-devel pcre \\
pcre-devel openssl openssl-devel zip unzip zlib-devel net-tools \\
lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel \\
bc systemd-devel bash-completion traceroute firewalld bridge-utils -y
fi
grep "Ubuntu" /etc/issue >> /dev/null
if [ $? -eq 0 ];then
apt-get update
apt-get install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server \\
nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate \\
tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 \\
libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip firewalld make -y
fi
DIR=`pwd`
useradd zabbix
tar xf zabbix-4.0.35.tar.gz && cd zabbix-4.0.35 && ./configure --prefix=/apps/zabbix_agent --enable-agent && make && make install
mkdir /apps/zabbix_agent/conf.d,run
\\cp $DIR/zabbix-agent.service /lib/systemd/system/zabbix-agent.service
\\cp $DIR/zabbix_agentd.conf /apps/zabbix_agent/etc/
IP=`ifconfig eth0 |grep -w inet |awk print $2`
sed -i s/Hostname=/Hostname=$IP/g /apps/zabbix_agent/etc/zabbix_agentd.conf
chown zabbix.zabbix /apps/zabbix_agent -R
systemctl daemon-reload
systemctl start zabbix-agent && systemctl enable zabbix-agent
echo "zabbix-agent 安装成功"
以上是关于zabbix-agent自动安装脚本的主要内容,如果未能解决你的问题,请参考以下文章