????在不同公司大家在安裝Zabbix?Agent的時候,因?yàn)楣竟芾硪?guī)則的不同,會導(dǎo)致安裝的步驟有所不同。網(wǎng)上現(xiàn)在自動安裝的腳本其實(shí)已經(jīng)比較多了,但是解釋感覺較少,主要是安裝的思路。
下面是基于源碼的agent安裝過程大家可以參考。
一、主要的思路是
1、執(zhí)行kill命令查看是否已經(jīng)有agent在運(yùn)行
2、檢測執(zhí)行用戶,因?yàn)閍gent必須用root用戶進(jìn)行安裝
3、檢測gcc包是否已經(jīng)安裝,因?yàn)檫@是agent安裝的基礎(chǔ)
4、檢測是否已經(jīng)存在zabbix安裝路徑
5、在os上添加zabbix用戶和用戶組
6、獲取安裝介質(zhì)
7、編譯?安裝
8、修改zabbix_agentd.conf文件
9、復(fù)制啟動腳本到init.d目錄,讓其開機(jī)自啟動
10、修改sudo權(quán)限,讓zabbix可以免密sudo到超級用戶
11、啟動agent并查看端口看是否啟動成功
二、自動安裝腳本如下
#!/bin/bash
#this script is used for installing a zabbix agent on Linux system
###zabbix server ip
SERVER_IP="1.1.1.1"
CONFG_PATH="/usr/local/zabbix/etc/zabbix_agentd.conf"
startup_bin="/usr/local/zabbix/sbin/zabbix_agentd"
set passwd "123456"
pkill zabbix? > /dev/null
###must run as root
if [ "`whoami`" != "root" ]
then
? ? ? ? print "This must be run as root."
? ? ? ? exit -1
fi
###check gcc
gcc_make_soft=`rpm -qa | grep -E '^gcc|^make' | wc -l`
if [ $gcc_make_soft -lt 2 ]; then
yum -y install gcc make
fi
###check zabbix install dir
if [ -d "/usr/local/zabbix" ] ;then
? ? ? ? mv /usr/local/zabbix /usr/local/zabbix_bak
fi
###user add
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
###get tar.gz from your server && compile
cd /usr/local/src/
spawn scp root@1.1.1.1:/usr/local/src/zabbix-3.2.3.tar.gz /usr/local/src
expect {
? "密碼:"
? ? ? ? {
? ? ? ? ? send "$passwd\n"
? ? ? ? }
? "pass"
? ? ? ? {
? ? ? ? ? send "$passwd\n"
? ? ? ? }
? "yes/no"
? ? ? ? {
? ? ? ? ? sleep 5
? ? ? ? ? send_user "send yes"
? ? ? ? ? send "yes\n"
? ? ? ? }
? eof
? ? {
? ? ? ? sleep 5
? ? ? ? send_user "eof\n"
? ? }
}
send "exit\r"
expect eof
tar -xvf zabbix-3.2.3.tar.gz
cd /usr/local/src/zabbix-3.2.3
./configure --prefix=/usr/local/zabbix --enable-agent? && make install
###modify config file
cd /usr/local/zabbix/etc/
sed -i "s/Server=.*/Server=${SERVER_IP}/g" $CONFG_PATH
sed -i "s/ServerActive=.*/ServerActive=${SERVER_IP}/g" $CONFG_PATH
sed -i "s/ZABBIX_BIN=.*/ZABBIX_BIN=\/usr\/local\/zabbix\/sbin\/zabbix_agentd/g"? /usr/local/src/zabbix-3.2.3/misc/init.d/fedora/core5/zabbix_agentd
cp /usr/local/src/zabbix-3.2.3/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
chkconfig zabbix_agentd on
sed -i '$a\zabbix? ? ALL=(ALL)? ? ? NOPASSWD: ALL' /etc/sudoers
systemctl daemon-reload
/etc/init.d/zabbix_agentd start
netstat -nltp | grep zabbix