腳本部署zabbix_agentd

傳送門:
Zabbix的Server端的源碼安裝:http://www.reibang.com/p/a861afe42394
LNMP的源碼安裝:http://www.reibang.com/p/4699bcb04633
Zabbix-3.0的Agent端在CentOS 7.3的源碼安裝實踐:http://www.reibang.com/p/2e4c535ca53a

Zabbix_agent的腳本安裝

環(huán)境準備:

1.提前下載zabbix軟件包


軟件獲取
Zabbix官網(wǎng)下載地址:http://www.zabbix.com/download.php

獲取3.0.0的LTS版地址
[root@localhost ~]# wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.0/zabbix-3.0.0.tar.gz

2.依賴軟件

[root@localhost ~]# yum -y install net-tools gcc gcc-c++ vim
    ```
3.修改主機名旺上,關閉selinux霞揉,配置iptables

[root@localhost ~]# hostnamectl set-hostname agent2
[root@agent2 ~]# shutdown -r now
[root@agent2 ~]# setenforce 0
[root@agent2 ~]# systemctl stop firewalld.service
[root@agent2 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@agent2 ~]# yum -y install iptables-services

配置iptables

[root@agent2 ~]# vim /etc/sysconfig/iptables

sample configuration for iptables service

you can edit this manually or use system-config-firewall

please do not ask us to add additional ports/services to this default configuration

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.81.11 -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
-A OUTPUT -d 192.168.81.11 -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

[root@agent2 ~]# service iptables save
[root@agent2 ~]# service iptables restart
[root@agent2 ~]# iptables -L
[root@agent2 ~]# systemctl enable iptables.service

######創(chuàng)建腳本(ps:如果zabbix的軟件版本號不一樣铛只,需要修改)

[root@agent2 ~]# vim zabbix_agentd.sh

!/bin/bash

Program:

Automatic install zabbix_agentd-3.0.0 in centos-6.x-x86_64 by the scripts.

Usage:

It relate to chage directory, please use source or . to execute this scripts, the others methods will fail.

History:

2017/04/22 v0.1

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

Check if user is root.

if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install zabbix_agentd!"
exit 1
fi

Function: check the zabbix_server ip address which has be inputed.

checkip() {
echo $1 | egrep -q '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$' > /dev/null
if [ $? -ne 0 ]; then
echo "Error: Please input correct format IP address!"
exit 1
fi

ipaddr=$1
ip1=echo $ipaddr | awk -F. '{print $1}'
ip2=echo $ipaddr | awk -F. '{print $2}'
ip3=echo $ipaddr | awk -F. '{print $3}'
ip4=echo $ipaddr | awk -F. '{print $4}'

for num in $ip1 $ip2 $ip3 $ip4; do
if [ $num -ge 255 ] || [ $num -lt 0 ]; then
echo "Error: Please input correct format IP address!"
exit 1
fi
done

return 0
}

Input zabbix_server's ip address.

read -p "Please input zabbix_server's ip address[ie: 192.168.1.1]: " zabbixserverip
checkip $zabbixserverip
echo "OK! Your zabbix_server is ${zabbixserverip}!"

Set iptables rules, zabbix server will detect agentd by tcp 10050, and zabbix_agentd will send trapper to server by tcp 10051.

iptables -I INPUT -s $zabbixserverip -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
iptables -I OUTPUT -d $zabbixserverip -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
service iptables save

Check selinux.

if [ $(getenforce) = "Enforcing" ]; then
sed -i 's|SELINUX=enforcing|SELINUX=disabled|g' /etc/selinux/config ; sed -i 's|SELINUXTYPE=targeted|#SELINUXTYPE=targeted|g' /etc/selinux/config && setenforce 0
fi

Create zabbix group and user.

groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix

Install zabbix_agentd

cur_dir=$(pwd)
tar -zxvf $cur_dir/zabbix-3.0.0.tar.gz -C /usr/local/src/
cd /usr/local/src/zabbix-3.0.0
./configure --prefix=/usr/local/zabbix --enable-agent && make && make install
cd ~

Add soft link to zabbix_agentd execute file.

ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/

Modify zabbix_agentd config file.

sed -i "s|Server=127.0.0.1|Server=${zabbixserverip}|g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i '262s|# Include=/usr/local/etc/zabbix_agentd.conf.d/|Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/|g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's|# UnsafeUserParameters=0|UnsafeUserParameters=1|g' /usr/local/zabbix/etc/zabbix_agentd.conf

Set zabbix_agentd automatic start scripts.

cp /usr/local/src/zabbix-3.0.0/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
chown zabbix:zabbix /etc/rc.d/init.d/zabbix_agentd
chmod +x /etc/rc.d/init.d/zabbix_agentd
sed -i 's|BASEDIR=/usr/local|BASEDIR=/usr/local/zabbix|g' /etc/rc.d/init.d/zabbix_agentd
chkconfig --level 35 zabbix_agentd on

Start zabbix_agentd service.

service zabbix_agentd start

Check zabbix_agentd service.

if [ $(netstat -tnlp | grep zabbix_agentd | awk '{print $7}' | awk -F/ '{print $2}') = "zabbix_agentd" ]; then
echo -e "\033[32m [INFO]Zabbix_agentd has installed and started! \033[0m"
else
echo -e "\033[31m [ERROR]Zabbix_agentd has not started! \033[0m"
fi

Clean install package.

rm -rf /usr/local/src/zabbix-3.0.0

#######運行腳本(腳本需要和zabbix安裝包在一個目錄下)

[root@agent2 ~]# sh zabbix_agentd.sh
Please input zabbix_server's ip address[ie: 192.168.1.1]: 192.168.81.11


![image.png](http://upload-images.jianshu.io/upload_images/5314324-c422955165bc2d8a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末惭等,一起剝皮案震驚了整個濱河市嫁乘,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌妖异,老刑警劉巖勇凭,帶你破解...
    沈念sama閱讀 219,366評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異埠巨,居然都是意外死亡历谍,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評論 3 395
  • 文/潘曉璐 我一進店門辣垒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來望侈,“玉大人,你說我怎么就攤上這事勋桶⊥蜒茫” “怎么了?”我有些...
    開封第一講書人閱讀 165,689評論 0 356
  • 文/不壞的土叔 我叫張陵例驹,是天一觀的道長捐韩。 經(jīng)常有香客問我,道長鹃锈,這世上最難降的妖魔是什么荤胁? 我笑而不...
    開封第一講書人閱讀 58,925評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮屎债,結(jié)果婚禮上仅政,老公的妹妹穿的比我還像新娘。我一直安慰自己盆驹,他們只是感情好圆丹,可當我...
    茶點故事閱讀 67,942評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著躯喇,像睡著了一般辫封。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,727評論 1 305
  • 那天倦微,我揣著相機與錄音妻味,去河邊找鬼。 笑死璃诀,一個胖子當著我的面吹牛弧可,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播劣欢,決...
    沈念sama閱讀 40,447評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼棕诵,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了凿将?” 一聲冷哼從身側(cè)響起校套,我...
    開封第一講書人閱讀 39,349評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎牧抵,沒想到半個月后笛匙,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,820評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡犀变,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,990評論 3 337
  • 正文 我和宋清朗相戀三年妹孙,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片获枝。...
    茶點故事閱讀 40,127評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡蠢正,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出省店,到底是詐尸還是另有隱情嚣崭,我是刑警寧澤,帶...
    沈念sama閱讀 35,812評論 5 346
  • 正文 年R本政府宣布懦傍,位于F島的核電站雹舀,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏粗俱。R本人自食惡果不足惜说榆,卻給世界環(huán)境...
    茶點故事閱讀 41,471評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望源梭。 院中可真熱鬧娱俺,春花似錦、人聲如沸废麻。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽烛愧。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間怜姿,已是汗流浹背慎冤。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留沧卢,地道東北人蚁堤。 一個月前我還...
    沈念sama閱讀 48,388評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像但狭,于是被迫代替她去往敵國和親披诗。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,066評論 2 355

推薦閱讀更多精彩內(nèi)容