版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】一鍵搭建nagios監(jiān)控系統(tǒng)之二腳本解釋篇
由于發(fā)布文章字?jǐn)?shù)有限制。腳本解釋將在這一篇文章里講解。如下:#!
/bin/bash
##
QQ:410018348
##################
nagios
server
configure
########################
installserver()
{
#定義安裝nagios函數(shù)
read
-p
"
Please
input
the
alarm
address
:
"
#報警郵箱
read
-p
"
Please
input
the
login
nagios
user:
"
loginuser
#網(wǎng)頁登錄時帳戶
read
-p
"
Please
input
the
login
nagios
pass:
"
loginpass
#網(wǎng)頁登錄時的密碼
echo
"###############
Install
nagios
server
#################"
yum
-y
install
httpd
php
php-gd
php-xml
php-mbstring
php-ldap
php-pear
php-xmlrpc
httpd-manual
mod_ssl
mod_perl
zlib
libpng
freetype
libart_lgpl
libart_lgpl-devel
libxml*
pango*
#安裝
apache
php
及其他
wget
/sourceforge/nagios/nagios-3.2.3.tar.gz
useradd
nagios
-s
/sbin/nologin
tar
-xvf
nagios-3.2.3.tar.gz
cd
nagios-3.2.3
./configure
--prefix=/usr/local/nagios
make
all
make
install
make
install-init
make
install-config
make
install-commandmode
make
install-webconf
cd
..
#安裝nagios軟件
wget
/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
tar
-xvf
nagios-plugins-1.4.15.tar.gz
cd
nagios-plugins-1.4.15
./configure
make
make
install
cd
..
#安裝nagios監(jiān)控插件
wget
/sourceforge/nagios/nrpe-2.12.tar.gz
tar
-xvf
nrpe-2.12.tar.gz
cd
nrpe-2.12
./configure
make
all
make
install
make
install-plugin
make
install-daemon
make
install-daemon-config
cd
..
#安裝nrpe插件
wget
http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz
tar
-xvf
rrdtool-1.4.7.tar.gz
cd
rrdtool-1.4.7
./configure
--prefix=/usr/local/rrdtool/
&&make
&&make
install
cd
..
#安裝繪圖工具
wget
/repo/pkgs/pnp4nagios/pnp-0.4.12.tar.gz/eb833a4769a5b58aad0ac53cae3e3e9f/pnp-0.4.12.tar.gz
tar
-xvf
pnp-0.4.12.tar.gz
cd
pnp-0.4.12
./configure
--with-nagios-user=nagios
--with-nagios-group-nagios
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool
make
make
all
make
install
make
install-config
make
install-init
cd
..
#安裝繪圖工具##
以上為安裝nagios服務(wù)的一些軟件。
wget
70/somenagios.tar
#這里的我個人找的一些
cpu
,內(nèi)存,及mysql的插件。
打包在這。
tar
-xvf
somenagios.tar
-C
/usr/local/nagios/libexec/
echo
"################install
nagios
server
completed#############"
#nagios安裝完成。
echo
"#################
configure
nagios
server
start###############"
#下面是常規(guī)的一些配置。
htpasswd
-bc
/usr/local/nagios/etc/htpasswd.users
$loginuser
$loginpass
#創(chuàng)建用戶密碼,就是上面要求輸入的內(nèi)容。
#
cgi.cfg
configure#
sed
-i
"s#use_authentication=1#use_authentication=0#g"
/usr/local/nagios/etc/cgi.cfg
#更改use_authentication參數(shù)
#nagios.cfg
configure#
sed
-i
'35i\cfg_file=/usr/local/nagios/etc/objects/hosts.cfg'
/usr/local/nagios/etc/nagios.cfg
#在nagios.cfg里添加
host.cfg
sed
-i
'35i\cfg_file=/usr/local/nagios/etc/objects/services.cfg'
/usr/local/nagios/etc/nagios.cfg
#在nagios.cfg里添加
services.cfg
sed
-i
'35i\cfg_file=/usr/local/nagios/etc/objects/hostgroup.cfg'
/usr/local/nagios/etc/nagios.cfg
#在nagios.cfg里添加
hostgroup.cfg
sed
-i
"s#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg#\#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg#g"
/usr/local/nagios/etc/nagios.cfg
#禁用監(jiān)控本地的配置文件
sed
-i
"s#process_performance_data=0#process_performance_data=1#g"
/usr/local/nagios/etc/nagios.cfg
#更改
process_performance_data
為1
sed
-i
"s/#host_perfdata_command=process-host-perfdata/host_perfdata_command=process-host-perfdata/g"
/usr/local/nagios/etc/nagios.cfg
#開啟
host_perfdata_commandsed
-i
"s/#service_perfdata_command=process-service-perfdata/service_perfdata_command=process-service-perfdata/g"
/usr/local/nagios/etc/nagios.cfg
#開啟service_perfdata_command
#command.cfg
configure#
line1=`sed
-n
'/process-host-perfdata$/='
/usr/local/nagios/etc/objects/commands.cfg`
#查找commands.cfg里
process-host-perfdata的行
line2=`sed
-n
'/process-service-perfdata$/='
/usr/local/nagios/etc/objects/commands.cfg`
#同上
sed
-i
"$(($line1+1))"d
/usr/local/nagios/etc/objects/commands.cfg
#刪除上面找的行的下一行
sed
-i
"$(($line1+1))i\
command_line
/usr/local/nagios/libexec/process_perfdata.pl"
/usr/local/nagios/etc/objects/commands.cfg
#插入新的命令
sed
-i
"$(($line2+1))"d
/usr/local/nagios/etc/objects/commands.cfg
#刪除上面找的行的下一行
sed
-i
"$(($line2+1))i\
command_line
/usr/local/nagios/libexec/process_perfdata.pl"
/usr/local/nagios/etc/objects/commands.cfg
#插入新的命令
echo
'
define
command{
command_name
check_nrpe
command_line
$USER1$/check_nrpe
-H
$HOSTADDRESS$
-c
$ARG1$
-t
30
}
define
command
{
command_name
check_mysql
command_line
$USER1$/check_mysql
-H
$HOSTADDRESS$
-unagdb
-pnagdb
-d
nagdb
}
'>>/usr/local/nagios/etc/objects/commands.cfg
#
在commands.cfg里添加兩條命令。
nrpe及監(jiān)控mysql
#templates.cfg
configure#
echo
'
define
host
{
name
hosts-pnp
register
0
action_url
/nagios/pnp/index.php?host=$HOSTNAME$
process_perf_data
1
}
define
service
{
name
services-pnp
register
0
action_url
/nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data
1
}'>>/usr/local/nagios/etc/objects/templates.cfg
#
上面是在templates.cfg里添加性能分析圖表的功能
#pnp
configure#
cp
/usr/local/nagios/etc/pnp/process_perfdata.cfg-sample
/usr/local/nagios/etc/pnp/process_perfdata.cfg
cp
/usr/local/nagios/etc/pnp/npcd.cfg-sample
/usr/local/nagios/etc/pnp/npcd.cfg
cp
/usr/local/nagios/etc/pnp/rra.cfg-sample
/usr/local/nagios/etc/pnp/rra.cfg
chown
-R
nagios:nagios
/usr/local/nagios/etc/pnp/*
#上面把pnp的模板文件改成真的配置文件
并授權(quán)
sed
-i
's#LOG_LEVEL
=
0#LOG_LEVEL
=
2#g'
/usr/local/nagios/etc/pnp/process_perfdata.cfg
#更改
LOG_LEVEL
為2
#contacts.cfg
configure#
sed
-i
"s#nagios@localhost#$email#g"
/usr/local/nagios/etc/objects/contacts.cfg
clear
#更改contacts.cfg里面的聯(lián)系人為所輸入的聯(lián)系人
echo
"###################
nagios
server
install
and
configure
completed,plase
add
hosts
and
services
then
start
it
##################"
}
#以上nagios安裝及配置完成。
restartnagios(){
#
這里是定義nagios,nrpe,及apache重啟的函數(shù)
echo
"stopping
"
service
nagios
stop
#nagios
stop
killall
-9
nrpe
#nrpe
stop
service
httpd
stop
#apache
stop
echo
"starting
"
service
nagios
start
#nagios
start
/usr/local/nagios/bin/nrpe
-c
/usr/local/nagios/etc/nrpe.cfg
-d
#
nrpe
start
service
httpd
start
#apache
start
}
addservices(){
#這里定義了在nagios端添加客戶機(jī)的函數(shù)
read
-p
"please
input
the
alias
name
:
"
host
#輸入添加機(jī)器別名
read
-p
"please
input
the
clint
ip
:
"
ip
#輸入添加機(jī)器的ip
echo
"define
host
{
host_name
$host
use
linux-server,hosts-pnp
alias
nagios
server
address
$ip
contact_groups
admins
check_command
check-host-alive
max_check_attempts
5
notification_interval
10
notification_period
24x7
notification_options
d,u,r
}"
>>
/usr/local/nagios/etc/objects/hosts.cfg
#在hosts.cfg里添加一個主機(jī)
(參數(shù)的意思可以在網(wǎng)上看下)
echo
"define
hostgroup
{
hostgroup_name
myserver
alias
myserver
members
$host
}"
>>/usr/local/nagios/etc/objects/hostgroup.cfg
#在hostgroup.cfg里添中一個主機(jī)組,$host就是添加的別名
是添加監(jiān)控的具體服務(wù)。
echo
"define
service
{
host_name
$host
use
local-service,services-pnp
service_description
CPU
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_cpu
}
#監(jiān)控客戶機(jī)CPU
define
service
{
host_name
$host
use
local-service,services-pnp
service_description
CPU_load
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_load
}
#監(jiān)控客戶機(jī)負(fù)載
define
service
{
host_name
$host
use
local-service,services-pnp
service_description
HTTP
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_http
}
#監(jiān)控客戶機(jī)http服務(wù)
define
service
{
host_name
$host
use
local-service,services-pnp
service_description
MEMORY
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_mem
}
#監(jiān)控客戶機(jī)的內(nèi)存使用情況
define
service
{
host_name
$host
service_description
connect-count
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_ips
}
#監(jiān)控客戶機(jī)的連接情況
define
service
{
host_name
$host
service_description
DISK
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_disk
}
#監(jiān)控客戶機(jī)的硬盤分區(qū)使用情況
define
service
{
host_name
$host
service_description
mysql
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_mysql
}
#監(jiān)控客戶機(jī)的mysql監(jiān)控狀態(tài)
define
service
{
host_name
$host
service_description
PING
use
local-service,services-pnp
check_period
24x7
max_check_attempts
4
normal_check_interval
1
retry_check_interval
1
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_ping!100.0,20%!500.0,60%
}
#監(jiān)控客戶機(jī)的ping是否正常
define
service
{
host_name
$host
use
local-service,services-pnp
service_description
FTP
check_period
24x7
max_check_attempts
4
normal_check_interval
60
retry_check_interval
10
contact_groups
admins
notification_interval
10
notification_period
24x7
notification_options
w,u,c,r
check_command
check_nrpe!check_ftp
}
#監(jiān)控客戶機(jī)的ftp服務(wù)
"
>>/usr/local/nagios/etc/objects/services.cfg
#把上面內(nèi)容添加到services.cfg里面(參數(shù)的意思可以在網(wǎng)上看下)echo
"###############
Add
services
completed
########"
}
#########################
nagios
configure
completed
########################
#以上為nagios服務(wù)端配置。
#######################
client
server
configure
########################
#以下為被監(jiān)控端配置
clientnagios()
{
#定義客戶機(jī)的安裝配置
###
install
soft###
read
-p
"Please
input
the
nagios
server
ip
:
"
nagiosip
#輸入naiogs服務(wù)端ip
read
-p
"Please
input
the
mysql
password
:
"
mysqlpass
#輸入本機(jī)的mysql密碼。
useradd
nagios
yum
install
zlib
libpng
freetype
libart_lgpl
libart_lgpl-devel
libxml*
pango*
#安裝所需要的包
wget
/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
tar
-xvf
nagios-plugins-1.4.15.tar.gz
cd
nagios-plugins-1.4.15
./configure
make
make
install
cd
..
wget
/sourceforge/nagios/nrpe-2.12.tar.gz
tar
-xvf
nrpe-2.12.tar.gz
cd
nrpe-2.12
./configure
make
all
make
install
make
install-plugin
make
install-daemon
make
install-daemon-config
cd
..
#以上為安裝被監(jiān)控機(jī)所需要的軟件
wget
70/somenagios.tar
tar
-xvf
somenagios.tar
-C
/usr/local/nagios/libexec/
#這里是個人找的幾個監(jiān)控插件
###
install
completed
###
###
configure
####
rm
/usr/local/nagios/etc/nrpe.cfg
#刪除安裝的nrpe.cfg配置文件
cat
>>/usr/local/nagios/etc/nrpe.cfg<<EOF
#添加以下內(nèi)容到nrpe.cfg配置文件里。主要就是一些監(jiān)控本機(jī)的命令,供nagios服務(wù)端調(diào)用
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=$nagiosip
dont_blame_nrpe=1
debug=1
command_timeout=30
connection_timeout=300
command[check_http]=/usr/local/nagios/libexec/check_http
-H
-u
/index.php
-t
60
command[check_disk]=/usr/local/nagios/libexec/check_disk
-w
15%
-c
10%
-A
-i
'/dev/shm'
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh
command[check_ips]=/usr/local/nagios/libexec/ip_conn.sh
400
600
command[check_load]=/usr/local/nagios/libexec/check_load
-w
14,12,10
-c
18,15,12
command[check_ftp]=/usr/local/nagios/libexec/check_ftp
-w
10
-c
60
EOF
mysql
-uroot
-p"$mysqlpass"
<<EOF
create
database
nagdb;
grant
all
on
nagdb.*
to
nagdb@"$nagiosip"
identified
by
'nagdb';
flush
privileges;
\q
EOF
#這里是創(chuàng)建一個只能是nagios服務(wù)端訪問的庫。監(jiān)控mysql狀態(tài)是需有的。
killall
-9
nrpe
/usr/local/nagios/bin/nrpe
-c
/usr/local/nagios/etc/nrpe.cfg
-d
#重啟被監(jiān)控機(jī)的nrpe服務(wù)
############
configure
completed
############
}
#客戶機(jī)配置完成
real=`grep
-l
'\^H'
/root/.bash_profile`
if
[
$?
-eq
1
];then
echo
'stty
erase
^H'
>>
/root/.bash_profile
source
/root/.bash_profile
#這幾行主要就是讓在使用read鍵時能使用回刪鍵。寫錯了,回刪了,重啟寫。不用這段的話,回刪鍵會變成亂碼。
fi
echo
-e
'\033[0;33;1m
#################nagios##################
\033[0m'
#讓echo能弄點(diǎn)顏色出來好看點(diǎn)。。。
echo
"nagios
server
install
a
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 初三學(xué)生關(guān)于誠信的演講稿5篇
- 寫給老婆的檢討書范文(6篇)
- 關(guān)于文員類實(shí)習(xí)報告模板錦集6篇
- 產(chǎn)品安全檢測員工作規(guī)范
- 買賣賒賬合同條款范本
- 軟件質(zhì)量管理評審修訂制度
- 虛擬現(xiàn)實(shí)行業(yè)勞動合同范本
- 綜合格斗比賽場地租賃合同
- 火車維修焊接施工合同
- 醫(yī)院建設(shè)項目招標(biāo)流程
- 2024年公安智能外呼項目合同
- 河南省信陽市2024-2025學(xué)年七年級上學(xué)期期中歷史試題(含答案)
- GB/T 44570-2024塑料制品聚碳酸酯板材
- 2024年學(xué)校食堂管理工作計劃(六篇)
- 體育賽事組織服務(wù)協(xié)議
- 天車工競賽考核題
- 民辦非企業(yè)單位理事會制度
- 臨床輸血的護(hù)理課件
- 民生銀行在線測評真題
- 人教版(PEP)小學(xué)六年級英語上冊全冊教案
- 第二章 旅游線路類型及設(shè)計原則
評論
0/150
提交評論