欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

昊鼎王五:如何2分钟内shell脚本实现编译安装zabbix_agent客户端?

程序员文章站 2024-01-16 11:44:34
...

昊鼎王五:如何2分钟内shell脚本实现编译安装zabbix_agent客户端?

Q.前提知识:

本文基于:
《昊鼎王五:linux如何安装zabbix服务器(zabbix2.2-server)》
https://blog.csdn.net/haoding205/article/details/82659479
接下来开始讲如何 2分钟内shell脚本实现编译安装zabbix_agent客户端

假设:
机器型号:centos7
zabbix-server机器:192.168.1.101
zabbix-Agent机器: 192.168.1.102

1.脚本内容:

cat install_zabbix_agent.sh

#!/bin/bash
Server_IP=192.168.1.101
Zabbix_Name=$(hostname)
yum install ntp openssl openssl-devel gcc gcc-c++ curl curl-devel -y >/dev/null 2>&1
wget http://192.168.1.103/other/zabbix/ntp.conf -O /etc/ntp.conf >/dev/null 2>&1
sed -i "s/ServerIP/${Server_IP}/g" /etc/ntp.conf
chkconfig --level 2345 ntpd on
service ntpd restart
#wget http://192.168.1.103/other/zabbix/libiconv-1.15.tar.gz
#tar zxvf libiconv-1.15.tar.gz
#cd libiconv-1.15/srclib/
#sed -i -e '/gets is a security/d' ./stdio.in.h
#cd ../
#./configure --prefix=/usr/local/
#make
#make install
#echo "/usr/local/lib" >>/etc/ld.so.conf
#ldconfig
#ls /usr/local/lib |grep libiconv.so.2
#rm -rf libiconv-1.15.tar.gz
groupadd zabbix >/dev/null 2>&1
useradd -s /sbin/nologin -M -g zabbix zabbix >/dev/null 2>&1
test -d /usr/local/zabbix && mv /usr/local/zabbix /usr/local/zabbix_bak_`date +%Y%M%d%H%m%S`
test -d /etc/zabbix && mv /etc/zabbix /etc/zabbix_bak_`date +%Y%M%d%H%m%S`
cd /root/
wget http://192.168.1.103/other/zabbix/zabbix-3.2.7.tar.gz >/dev/null 2>&1
tar zxvf zabbix-3.2.7.tar.gz >/dev/null 2>&1
cd zabbix-3.2.7
./configure --prefix=/usr/local/zabbix --enable-agent --with-ssh2 --with-libcurl >/dev/null 2>&1
make -j8 >/dev/null 2>&1 && make install >/dev/null 2>&1
mkdir /usr/local/zabbix/logs
chown -R zabbix.zabbix /usr/local/zabbix/logs
mkdir /etc/zabbix
ln -sf /usr/local/zabbix/etc/* /etc/zabbix
ln -sf /usr/local/zabbix/bin/zabbix_* /usr/local/bin/
ln -sf /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/
ln -sf /usr/local/zabbix/logs /etc/zabbix/logs
wget http://192.168.1.103/other/zabbix/zabbix_agentd_linux_init -O /etc/init.d/zabbix_agentd >/dev/null 2>&1
chmod 755 /etc/init.d/zabbix_agentd
chkconfig --add zabbix_agentd
chkconfig --level 2345 zabbix_agentd on
wget http://192.168.1.103/other/zabbix/zabbix_agentd.conf_linux -O /usr/local/zabbix/etc/zabbix_agentd.conf >/dev/null 2>&1
sed -i "s/ServerIP/${Server_IP}/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/ZabbixName/${Zabbix_Name}/g" /usr/local/zabbix/etc/zabbix_agentd.conf
/etc/init.d/zabbix_agentd restart
rm -rf /root/zabbix*

2.执行命令:

ntpq -p
bash install_zabbix_agent.sh

好了,聪明如你,知道了2分钟内shell脚本实现编译安装zabbix_agent客户端,是不是很欢喜 ^_^

还有其他问题的可以在评论区留言或者扫码加博主获取资源或者提问。
昊鼎王五:如何2分钟内shell脚本实现编译安装zabbix_agent客户端?