安裝配置nagios

來源:互聯網
上載者:User

nagios是開源的監控解決方案,可以用來監控linux、windows、unix的主機狀態,可以通過簡訊和郵件的形式發送警示給使用者。另一個優點是由於是開源方案,可以比較方面的寫自己需要的監控指令碼,網上也有很多現成的指令碼可以借鑒等。總之,開源免費.

下面是具體的安裝過程

版本是rhel6.3 +nagios 4.0.2

伺服器端需要安裝nagioscore,nagios nrpe和nagios plugin軟體,Ip地址是10.4.1.11

windows用戶端需要安裝NSClient++

linux用戶端需要安裝nrpe和nagiosplugin

安裝配置nagios監控伺服器

1,配置yum源,安裝相關軟體包

mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare

[root@Stylog3 software]# mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare

vi /etc/yum.repos.d/rhel5.repo

[Server]

name=rhel5server

baseurl=file:///nfsshare/rhel-5.9-repo/install

enable=1

gpcheck=1

gpgkey=file:///nfsshare/rhel-5.9-repo/install/RPM-GPG-KEY-redhat-release

mkdir /nfsshare

mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare/

為了方便,直接使用linux內建的httpd服務

yum install -y httpd php gcc glibcglibc-common gd gd-devel make net-snmp

2,建立使用者

useradd nagios

passwd nagios

3,編譯安裝nagios core

tar -zxvf nagios-4.0.2

cd nagios-4.0.2

./configure

make all

make install

make install-init

make install-commandmode

make install-config

4,配置web介面

cd nagios-4.0.2

make install-webconf

為了安全,建立使用者

htpasswd -s -c/usr/local/nagios/etc/htpasswd.users nagiosadmin

啟動http服務

service httpd start

5,安裝nagios plugin

tar -zxvf nagios-plugins-1.5.tar.gz

cd nagios-plugins-1.5

./configure

make

make install

6,修改並驗證設定檔

相關設定檔均在/usr/local/nagios/etc/目錄下

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

7,登入網站驗證,是否正確安裝

http://Your-server-IP-address/nagios

8, clinet端的配置,具體用戶端如何安裝見下文

只需要在nrpe.cfg檔案中,添加相關命令即可,主要每個service對應的command都要添加一個對應的

cat /usr/local/nagios/etc/nrpe.cfg

添加如下類似內容

command[check_disk]=/usr/local/nagios/libexec/check_disk-w 15% -c 10% -p /home

新增一台windows監控用戶端

1,安裝軟體nscp

預設安裝在C:\Program Files\NSClient++,設定檔為nsclient.ini,預設監控連接埠為12489

伺服器端安裝監控windows的外掛程式(已經預設安裝了,就是check_nt)

2.定義命令

vi/usr/local/nagios/etc/objects/commands.cfg

# 'check_nt' command definition

define command{

command_name check_nt

command_line $USER1$/check_nt-H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$

}

3.定義要監控的項目 services

vi/usr/local/nagios/etc/objects/windows_stysql1.cfg

vi /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/windows_stysql1.cfg

添加linux伺服器監控用戶端

1,上傳並安裝nagios plugin安裝軟體

scp /monitor/software/nrpe-2.12.tar.gz hadoop@stylog2:/monitor/software

scp hadoop@10.1.1.5:/monitor/software/nagios-plugins-1.5.tar.gz /monitor/software/

scp hadoop@10.1.1.5:/monitor/software/nrpe-2.12.tar.gz /monitor/software/

tar -zxvf nagios-plugins-1.5.tar.gz

2 ,配置yum源,安裝相關軟體包

vi /etc/yum.repos.d/rhel6.repo

[Server]

name=rhel6server

baseurl=file:///nfsshare/rhel-6.3-repo/RHEL63/Server

enable=1

gpcheck=1

gpgkey=file:///nfsshare/rhel-6.3-repo/RHEL63/RPM-GPG-KEY-redhat-release

mkdir /nfsshare

mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare/

3,建立相關使用者

useradd nagios

passwd nagios

4,編譯nagios plugin

