自动安装脚本-------------基于LVMP搭建Nagios 监控

Mysql初始化参数(mysql-5.6.31)

 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --enable-local-infile

Nginx源码安装参数(nginx-1.8.1)
./configure --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/run/nginx/nginx.lock --user=daemon --group=daemon--with-pcre=/root/LNMP/pcre-8.36 --with-threads

PHP源码安装参数(php-5.6.24)
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=daemon --with-fpm-group=daemon --with-config-file-path=/usr/local/php --with-pcre-dir=/usr/local/pcre --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config

-------------------------------------

System:Red Hat Enterprise Linux Server release 6.5

IP:192.168.1.5

-----------------------------------------------------------------------

我这个菜鸟。。。。。还在挣扎中

----------------------------------

这坑啊,爬了一天

直接给出脚本了

主要的也就这几个脚本,感觉安装的Nagios监控服务还有点问题

少了nrpe模块还没有搞定,慢慢来嘛 - -

 

---------------------------安装脚本---main函数--------------------------------------

#!/bin/bash
#Filename:install_nagios.sh
#By losnau
#Date:2016.8.31
###############sh函数#################
. Check_installation_environment.sh        #检查安装需要
. Support_perl_cgi.sh                #- - 
. Install_nagios.sh                #安装nagios服务器,及其插件、扩展
. Configure.sh                    #配置那些什么鬼啦
###################全局变量###############
. Variable
###########################################

function main(){
# 检查安装环境
#    check;
#给Nginx加上对Perl的CGI支持 
#    suport_perl;
#安装nagios服务端
#    install_nagios;
    all_configure;
    echo -e "默认的nagios\n登录帐号:nagiosadmin \n密码\t:123"
}
main;

----------------------------检查环境函数-----------------------

#!/bin/bash
#Filename:Check_installation_environment.sh
#By losnau
#Date:2016.8.31
function check(){
#生成密码需要这个
    echo "-----确保安装httpd服务,只是为了自己儿修改Nagios的登录帐号及密码-------"
    yum -y install httpd* 2&>/dev/null
#建立一个临时目录
    install_configure
#关闭防火墙
    echo "-------------------关闭防火墙----------------------"
    service iptables stop
#设置selinux
    echo "-------------------SELINUX=diable---------------------"
    disable_Selinux
    echo "-------------------检查网络---------------------"
    check_internet;
    echo "-------------------配置网路yum源---------------------"
    network_yum;
}
function  install_configure(){

    if [ -d $tmpdir ]
    then
        rm -rf $tmpdir
        mkdir -p $tmpdir
    else
        mkdir -p $tmpdir
    fi
}
function disable_Selinux()
{
    if [ -s /etc/selinux/config ]; then
        sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
    fi
}
function check_internet(){
    ping -c2 8.8.8.8 >/dev/null
    if [ ! $? -eq 0 ]
    then 
        echo -e "没网络啊,\n失败了啊!"
        exit 1
    else
        echo "-------------------网络检查通过-----------------------"
    fi
}
function network_yum()
{
    cd /etc/yum.repos.d/
    echo "-------------------下载163-repo--------------------"
    wget  http://mirrors.163.com/.help/CentOS6-Base-163.repo    2&>/dev/null
    sed -i "s/\$releasever/6/g" /etc/yum.repos.d/CentOS6-Base-163.repo
    sed -i "s/RPM-GPG-KEY-CentOS-6/RPM-GPG-KEY-CentOS-6/g"  /etc/yum.repos.d/CentOS6-Base-163.repo
    yum clean all        2&>/dev/null
    yum makecache        2&>/dev/null

}

----------------------------------Perl---FCGI---Nginx---------------

