Nagios是一個監(jiān)視系統(tǒng)運(yùn)行狀態(tài)和網(wǎng)絡(luò)信息的監(jiān)視系統(tǒng)。Nagios能監(jiān)視所指定的本地或遠(yuǎn)程主機(jī)以及服務(wù),同時提供異常通知功能等。
陽江ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
Nagios可運(yùn)行在Linux/Unix平臺之上,同時提供一個可選的基于瀏覽器的WEB界面以方便系統(tǒng)管理人員查看網(wǎng)絡(luò)狀態(tài),各種系統(tǒng)問題,以及日志等等。
nagios常用配置文件主要用以下6個:
cgi.cfg(控制cgi訪問的配置文件),nagios.cfg(Nagios主配置文件),resource.cfg(resource.cfg定義了一些變量,以便被其他文件引用,如$USER1$),objects(objects是一個目錄,用于定義Nagios對象),servers(servers是自己創(chuàng)建的目錄,Nagios可以加載該目錄下所有配置文件,常用于定義各遠(yuǎn)程服務(wù)器監(jiān)控信息,需要在nagios.cfg中配置)
其中:
objects目錄下文件::
commands.cfg #命令定義配置文件,里面定義的命令可以被其他文件引用
contacts.cfg #聯(lián)系人和聯(lián)系人組配置文件
localhost.cfg #監(jiān)控本地機(jī)器的配置文件
printer.cfg #監(jiān)控打印機(jī)的一個事例配置文件(默認(rèn)未啟用)
switch.cfg #監(jiān)控路由器的一個事例配置文件(默認(rèn)未啟用)
templates.cfg #模板配置文件,在此可以定義模板,在其他文件中引用
timeperiods.cfg #定義監(jiān)控時間段的配置文件
windows.cfg #監(jiān)控Windows的一個事例配置文件(默認(rèn)未啟用)
Nagios所需要的運(yùn)行條件是機(jī)器必須可以運(yùn)行Linux(或是Unix變種)并且有C語言編譯器。你必須正確地配置TCP/IP協(xié)議棧以使大多數(shù)的服務(wù)檢測可以通過網(wǎng)絡(luò)得以進(jìn)行。你需要但并非必須正確地配置Nagios里的CGIs程序,而一旦你要使用CGI程序時,你必須要安裝以下這些軟件。
1.nagios安裝##可參考官網(wǎng)文檔
所需軟件包:gd-devel-2.0.35-11.el6.x86_64.rpm nagios-plugins-2.1.1.tar.gz nagios-cn-3.2.3.tar.bz2
tar jxf nagios-cn-3.2.3.tar.bz2 yum install gd-devel-2.0.35-11.el6.x86_64.rpm -y
cd nagios-cn-3.2.3 groupadd nagcmd useradd -M -d /usr/local/nagios -G nagcmd nagios usermod -G nagcmd apache
./configure --with-command-group=nagcmd make all ##可以看到后面步驟 make install make install-init make install-config make install-commandmode make install-webconf
/etc/httpd/conf.d/nagios.conf cat /usr/local/nagios/etc/htpasswd.users ##可看到用戶名和密碼 htpasswd /usr/local/nagios/etc/htpasswd.users nagiosadmin ##修改nagiosadmin的密碼
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/httpd start /etc/init.d/nagios start
http://172.25.45.1/nagios/
用戶名:nagiosadmin 密碼:修改的密碼
2.nagios-plugins安裝
tar zxf nagios-plugins-2.1.1.tar.gz cd nagios-plugins-2.1.1
./configure##可看到插件安裝的信息,可根據(jù)缺少的插件進(jìn)行安裝。例如:MySQL-devel,openssl-devel make make install
cd /usr/local/nagios/libexec chown nagios.nagios * -R
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
cd /usr/local/nagios/etc/ vim nagios.cfg
添加兩個cfg_file(33行下面)
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
注釋掉cfg_file=/usr/local/nagios/etc/objects/localhost.cfg(38行)
cd objects/ cp -p localhost.cfg hosts.cfg cp -p localhost.cfg services.cfg vim hosts.cfg
將內(nèi)容修改為以下:
define host{
use linux-server
host_name server1.example.com
alias Manager
# parents MainSwitch
address 172.25.45.1
icon_p_w_picpath server.gif
statusmap_p_w_picpath server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members * ; Comma separated list of hosts that belong to this group
}
vim services.cfg
將166行之前全部刪掉,再刪除第8行開始的servicegroup,只留下一個servicegroup。將此servicegroup的members最后兩個成員HomeRouter和PING刪除
:%s/田朝陽家用機(jī)/server1.example.com/g
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
http://172.25.45.1/nagios/
cd /usr/local/nagios/libexec ./check_disk ./check_disk -w 20 -c 10 ./check_disk -w 20 -c 10 -p /
vim services.cfg
添加以下內(nèi)容:
max_check_attempts 2
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
http://172.25.45.1/nagios/
【server2】
yum install -y mysql-server /etc/init.d/mysqld start mysql_secure_installation
mysql -p mysql> create database nagdb; mysql> grant select on nagdb.* to nagios@'172.25.45.1' identified by 'westos'; mysql> quit
【server1】
cd /usr/local/nagios/libexec ./check_mysql -H 172.25.45.2 -u nagios -p westos
mysql -h 172.25.45.2 -u nagios -p mysql> show databases; mysql> quit
將serevr2的mysql服務(wù)關(guān)閉
cd /usr/local/nagios/etc/objects vim commands.cfg
在212行后添上以下內(nèi)容:
# 'check_mysql' command definition
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$
}
vim services.cfg
在最后添上以下內(nèi)容:
#######################check_mysql
define service{
use local-service
host_name server2.example.com
service_description MYSQL
check_command check_mysql!nagios!westos
}
vim hosts.cfg
在上面host下再添加一個host,內(nèi)容如下:
define host{
use linux-server
host_name server2.example.com
alias Manager
# parents MainSwitch
address 172.25.45.2
icon_p_w_picpath server.gif
statusmap_p_w_picpath server.gd2
2d_coords 400,100
3d_coords 400,100,100
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
http://172.25.45.1/nagios/
###添加連線
vim hosts.cfg
將alias的值改為server2
將parents的注釋取消,并將值改為server1.example.com
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
http://172.25.45.1/nagios/
此時HTTP的告警狀態(tài)是因為沒有index.html頁面,在/var/www/html下建立一個index.html文件就可以解決HTTP告警問題
3.安裝nrpe
【server2】
所需軟件包:nrpe-2.15.tar.gz nagios-plugins-2.1.1.tar.gz
tar zxf nrpe-2.15.tar.gz tar zxf nagios-plugins-2.1.1.tar.gz
useradd -M -d /usr/local/nagios nagios cd nagios-plugins-2.1.1 ./configure
出現(xiàn)以下錯誤,是因為缺少軟件,下載gcc可解決
[root@server2 nagios-plugins-2.1.1]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to disable maintainer-specific portions of Makefiles... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/nagios-plugins-2.1.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
yum install openssl-devel -y
./configure##這里不需要--with-mysql,可以不安裝
make make install
cd /usr/local/nagios/ chown nagios.nagios . -R
yum install -y xinetd
cd /root/nrpe-2.15 ./configure make all make install-plugin make install-daemon make install-daemon-config make install-xinetd
cd /etc/xinetd.d vim nrpe
將15行的only_from改為172.25.45.1
vim /etc/services
添加以下內(nèi)容:
nrpe 5666/tcp
/etc/init.d/xinetd start netstat -antlpe
vim /usr/local/nagios/etc/nrpe.cfg
修改221行,改為以下內(nèi)容:
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
/etc/init.d/xinetd restart
cd /usr/local/nagios/libexec/ scp check_nrpe root@172.25.45.1:/usr/local/nagios/libexec/
【server1】
cd /usr/local/nagios/libexec/ chown nagios.nagios check_nrpe ./check_nrpe -H 172.25.45.2 ./check_nrpe -H 172.25.45.2 -c check_disk
測試:
在server2將/usr/local/nagios/etc/nrpe.cfg修改,將command[check_disk] -w改為90%,并重啟服務(wù)
./check_nrpe -H 172.25.45.2 -c check_disk
將server2的/usr/local/nagios/etc/nrpe.cfg文件恢復(fù)上一步之前,并重啟服務(wù)。
【server1】
cd /usr/local/nagios/etc/objects vim commands.cfg
在# 'check_mysql' command definition這一段下添加以下內(nèi)容:
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
vim services.cfg
在最后添上以下內(nèi)容:
#######################check_nrpe
define service{
use local-service ; Name of service template to use
host_name server2.example.com
service_description 根分區(qū)
check_command check_nrpe!check_disk
}
define service{
use local-service ; Name of service template to use
host_name server2.example.com
service_description 登錄用戶數(shù)
check_command check_nrpe!check_users
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
http://172.25.45.1/nagios/
4.虛擬機(jī)連網(wǎng)
ip addr add 172.25.254.101/24 dev eth0 ip addr show
ip route show route -n ping 172.25.254.45 route del default gw 172.25.45.250 route add default gw 172.25.254.45 route -n
vim /etc/resolv.conf
ping 192.168.122.1 ping 172.25.254.45
測試網(wǎng)絡(luò)是否連通
dig baidu.com ping baidu.com
已連網(wǎng)
在家里用無限上網(wǎng),也可以用NAT的方式進(jìn)行虛擬機(jī)連網(wǎng),網(wǎng)絡(luò)配置選擇DHCP分配網(wǎng)絡(luò)
可以看到本地發(fā)送郵件的地址。
登錄郵箱,進(jìn)行設(shè)置。在反垃圾處設(shè)置郵件地址白名單:nagios@server1.example.com
【server1】
yum install mail -y
su - nagios mail wjl19940429@qq.com
cd /usr/local/nagios/etc/objects vim contacts.cfg
修改35行email的值為自己的郵箱
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
【server2】
/etc/init.d/mysqld stop
【server1】
vim /usr/local/nagios/etc/objects/templates.cfg
修改186行max_check_attempts的值為3
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
為了盡快測試,將檢測次數(shù)減少一些
##110云告警##
所需軟件包:alert-agent-4.1.3.1-linux-x64.tar.gz
su - nagios -bash-4.1$ tar zxf alert-agent-4.1.3.1-linux-x64.tar.gz -C /usr/local/nagios/libexec/ -bash-4.1$ cd /usr/local/nagios/libexec/ -bash-4.1$ cd alert-agent/ -bash-4.1$ ll
-bash-4.1$ cd plugin/nagios-plugin/ -bash-4.1$ cp nagios /usr/local/nagios/libexec/ -bash-4.1$ cp 110monitor.cfg /usr/local/nagios/etc/objects/
在110云告警頁面選擇配置,添加應(yīng)用云告警
復(fù)制下key
cd /usr/local/nagios/etc/objects vim 110monitor.cfg
將復(fù)制下的key粘貼在18行,paper后
vim contacts.cfg
在54行members后添加110monitor
cd .. vim nagios.cfg
在35行之后添加cfg_file=/usr/local/nagios/etc/objects/110monitor.cfg
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /etc/init.d/nagios reload
網(wǎng)頁進(jìn)行下一步,完成配置。
選擇通知策略,進(jìn)行配置
例如
【server2】
/etc/init.d/mysqld stop
【server1】
cd /usr/local/nagios/var tail -f nagios.log
/etc/init.d/nagios reload
缺云告警成功示例截圖
本文名稱:(十一)企業(yè)部分之nagios
當(dāng)前網(wǎng)址:http://jinyejixie.com/article6/pggoig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、靜態(tài)網(wǎng)站、域名注冊、網(wǎng)站維護(hù)、網(wǎng)站策劃、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)