1. 程式人生 > >nagios 安裝指令碼

nagios 安裝指令碼

研究了一段時間nagios,其實安裝很簡單,但頭懶得做,要求指令碼啊。。。
#! /usr/bin/env bash

# Author: Lawrency Meng
# Date: 2013-3-1
# Version: v1.0.2
# Description: the nagios install sh

# dirs cont
TOP_DIR=`cd $(dirname "$0") && pwd`

SRC_DIR="${TOP_DIR}/src"
DEPEND="${TOP_DIR}/apt"
PLUGIN_DIR="${TOP_DIR}/plugin"
ETC_DIR="${TOP_DIR}/etc"
NAGIOS_DIR="/usr/local/nagios/"
UNTAR_TMP="/tmp/nagios/"
PLUGIN_DIR="$NAGIOS_DIR/libexec/"

# srcs cont
CORE_SRC="nagios-3.4.4.tar.gz"
NRPE_SRC="nrpe-2.14.tar.gz"
PLUGIN_SRC="nagios-plugins-1.4.16.tar.gz"
NDOUTILS_SRC="ndoutils-1.5.2.tar.gz"

# check the depends in apt file
function check_depends(){
	#apt-get update
        while read -r line
        do
            dpkg -l $line > /dev/null || apt-get install -y $line
        done < $DEPEND
}

# check the use input
function check_input(){
        if [ "x${CHOOSE}" == "x" ]; then
                return "ok"
        fi
        if [[ "${CHOOSE}" =~ (c|C|n|N|p|P|d|D) ]]; then
                return "err"
        else
                return "err"
        fi
}

# check the untar tmp dir
function check_dir(){
        if [ ! -z ${UNTAR_TMP} ]; then
                sudo mkdir -p ${UNTAR_TMP}
                echo "[Info] Create the untar temp dir ${UNTAR_TMP}"
        fi
}


# create users and groups 
function create_UG(){
        if [ ! `getent passwd nagios` > /dev/null ]; then
                echo "[Info] Creating a user called nagios..."
                useradd -U -G sudo -s /bin/bash -m nagios 
                groupadd nagcmd
                usermod -a -G nagcmd www-data
                get_sudo
		cp -r $TOP_DIR /home/nagios/
		chown -R nagios:nagios /home/nagios/
        else
                echo "[Info] user nagios is exist..."
        fi
}

# give sudo priv
function get_sudo(){
        echo "[Info] Giving nagios user passwordless sudo priviledges"
        grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
                echo "#includedir /etc/sudoers.d" >> /etc/sudoers
            ( umask 226 && echo "nagios ALL=(ALL) NOPASSWD:ALL" \
                     > /etc/sudoers.d/50_nagios_sh )
}

#  switch user
function switch_user(){
	chown -R nagios:nagios /usr/local/nagios/
}

# clean install files
function clean(){
	if [ $1 = 'PLUGIN' ]; then
		cd ${UNTAR_TMP}/${PLUGIN_SRC/.tar.gz/}
		make clean
	fi
	
	if [ $1 = 'NRPE' ]; then
		cd ${UNTAR_TMP}/${NRPE_SRC/.tar.gz/}		
		make clean
		[ `iptables --list | grep 'nrpe' > /dev/null` ] && sudo iptables -D INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
		[ `grep -i 'nrpe' /etc/services > /dev/null` ] && sed -i "/nrpe/ d" /etc/services
        	[ `grep -i "iptables-restore" /etc/network/interfaces > /dev/null` ] && sed -i "/iptables-restore/ d" /etc/network/interfaces	
		
	fi
	if [ $1 = 'CORE' ]; then
		cd ${UNTAR_TMP}/${CORE_SRC%%-*}
		make clean
	fi
}

# core install func
function core_install(){
        switch_user nagios
        cd ${SRC_DIR}
        check_dir
        sudo tar -zxvf ${CORE_SRC} -C ${UNTAR_TMP}  && cd ${UNTAR_TMP}/${CORE_SRC%%-*}
        ./configure --with-command-group=nagcmd
	make clean
        make all
        make install && make install-init && make install-config && make install-commandmode
        echo "[Info] Install nagios core successfully..."
        switch_user root
}

