zabbix_agentd-install.sh (指令碼部署zabbix_agentd服務),

來源:互聯網
上載者:User

zabbix_agentd-install.sh (指令碼部署zabbix_agentd服務),

原文發表於cu:2016-05-20

基於http://www.cnblogs.com/netonline/p/7406598.html(http://blog.chinaunix.net/uid-26168435-id-5730201.html),寫了1個簡單的指令碼來簡化zabbix_agnetd的部署。
指令碼運行注意事項:
1. script與zabbix-3.0.1.tar.gz放置在同一個目錄運行;
2. 由於zabbix安裝檔案的名字未採用變數,在script中已寫死,雖然可變更,但需要同步修改腳其中對應的地方;
3. script中涉及到變更運行目錄,所以請使用"source" 或 ". "運行script,如: "source xx.sh"或". ./xx.sh";
4. script運行基於centos6.x,請注意與centos7.x的命令區別,這裡主要是centos7.x預設沒有iptables,需要提前準備好iptables的環境。

#!/bin/bash# Program:#     Automatic install zabbix_agentd-3.0.1 in centos-6.x-x86_64 by the scripts.# Usage:#     It relate to change directory, please use source or . to execute this scripts, the others methods will fail.# History:#     2016/05/10    v0.1PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport 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 1fi# 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]: " zabbixserveripcheckip $zabbixserveripecho "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 ACCEPTiptables -I OUTPUT -d $zabbixserverip -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPTservice 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 0fi# Create zabbix group and user.groupadd zabbixuseradd -g zabbix -s /sbin/nologin zabbix# Install zabbix_agentdcur_dir=$(pwd)tar -zxvf $cur_dir/zabbix-3.0.1.tar.gz -C /usr/local/src/cd /usr/local/src/zabbix-3.0.1 ./configure --prefix=/usr/local/zabbix --enable-agent && make && make installcd ~# 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.confsed -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.confsed -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.1/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentdchown zabbix:zabbix /etc/rc.d/init.d/zabbix_agentdchmod +x /etc/rc.d/init.d/zabbix_agentdsed -i 's|BASEDIR=/usr/local|BASEDIR=/usr/local/zabbix|g' /etc/rc.d/init.d/zabbix_agentdchkconfig --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.1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.