Use shell to automatically install and deploy Nagios

Source: Internet
Author: User

#! /Bin/sh
# This script is auto_nagios
# Version 1.0.0
# Copyright (c) zhaohaihua zhaohha@ufida.com.cn
Export install_dir = "/usr/src/pack_nagios"
Dir = 'pwd'
Tar zxf $ dir/pack_nagios.tar.gz-C/usr/src
Login_nagios_user = chanjet
Fetion_id = 1, 15910683240
Fetion_passwd = zhh19861213
# Notify email
EMAIL = zhaohh@chanjet.com
LOCAL_HOSTNAME = 'hostname'
CHEK_HOSTNAME = chanjet21
# Localhost ip
IP = 'ifconfig eth0 | grep inet addr | awk {print $2} | cut-d:-f2'
# Be monitored host ip
CHEK_IP = 192.168.0.3
# Check if user is root
If [[$ LOGNAME! = "Root"]; then
Printf "Error: You must be root to run this script! "
Exit 1
Fi
 
# Read config
. Config. sh
. Showcolor. sh
 
# Function to install all
Install_all (){
Install_apache
Install_nagios
Install_plugins
Install_nrpe
Install_fetion
. $ Dir/define. sh
Auth_user
}
 
# Function to install partion
Install_partion (){
Install_apache
Install_nagios
Install_plugins
Install_fetion
. $ Dir/define. sh
Auth_user
}
 
# Function to only install nrpe
Function Install_nrpe_only (){
Useradd nagios-s/sbin/nologin
Cd $ install_dir
Tar zxf restart nrpe_version.tar.gz
Cd $ NRPE_VERSION
$ NRPE_COMPILE_COMMAND
Sleep 2
Make all & make install
Sleep 2
# Cp $ NRPE_PREFIX/libexec/check_nrpe $ NAGIOS_PREFIX/libexec/
# Cp $ NAGIOS_PREFIX/libexec/{check_disk, check_load, check_ping, check_procs} $ NRPE_PREFIX/libexec/
Mkdir $ NRPE_PREFIX/etc
Chown-R nagios. nagios $ NRPE_PREFIX/etc
Cp $ install_dir/$ NRPE_VERSION/sample-config/nrpe. cfg $ NRPE_PREFIX/etc/
Cd ..
Rm-rf $ NRPE_VERSION
Echo "nrpe install is OK, but you need to cp NRPE_PREFIX/libexec/check_nrpe NAGIOS_PREFIX/libexec/; cp NAGIOS_PREFIX/libexec/{check_disk, check_load, check_ping, check_procs} NRPE_PREFIX/libexec /"
Sleep 3
}
 
 
# Function to install apache
Install_apache (){
Cd $ install_dir
Tar zxf paiapache_version.tar.gz
Cd $ APACHE_VERSION
$ APACHE_COMPILE_COMMAND
Sleep 2
Make & make install
Sleep 2
Cd ..
Rm-rf $ APACHE_VERSION
Echo/usr/local/apache2/bin/>/etc/profile
Ln-s/usr/local/apache2/bin/apachectl
Sed-I/^ # ServerName www/cServerName $ LOCAL_HOSTNAME: 80/usr/local/apache2/conf/httpd. conf
Sed-I/^ * DirectoryIndex/c DirectoryIndex. php index.html. var/usr/local/apache2/conf/httpd. conf
Cat>/usr/local/apache2/conf/httpd. conf <EOF
ScriptAlias/nagios/cgi-bin/usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow, deny
Allow from all
AuthName "Nagios Access"
AuthUserFile/usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias/nagios/usr/local/nagios/share
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow, deny
Allow from all
AuthName "nagios Access"
AuthUserFile/usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
EOF
Apachectl start
Echo "apache install is OK"
Sleep 3
}
 
# Function to install_nagios
Install_nagios (){
Useradd nagios-s/sbin/nologin
Cd $ install_dir
Tar zxf restart nagios_version.tar.gz
Cd $ NAGIOS_VERSION
$ NAGIOS_COMPILE_COMMAND
Sleep 2
Make all
Make install
Make install-init
Make install-commandmode
Make install-config
Sleep 2
Cd ..
Rm-rf $ NAGIOS_VERSION
Echo "nagios install is OK"
Sleep 3
}
# Function to Install_nagios-plugins
Install_plugins (){
Cd $ install_dir
Tar zxf zookeeper nagios_plugins_version#.tar.gz
Cd $ {NAGIOS_PLUGINS_VERSION}
$ NAGIOS_PLUGINS_COMPILE_COMMAND
Sleep 2
Make; make install
Sleep 2
Cd ..
Rm-rf $ {NAGIOS_PLUGINS_VERSION}
Echo "nagios-plugins install is OK"
Sleep 3
}
 
 
# Function to install nrpe
Function Install_nrpe (){
Cd $ install_dir
Tar zxf restart nrpe_version.tar.gz
Cd $ NRPE_VERSION
$ NRPE_COMPILE_COMMAND
Sleep 2
Make all & make install
Sleep 2
Cp $ NRPE_PREFIX/libexec/check_nrpe $ NAGIOS_PREFIX/libexec/
Cp $ NAGIOS_PREFIX/libexec/{check_disk, check_load, check_ping, check_procs} $ NRPE_PREFIX/libexec/
Mkdir $ NRPE_PREFIX/etc
Cp $ install_dir/$ NRPE_VERSION/sample-config/nrpe. cfg $ NRPE_PREFIX/etc/
Chown-R nagios. nagios $ NRPE_PREFIX/libexec
Chown-R nagios. nagios $ NRPE_PREFIX/etc
Chown-R nagios. nagios $ NAGIOS_PREFIX/libexec
Chown-R nagios. nagios $ NAGIOS_PREFIX/etc
Cd ..
Rm-rf $ NRPE_VERSION
Echo "nrpe install is OK"
Sleep 3
}
 
# Function to install fetion
Install_fetion (){
Cd $ install_dir/fetion
Mkdir-p $ NAGIOS_PREFIX/libexec/sms
Cp libACE * libcrypto * libssl * fetion $ NAGIOS_PREFIX/libexec/sms
Echo "fetion install is OK"
Sleep 3
}
# Function to create web auth user
Function Auth_user (){
Chown-R nagios. nagios $ NAGIOS_PREFIX/etc
Clear
Read-p "Please enter web author:" AUTH_USER
$ APACHE_PREFIX/bin/htpasswd-c $ NAGIOS_PREFIX/etc/htpasswd $ AUTH_USER
Cat <EOF
 
......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.