function nrpe_install(){
        switch_user nagios
	`clean "NRPE"` 
        cd ${SRC_DIR}
        check_dir
        sudo tar -xzvf ${NRPE_SRC} -C ${UNTAR_TMP} && cd ${UNTAR_TMP}/${NRPE_SRC/.tar.gz/}
        ./configure --with-ssl=/usr/lib/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu/ --enable-command-args
        make all
        make install-plugin && make install-daemon && make install-daemon-config && make install-xinetd
        cp -r ${ETC_DIR} ${NAGIOS_DIR}/etc/
        sed -i "s/dont_blame_nrpe=0/dont_blame_nrpe=1/g" /usr/local/nagios/etc/nrpe.cfg
	[ ! `grep -i 'nrpe' /etc/services > /dev/null` ] && echo -e "nrpe\t5666/tcp\t#NRPE" >> /etc/services
	service xinetd restart
	[ ! `iptables --list | grep 'nrpe' > /dev/null` ] && sudo iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
	iptables-save
	[ ! `grep -i "iptables-restore" /etc/network/interfaces > /dev/null` ] && sed -i "/iface eth0/a\\pre-up iptables-restore < /etc/iptables.up.rules" /etc/network/interfaces 
        [ ! "`netstat -at | grep nrpe`" ] && echo "[info] Install nagios nrpe successfully..."
        switch_user root
}

