首页 > 移动平台 > 详细

自动化运维之系统监控Nagios(一)安装部署

时间:2015-11-25 19:33:54      阅读:359      评论:0      收藏:0      [点我收藏+]

一、系统环境

  操作系统:CentOS 7

  软件版本:Nagios 4.11

二、部署脚本

 安装脚本如下:  

#!/bin/sh

#mysql密码

mysqlps=123

#nagios账户密码

nagiospa=123

#nagiosadmin账户密码

nagadps=123

#获取本机IP

hostip=` ip a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk ‘{print $2}‘|sed "s%/24%%g" `


#安装LAMP

yum -y install httpd mariadb-server mariadb php php-mysql php-gd php-pear
systemctl start httpd
systemctl enable httpd
systemctl start mariadb
systemctl enable mariadb

expect <<EOF
	set timeout -1
	spawn mysql_secure_installation
	expect {
		"*(enter for none):" { send "\r"; exp_continue }
		"*password:" { send "${mysqlps}\r"; exp_continue }
		"*password:" { send "${mysqlps}\r"; exp_continue }
		"*users?" { send "Y\r"; exp_continue }
		"*remotely?" { send "Y\r"; exp_continue }
		"*it?" { send "Y\r"; exp_continue }
		"*now?" { send "Y\r"; exp_continue }
		}
	expect eof
EOF

#安装Nagios

yum install -y gd gd-devel gcc glibc glibc-common openssl openssl-devel openssl-perl unzip wget

useradd -m nagios

expect <<EOF
	set timeout -1
	spawn passwd nagios
	expect {
		"*password:" { send "${nagiospa}\r";exp_continue }
		"*password:" { send "${nagiospa}\r" }
		}
	expect eof
EOF


groupadd nagcmd

usermod -a -G nagcmd nagios

usermod -a -G nagcmd apache

cd /tmp

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz

tar xzf nagios-4.1.1.tar.gz

cd nagios-4.1.1

./configure --with-command-group=nagcmd

make all

make install

make install-init

make install-commandmode

make install-config

make install-webconf

make install-exfoliation

make install-classicui

#安装nagios-plugins、nrpe

yum install -y nagios-plugins* nrpe*

echo -e "#‘check_nrpe‘ command definition
define command{
\tcommand_name check_nrpe
\tcommand_line \$USER1\$/check_nrpe -H \$HOSTADDRESS\$ -c \$ARG1\$
}">>/usr/local/nagios/etc/objects/commands.cfg

sed -i "s/nrpe_user=nrpe/nrpe_user=nagios/g" /etc/nagios/nrpe.cfg

sed -i "s/nrpe_group=nrpe/nrpe_group=nagcmd/g" /etc/nagios/nrpe.cfg

sed -i "s%/usr/local/nagios/libexec%/usr/lib64/nagios/plugins%g" /usr/local/nagios/etc/resource.cfg

#设置nagios Web 访问密码

expect <<EOF
	set timeout -1
	spawn htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
	expect {
		"*password:" { send "${nagadps}\r";exp_continue }
		"*password:" { send "${nagadps}\r" }
		}
	expect eof
EOF

#修复假报警

touch /var/www/html/index.html

#重启服务

systemctl restart httpd

ln -s /usr/local/nagios/bin/nagios /usr/bin/

nagios -v /usr/local/nagios/etc/nagios.cfg

systemctl start nrpe
systemctl enable nrpe
systemctl start nagios
chkconfig nagios on
systemctl restart httpd

systemctl status -l nrpe
systemctl status -l nagios
systemctl status -l httpd

echo "请访问http://${hostip}/nagios验证配置!!"


部署完成!

本文出自 “月夜星魂” 博客,请务必保留此出处http://wongkun.blog.51cto.com/2824237/1716843

自动化运维之系统监控Nagios(一)安装部署

原文:http://wongkun.blog.51cto.com/2824237/1716843

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!