[root@tydb nagios]# cd nagios-plugins-1.5

[root@tydb nagios]# ./configure

[root@tydb nagios]# make

[root@tydb nagios]# make install

5,修改許可權

chown nagios:nagios /usr/local/nagios

chown -R nagios:nagios/usr/local/nagios/libexec

6,安裝xinetd

yum install xinetd

7,安裝nrpe

備忘:checkingfor SSL headers... configure: error: Cannot find ssl headers

yum -y install openssl-devel

scphadoop@stylog1:/monitor/software/nrpe-2.12.tar.gz /monitor/software/

tar -xvf nrpe-2.12.tar.gz

cd nrpe-2.12

[root@tydb]# ./configure

[root@tydb]# make all

[root@tydb]# make install-plugin

[root@tydb]# make install-daemon

[root@tydb]# make install-daemon-config

make install-xinetd

8,修改配置

vi /etc/xinetd.d/nrpe

only_from = 127.0.0.1 localhost<nagios_ip_address>

vi /etc/services

nrpe 5666/tcp NRPE

重啟服務

service xinetd restart

9,驗證是否安裝成功

[root@stylog2 nrpe-2.12]# netstat -at | grep nrpe

tcp 0 0 *:nrpe *:* LISTEN

[root@stylog2 nrpe-2.12]#/usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.12

10,添加監控的配置

vi /usr/local/nagios/etc/nrpe.cfg

預設已經添加了

command[check_users]=/usr/local/nagios/libexec/check_users-w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 1000 -c 1500

#command[check_ftp]=/usr/local/nagios/libexec/check_ftp-w 150 -c 200

command[check_ssh]=/usr/local/nagios/libexec/check_ssh10.1.1.5

command[check_disk]=/usr/local/nagios/libexec/check_disk-w 15% -c 10% -p /

你可以測試相關命令是否可以正常執行

/usr/local/nagios/libexec/check_nrpe -Hlocalhost -c check_users

當然你也可以根據需要,添加你需要的命令

11,監控server端也需要簡單配置

a,確保已經安裝nrpe和nrpe client

b,檢查到新加被監控伺服器的串連

[root@stadmin ~]#/usr/local/nagios/libexec/check_nrpe -H 10.1.1.6

NRPE v2.12

C, 添加hosts

vi /usr/local/nagios/etc/hosts.cfg

definehost{

use linux-tydb2 ; Inherit default values from atemplate

host_name stylog1 ; The name we're giving tothis server

alias stylog1 ; A longer name for the server

address 10.1.1.5 ; IP address of Remote Linux host

}

define host{

use linux-tydb2 ; Inherit default values from atemplate

host_name stylog2 ; The name we're giving tothis server

alias stylog2 ; A longer name for the server

address 10.1.1.6 ; IP address of Remote Linux host

}

D,建立一個服務組態檔

vi service_linux.cfg

樣本只添加了一個service,實際上可能需要更多監控項的定義

define service{

use generic-service

host_name stylog2

service_description FileSystem Usage

check_command check_nrpe!check_disk

}

E,重新啟動nagios

service nagios restart

新增一個監控項

已添加linux 檔案系統的監控

預設設定檔在目錄/usr/local/nagios/etc

A,nagios.cfg 中添加設定檔

cfg_file=/usr/local/nagios/etc/servicesi_linux.cfg

B,service_linux.cfg 設定檔中添加servicecheck_disk

define service{

use generic-service

host_name stylog1

service_description File System Usage

check_command check_nrpe!check_disk

}

C,用戶端的伺服器commands.cfg檔案中添加命令

cat/usr/local/nagios/etc/objects/commands.cfg

# 'check_disk' command definition

define command{

command_name check_disk

command_line $USER1$/check_disk-w $ARG1$ -c $ARG2$ -p $ARG3$

}

參考文檔

http://www.tecmint.com/install-nagios-in-linux/

http://www.tecmint.com/how-to-add-linux-host-to-nagios-monitoring-server/

http://www.tecmint.com/how-to-add-windows-host-to-nagios-monitoring-server/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.