function plugin_install(){
        switch_user
	`clean "PLUGIN"`
        cd ${SRC_DIR}
        check_dir
        tar -xzvf ${PLUGIN_SRC} -C ${UNTAR_TMP}  && cd ${UNTAR_TMP}/${PLUGIN_SRC/.tar.gz/}
        ./configure --with-nagios-user=nagios --with-nagios-group=nagios
        make && make install
	cp ${PLUGIN_DIR}/* /usr/local/nagios/libexec/ 
        [ -d "/usr/local/nagios/libexec" ] && echo "[Info] Install nagios plugin successfully..."
        echo "[Info] Nagios plugin default install in dir: /usr/local/nagios/libexec/"
        switch_user 
}

function main(){
        
        check_depends
        create_UG
        while true
        do
                echo "[Info] Please choose to install nagios modules: "
                echo "[c] Nagios core" 
                echo "[n] Nagios NRPE"
                echo "[p] Nagios plugin"
#                echo "[d] Nagios NDOUtils"
                echo "[e] exit..."
		
                read -p ">>>>" CHOOSE
		
                case "${CHOOSE}" in
                        [cC]) core_install ;;
                        [nN]) nrpe_install ;;
                        [pP]) plugin_install ;;
#                        [dD]) ndoutil_install ;;
                        [eE]) exit 0;;
                        *) echo "[Err] only accept input [ cC | nN | pP | dD | eE ]" ;;
                esac
        done
}

main 
[email protected]

相關推薦

nagios 安裝指令碼

研究了一段時間nagios,其實安裝很簡單,但頭懶得做,要求指令碼啊。。。#! /usr/bin/env bash # Author: Lawrency Meng # Date: 2013-3-1 # Version: v1.0.2 # Description: the

Ubuntu下nagios安裝(來源官網)

update gawk ibm plain cert lib account adding resolv Ubuntu下nagios安裝(來源官網) https://assets.nagios.com/downloads/nagioscore/docs/nagioscore

nagios安裝及監控window主機,交換機

allow aec 找不到 src .tar.gz 選項 cto 分析 nor nagios安裝及監控window主機,交換機註:因為文章是後來寫的,所以搭建時遇到的各種問題,都記不起來,反正是歷盡艱辛萬苦,不過會盡量寫下來先上最終的結果,版本為3.2.0以下圖是監控的主機

nagios安裝及監控window主機

com ffffff term img size cto tex ima nagios安裝 nagios安裝及監控window主機

Linux筆記網絡監控之nagios安裝與配置

nagios linux 安裝與配置 nagios簡介 Nagios是一款開源的電腦系統和網絡監視工具,能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網絡設置,打印機等。在系統或服務狀態異常時發出郵件或短信報警第一時間通知網站運維人員,在狀態恢復後發出正常的郵件或短信通

nagios安裝的配置筆記

type ado archive ssh gin word white nag pad 選用的雲主機,省去很多繁瑣的步驟安裝nagios和httpd:[root@fjx ~]# yum install -y nagios httpd [root@fjx ~]# htpas

kickstart自動安裝指令碼;系統延時定時任務的at,crobtab,檔案方式設定定時任務;

kickstart自動安裝指令碼 前提條件:掛載好yum,開啟httpd服務,配置dhcp服務 yum install -y system-config-kickstart system-config-kickstart 點Add 點 Add Netwo

kickstart自動安裝指令碼

###kickstart自動安裝指令碼### 1.在服務端安裝sysytem-config-kickstart服務 2.在服務端安裝httpd服務和dhcpd服務     3.配置dhcpd服務,編輯/etc/dhcpd/dhcpdconf檔案

kickstart自動安裝指令碼及系統定時任務的設定

##kickstart自動安裝指令碼### 1虛擬機器安裝httpd檔案 yum install -y system-config-kickstart httpd 2system-config-kickstart vim ks.cfg(根據新增的檢查是否在這個指令碼中還需新增

LAMP自動安裝指令碼

1 #!/bin/bash 2 # 功能描述:LAMP自動安裝指令碼 3 4 # 初始化 5 if [ "$(cat /etc/system-release | awk '{print $(NF-1)}' | awk -F"." '{print $1}')" -ne 7 ] 6

centos7-ss自動化安裝指令碼

#!/bin/bash #install Shadowsocks on CentOS 7 echo "Installing Shadowsocks................................................." CONFIG_FILE=/etc/shadow

MySQL5.7一鍵安裝指令碼

本文寫作說明:MySQL的配置檔案my.cnf引數調整參考來源於iMySQL | 老葉茶館此指令碼是本博主生產環境中經常使用的進行批量部署mysql服務時採用。指令碼比較陋,寫此處主要是方便自己使用時及時查閱,同時也希望可以幫助初級的DBA同學,指令碼中如有寫法不當之處歡迎拍磚,但是也希望不喜勿噴。 指令碼

Shell-case:服務nginx的安裝指令碼

     之前分享了不少指令碼中的使用的小技巧,今天拿出點實打實的東西來,在我的 github https://github.com/SmartLyu/shell 裡有 nginx 的一個安裝配置包,還有一個關於安裝 nginx 的指令碼,今天就來和大家分享一

Red5一鍵安裝指令碼(Linux&Win):一鍵搭建你的直播平臺

Red5一鍵部署script(Linux&Win):一鍵搭建你的直播平臺 看到bilibili,熊貓TV,鬥魚TV等直播平臺你是不是也很眼紅呢,這裡站長為大夥寫了一個Red5一鍵部署script。 Red5供給基於Flash的流媒體服務的一款基於Java的開源流媒體伺服器。它由Java言語編寫,使

VPS網路優化各種方法彙總——銳速-BBR-BBR魔改版一鍵安裝指令碼

雲主機網路優化各類方式彙總——銳速/BBR/BBR改裝版一鍵部署script       大夥的大有些雲主機都是放在海外的,在海外的伺服器上由於受各類要素影響,就算海外的伺服器都是百兆同享或者G口到大陸下載速率都不是很讓人滿足,而大有些的friend們都用的低廉Linux

VDVESTA一鍵安裝指令碼-VESTACP-PHP7.1-檔案管理器-vDDoSProxy

VDVESTA一鍵部署script/VESTACP/PHP7.1/檔案管理器/vDDoS Proxy 簡介 VDVESTA是一個小型的shellscript,為您的CentOS7 x86_64主動定製並部署VESTACP面板,與官方面板不同的是,此script支援php7。並增加了需付費使用的檔案管理面板

OpenVZ虛擬化(架構)VPS安裝Windows一鍵安裝指令碼

OpenVZ虛擬化(架構)雲主機部署微軟s一鍵部署script 簡介 許多人以為OpenVZ虛擬化的雲主機都沒法部署微軟s,但事實上是可以通過Qemu來部署的,因而伏筆VPS就隨意寫了個破script:一鍵部署VNC+Qemu+附贈一個WinXP的iso VNCscript直接接納的:http://bl

python os庫及第三庫安裝指令碼

目錄 一、os庫基本介紹 1、路徑操作 2、程序管理 3、環境引數 二、第三方庫安裝指令碼 一、os庫基本介紹 os庫提供通用的、基本的作業系統互動功能,包括windows、Mac os、linux os庫是python標準庫,包含幾百個函式 常用路徑操作、經常管理、環境引數等幾類

nginx一鍵安裝指令碼

nginx一鍵安裝指令碼 [[email protected] nginx]# cat nginx_install.sh #!/bin/bash # > File Name: nginx_install.sh # > Author: cc # > mail: [emai

SamsungR一鍵安裝指令碼

本指令碼適用環境: 系統支援:CentOS,Debian,Ubuntu 記憶體要求:≥128M 日期:2018 年 02 月 07 日 關於本指令碼: 一鍵安裝 ShadowsocksR 服務端。 請下載與之配套的客戶端程式來連線。 (以下客戶端只有 Windows 客戶端和