您好,登錄后才能下訂單哦!
服務器端:
硬件環境:
虛擬機環境
軟件環境:
Centos-6.2x86-64
Lamp環境
Nagios-3.2.0版本
Nagios-plugins-1.4.13插件版本
Pnp-0.4.14版本
Rrdtool-1.2.14版本
Nrpe-2.12版本
客戶端:
硬件環境:
物理機和虛擬機
軟件環境:
Linux客戶端:
linux服務器端與linux客戶端監控原理:
更多內容: http://exchange.nagios.org/directory/p_w_picpath/93
Centos-6.X-x86-64
Nrpe-2.12版本
Windows客戶端:
Windows2008R2
Windows2003R2
需開啟Snmp服務
服務器端安裝
一,安裝前準備:
1,解決perl編譯問題:
后面編譯的軟件有perl程序,這里要提前設置下環境變量。
批量執行命令如下:
echo'export LC_ALL=C'>>/etc/profile
tail-1 /etc/profile
source/etc/profile
echo$LC_ALL
2,關閉防火墻,安裝完后啟動防火墻。
/etc/init.d/iptablesstop
/etc/init.d/iptablesstart
2.1解決系統時間同步。
echo‘*/5* * * * /usr/sbin/ntpdate time.windows.com’ >>/var/spool/cron/root
[root@nagios~]# crontab -l
*/5* * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1
3,安裝nagios所需基礎軟件包
批量執行命令如下:
yuminstall gcc glibc glibc-common -y
yuminstall gd gd-devel -y
yuminstall httpd php php-gd -y
3.1創建nagios需要的用戶及組
批量命令:
/usr/sbin/useradd-m nagios
/usr/sbin/useraddapache
/usr/sbin/groupaddnagcmd
/usr/sbin/usermod-a -G nagcmd nagios
/usr/sbin/usermod-a -G nagcmd apache
id-n -G nagios
id-n -G apache
groupsnagios
groupsapache
3.2 下載軟件包
mkdir -p/server/soft
http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
二,安裝nagios
tarzxf nagios-3.2.0.tar.gz
cdnagios-3.2.0
./configure--with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
提示:如果是編譯安裝的httpd是,可以執行./configure--with-command-group=nagcmd --with-httpd-conf=/usr/local/apache2/conf/extra 增加一個編譯參數即指定編譯nagios web配置的生產路徑。然后編輯vi/usr/local/apache2/conf/httpd.conf增加 Includeconf/extra/nagios.conf
1,創建nagios web監控界面登入時需要的用戶名及密碼
htpasswd-c /usr/local/nagios/etc/htpasswd.users admin
輸入密碼即可
cat/usr/local/nagios/etc/htpasswd.users
提示:如果為單獨編譯的apache,則操作命令如下
/usr/local/apache2/bin/htpasswd-c /usr/local/nagios/etc/htpasswd.users admin
2,添加接收監控報警的email地址
vi/usr/local/nagios/etc/objects/contacts.cfg +35
email nagios@localhost
改為:
email baochengcai@autohome.com.cn
快速命令:
sed-I 's#nagios@localhost#baochengcai@autohome.com.cn#'/usr/local/nagios/etc/objects/contacts.cfg
3,啟動郵件服務。
/etc/init.d/sendmailstart
chkconfigsendmail on
chkconfig--list sendmail
如果sendmail啟動比較緩慢,可以修改/etc/hosts
127.0.0.1 nagios localhost.localdomain localhost #增加主機名hostname
4,配置apache服務
啟動apache并加入系統開機自啟動:
/etc/init.d/httpdstart
chkconfighttpd on
5,安裝nagios插件軟件包
tarzxf nagios-plugins-1.4.13.tar.gz
cdnagios-plugins-1.4.13
./configure --with-nagios-user=nagios--with-nagios-group=nagios --enable-perl-modules
make
makeinstall
ls /usr/local/nagios/libexec/|wc -l
#編譯如遇到make:***[all] Error 2 則configure 加--with-mysql=/usr/local/mysql解決
chkconfig nagios on
chkconfig--list nagios
6,驗證nagios配置文件(檢查語法)
簡單方法:/etc/init.d/nagioscheckconfig
[root@nagios~]# /etc/init.d/nagios checkconfig
Runningconfiguration check... OK.
/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg
TotalWarnings: 0
TotalErrors: 0
Thingslook okay - No serious problems were detected during the pre-flight check
#Total Warnings:警告和Total Errors:錯誤都為0,表示配置正常。
#Total Errors:如果不為0必須解決,否則nagios無法啟動。
#Total Warnings:這個如果不為0可以啟動nagios。
啟動nagios服務
/etc/init.d/nagios start
檢查nagios進程:
ps -ef|grep nagios |grep -v grep
檢查selinux是否關閉
setenforce0
sed-i ' s#SELINUX=enforcing#SELINUX=disabled# ' /etc/selinux/config
getenforce
7,安裝nrpe軟件:
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
makeinstall-daemon-config
nagios服務器端安裝結束,后續需要調整參數。
**Nagios添加多賬戶管理
檢查當前系統賬號:
[root@nagios ~]# cat /usr/local/nagios/etc/htpasswd.users
admin:HMcYqU.5Bh5bk
xiaomin:$apr1$GFzBDndr$Rd6Qvbc58PCUTPXNjhs8E1
chenkaixiong:$apr1$M6RLaWz8$8Ghi27zHStHaSZ9W1DVgs/
添加系統登錄賬號:
[root@nagios ~]# htpasswd -m/usr/local/nagios/etc/htpasswd.users chengcai
Newpassword:
Re-typenew password:
Addingpassword for user chengcai
[root@nagios etc]# cat /usr/local/nagios/etc/htpasswd.users
admin:HMcYqU.5Bh5bk
xiaomin:$apr1$GFzBDndr$Rd6Qvbc58PCUTPXNjhs8E1
chenkaixiong:$apr1$M6RLaWz8$8Ghi27zHStHaSZ9W1DVgs/
chengcai:$apr1$lXiSe1w4$HxIw6xSwjon5NshKfbbSx0
配置賬號權限:
[root@nagios etc]# egrep -v "^#|^$" cgi.cfg
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
show_context_help=0
use_pending_states=1
use_authentication=1
use_ssl_authentication=0
authorized_for_system_information=nagiosadmin,admin
authorized_for_configuration_information=nagiosadmin,admin
authorized_for_system_commands=nagiosadmin,admin
authorized_for_all_services=nagiosadmin,admin
authorized_for_all_hosts=nagiosadmin,admin
authorized_for_all_service_commands=nagiosadmin,admin
authorized_for_all_host_commands=nagiosadmin,admin
authorized_for_read_only=xiaomin,chenkaixiong,chengcai
#注:只給chengcai賬號只讀權限,如果想給該賬號更多權限,可根據配置添加。
default_statusmap_layout=5
default_statuswrl_layout=4
ping_syntax=/bin/ping-n -U -c 5 $HOSTADDRESS$
refresh_rate=90
escape_html_tags=1
action_url_target=_blank
notes_url_target=_blank
lock_author_names=1
客戶端安裝:-linux:
1,解決perl編譯問題:
后面編譯的軟件有perl程序,這里要提前設置下環境變量。
批量執行命令如下:
yum-y install perl-devel perl
echo'export LC_ALL=C'>>/etc/profile
tail-1 /etc/profile
source/etc/profile
echo$LC_ALL
2,關閉防火墻,安裝完后啟動防火墻。
/etc/init.d/iptables stop
/etc/init.d/iptablesstart
2.1解決系統時間同步。
echo‘*/5* * * * /usr/sbin/ntpdate time.windows.com’ >>/var/spool/cron/root
[root@nagios~]# crontab -l
*/5* * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1
3,在nagios客戶端安裝插件
mkdir-p /server/soft
cd/server/soft
rz-y (oldboy_tracining_nagios_soft.zip)#老男孩提供的軟件包。
unzipoldboy_tracining_nagios_soft.zip
3.1安裝nagios-plugins-1.4.13.tar.gz
/usr/sbin/useraddnagios -M -s /sbin/nologin
tarzxf nagios-plugins-1.4.13.tar.gz
cdnagios-plugins-1.4.13
./configure --with-nagios-user=nagios--with-nagios-group=nagios --enable-perl-modules
make
makeinstall
ls /usr/local/nagios/libexec/|wc -l
#編譯如遇到make:***[all] Error 2 則configure 加--with-mysql=/usr/local/mysql解決
3.2,安裝nrpe軟件:
tarzxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
makeinstall-daemon-config
3.3安裝其他相關的插件【iostat】
#-----------
tarzxf Params-Validate-0.91.tar.gz
cdParams-Validate-0.91
perlMakefile.PL
make
makeinstall
cd..
#-----------
tarzxf Class-Accessor-0.31.tar.gz
cdClass-Accessor-0.31
perlMakefile.PL
make
makeinstall
cd..
#------------
tarzxf Config-Tiny-2.12.tar.gz
cdConfig-Tiny-2.12
perlMakefile.PL
make
makeinstall
cd..
#-------------
tarzxf Math-Calc-Units-1.07.tar.gz
cdMath-Calc-Units-1.07
perlMakefile.PL
make
makeinstall
cd..
#-----------
tarzxf Regexp-Common-2010010201.tar.gz
cdRegexp-Common-2010010201
perlMakefile.PL
make
makeinstall
cd..
#---------------
tarzxf Nagios-Plugin-0.34.tar.gz
cdNagios-Plugin-0.34
perlMakefile.PL
make
makeinstall
cd..
#-------------
yuminstall sysstat -y
#這個命令式安裝系統性能分析工具,監控系統性能時程序或腳步會調用這些工具。
3.4配置開發的幾個基本腳本插件
cp /server/soft/nagios/check_memory.pl /usr/local/nagios/libexec/
cp /server/soft/nagios/check_iostat /usr/local/nagios/libexec
chmod 755/usr/local/nagios/libexec/check_memory.pl
chmod 755/usr/local/nagios/libexec/check_iostat
dos2unix/usr/local/nagios/libexec/check_memory.pl
dos2unix/usr/local/nagios/libexec/check_iostat
3.5配置nrpe
cd/usr/local/nagios/etc
vinrpe.cfg +79
加入可以監控本機的nagios server端IP,如下:
allowed_hosts=10.168.0.217
#注:如果機器大于500臺做集群或分布式監控時,可以使用多個nagiosserver-,ip要用逗號隔開。
#可用一條命令執行。↓
# perl -pi -e's/allowed_hosts=127.0.0.1/allowed_hosts=10.168.0.245/g'/usr/local/nagios/etc/nrpe.cfg
grep allowed_host/usr/local/nagios/etc/nrpe.cfg
更改nrpe配置文件信息。
cd /usr/local/nagios/etc
vi nrpe.cfg (shift+g切換到結尾)#注釋掉或者干脆刪除199-203行,同時在下面新添加要監控的內容。
command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20
command[check_mem]=/usr/local/nagios/libexec/check_memory.pl-w 10% -c 3%
command[check_disk]=/usr/local/nagios/libexec/check_disk-w 15% -c 7% -p /
command[check_swap]=/usr/local/nagios/libexec/check_swap-w 20% -c 10%
command[check_iostat]=/usr/local/nagios/libexec/check_iostat-w 6 -c 10
#-c為嚴重報警
啟動:nagios client
/usr/local/nagios/bin/nrpe-c /usr/local/nagios/etc/nrpe.cfg -d
echo"/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d">>/etc/rc.local
ps-ef|grep nagios
netstat-lnt|grep 5666
lsof-I :5666
#重啟client端nagios nrpe服務的組合命令
pkill nrpe &&/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
客戶端安裝:-windows:
windows:
添加服務:
添加完snmp服務后對服務進行設置.
打開本地服務:
右鍵屬性,添加團體名和監控主機IP地址.
啟動服務即可。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。