#/bin/bash
#Filename:Support_perl_cgi.sh
#By losnau
#Date:2016.8.31
function suport_perl(){
    cd $tmpdir
    yum -y install wget 2&>/dev/null
#安装FCGI模块
    echo "-------------------安装FCGI模块-----------------------------"
    wget http://search.cpan.org/CPAN/authors/id/F/FL/FLORA/FCGI-0.74.tar.gz    2&>/dev/null
    tar xzf FCGI-0.74.tar.gz                1>/dev/null
    cd FCGI-0.74
    perl Makefile.PL                        1>/dev/null
    make                                1>/dev/null
    make install                        1>/dev/null
    cd $tmpdir

#安装FCGI-ProcManager模块
    echo "-------------------安装FCGI-ProcManager模块-----------------------------"
    wget http://www.cpan.org/authors/id/B/BO/BOBTFISH/FCGI-ProcManager-0.24.tar.gz    2&>/dev/null
    tar xzf FCGI-ProcManager-0.24.tar.gz        1>/dev/null
    cd FCGI-ProcManager-0.24
    perl Makefile.PL                        1>/dev/null
    make                                1>/dev/null
    make install                        1>/dev/null
    cd $tmpdir

#安装IO和IO::ALL模块 
    echo "-------------------安装IO和IO::ALL模块 -----------------------------"   
    echo "-------------------IO -----------------------------"  
    wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz 2&>/dev/null
    tar xvf IO-1.25.tar.gz                1>/dev/null
    cd IO-1.25
    perl Makefile.PL                    1>/dev/null
    make                            1>/dev/null
    make install                    1>/dev/null
    cd $tmpdir
    echo "-------------------IO ALL-----------------------------" 
    wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz 2&>/dev/null
    tar xvf IO-All-0.41.tar.gz            1>/dev/null
    cd IO-All-0.41
    perl Makefile.PL                    1>/dev/null
    make                            1>/dev/null
    make install                    1>/dev/null
    cd $tmpdir

#perl-fcgi 
    echo "-------------------下载perl-fcgi  -----------------------------"
    wget http://www.mike.org.cn/wp-content/uploads/2011/07/perl-fcgi.zip 2&>/dev/null
    unzip perl-fcgi.zip                1>/dev/null
    cp perl-fcgi.pl $nginxdir 
}

 

----------------------------Nagios服务端-插件-扩展------------------------------
#!/bin/bash
#Filename:Install_nagios.sh
#By losnau
#Date:2016.8.31
function install_nagios(){

#安装Nagios基础套件
    echo "-------------------安装Nagios基础套件-----------------------------" 
    yum install -y gcc glibc glibc-common xinetd openssl-devel                    2&>/dev/null    
    cd $tmpdir
    wget http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz 2&>/dev/null
    wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz            2&>/dev/null    
    wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz                                                    2&>/dev/null

#安装GD库,Nagios的map需要
    echo "-------------------安装GD库-----------------------------" 
    yum -y install gd gd-devel                        1>/dev/null

#安装Nagios主程序,主程序只是提供一个运行框架
    useradd -s /sbin/nologin nagios
    groupadd nagcmd
    usermod -a -G nagcmd nagios
    usermod -a -G nagcmd $nginxuser
    tar xzf nagios-3.5.0.tar.gz                        1>/dev/null
    cd nagios
      ./configure --prefix=$nagiosdir --with-command-group=nagcmd 1>/dev/null
    make                                        1>/dev/null
    make all                                    1>/dev/null
    make install 1>/dev/null #用于安装主要的程序、CGI及HTML文件
    make install-init #用于生成init启动脚本
    make install-config #用于安装示例配置文件
    make install-commandmode #用于设置相应的目录权限
    chkconfig --add nagios
    chkconfig nagios on
    cd $tmpdir

 #安装nagios插件
    tar xzf nagios-plugins-1.5.tar.gz                    1>/dev/null
    cd nagios-plugins-1.5
    ./configure --prefix=$nagiosdir --with-nagios-user=nagios --with-nagios-group=nagios                                    1>/dev/null
    make                                        1>/dev/null
    make install                                1>/dev/null
    cd $tmpdir

#安装Nagios的扩展NRPE(Nagios Remote Plugin Executor)
    tar xzf nrpe-2.14.tar.gz                        1>/dev/null
    cd nrpe-2.14
    ./configure                                    1>/dev/null
    make                                        1>/dev/null
    make install                                1>/dev/null
    make install-xinetd                            1>/dev/null
    cp $tmpdir/nrpe-2.14/sample-config/nrpe.cfg /usr/local/nagios/etc/
    chown nagios.nagios $nagiosdir/etc/nrpe.cfg
    cd ../ 
}

脚本自己写的

这里给出几个可能错误的原因:

502 Bad Gateway(看nginx日志,很重要,里面有你想要的答案)

请检查php服务是否开启(php-fpm)

请检查perl-fcgi是否OK(可能是权限问题,nginx的user没有/bin/bash权限,修改/etc/passwd文件里面的nginx用户bash)

403 (查看Nagios的日志)

还是各种权限问题,或者nginx的根目录有点问题,用这个脚本我是没碰到过这种错误,但是前面手动安装的时候出现过

参考:一键安装LNMP脚本

知识来源于:

1)Nginx下搭建Nagios监控平台:http://blog.csdn.net/u012063703/article/details/46669293

2)  安装nagios框架 : https://blog.linuxeye.com/312.html

介绍的最详细的当然还是下面那个了

Linux下Nagios的安装与配置: http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

我只是他们的搬运工- - 、、、、、、、、、、、



这里只是一个模版,可以自行修改脚本

posted on 2016-08-30 10:42  losbyday  阅读(268)  评论(0编辑  收藏  举报

导航