您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么在RedHat6.5上部署Nagios”,在日常操作中,相信很多人在怎么在RedHat6.5上部署Nagios問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么在RedHat6.5上部署Nagios”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
部署環境:系統,RedHat 6.5;組件,Nagios;
部署前準備:關閉Selinux,和防火墻(/etc/init.d/iptables stop);獲取相關軟件包。
(包括gd-devel mysql-server openssl-devel xinetd;等)
具體步驟:
1.在Nagios運行的主機上創建Nagios用戶和nagcmd組;
groupadd nagcmd;
useradd -M -d /usr/local/nagios -G nagcmd nagios;
usermod -G nagcmd apache
2.解壓相應的源碼包和插件包;并指定編譯環境和參數;
cd /guo
tar jxf nagios-cn-3.2.3.tar.bz2;
cd nagios-cn-3.2.3
###指定編譯環境組為"ngcmd";
./configure --with-command-group=nagcmd;
###開始編譯并安裝
make all && make install
###安裝啟動腳本
make install-init;
###安裝WEB配置文件
make install-webconf;
###安裝配置文件
make install-config;
###設定Nagios的登陸用戶名和密碼;
htpasswd/usr/local/nagios/etc/htpasswd.users nagiosadmin
###檢查配置正確性
/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg
確保無Error 或者warning。
3.啟動相關服務并測試;
/etc/init.d/nagios start
/etc/init.d/httpd start
4.安裝相關插件。
cd /guo
tar zxf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure
###執行完畢應確保自身所需的功能后面的狀態顯示“yes”;比如后面要用到Mysql和ssl協議加密;那結果至少包含"--with-mysql:yes,--with-openssl:yes"
###插件會被自動安裝至/usr/local/nagios/libexec;
cd /usr/local/nagios/libexec;
###調整并遞歸此目錄下所有文件
chown nagios.nagios . -R ;
###再次檢查配置
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
###重載Nagios配置
/etc/init.d/nagios reload
5.編輯相關配置文件。
cd /usr/local/nagios/etc/objects/
cp -p localhost.cfg hosts.cfg
cp -p localhost.cfg services.cfg
vim /usr/local/nagios/etc/objects/hosts.cfg
###添加如下內容:
###通過hosts.cfg文件來指定被監控主機及其相關信息;
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
###通過services.cfg文件定義監控哪些服務和資源。
cfg_file=/usr/local/nagios/etc/objects/services.cfg
###vi hosts.cfg
definehost{
use linux-server
host_name pu_tao.example.com
alias Manager
address 172.25.254.18
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
alias Linux Servers
members *
}
本次取一臺被監控主機做實驗,僅寫一個服務組
define servicegroup{
servicegroup_name 系統負荷檢查
alias 負荷檢查
members server2.example.com,進程總數,server2.example.com用戶登錄 數,server2.example.com,根分區,server2.example.com,交換空間利用率
}
監控ping的情況
defineservice{
use local-service
host_name *
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
監控硬盤情況
defineservice{
use local-service
host_name xi_gua.example.com
service_description 根分區
check_command check_local_disk!20%!10%!/
}
監控登錄用戶數
defineservice{
use local-service
host_name xi_gua.example.com
service_description 登錄用戶數
check_command check_local_users!20!50
}
監控系統負荷
define service{
use local-service
host_name xi_gua.example.com
service_description 系統負荷
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
監控進程總數
defineservice{
use local-service
host_name xi_gua.example.com
service_description 進程總數
check_command check_local_procs!250!400!RSZDT
}
監控交換空間利用率
define service{
use local-service
host_name xi_gua.example.com
service_description 交換空間利用率
check_command check_local_swap!20!10
}
監控ssh情況
define service{
use local-service
host_name xi_gua.example.com
service_description SSH
check_command check_tcp!22!1.0!10.0
notifications_enabled 0
}
監控apache
defineservice{
use local-service
host_name xi_gua.example.com
service_description HTTP
check_command check_http
notifications_enabled 0
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload
如圖顯示本機的監控成功
6.再開啟一臺主機。本次實驗主機名為xi_gua.example.com.ip:172.25.254.17;同樣關閉Selinux和防火墻。
在本機上安裝Mysql;并創建用戶Nagios和賦予一定權限。
create database nagdb;
grant select on nagdb.* tonagios@172.25.254.18 identified by 'nagios';
返回Nagios所在主機pu_tao.example.com;
cd /usr/local/nagios/libexec
./check_mysql -H 172.25.254.3 -unagios -pnagios
執行完畢應有類似日志信息顯示;如有且無報錯說明本機成功監控對端mysql
cd /usr/local/nagios/etc/objects
在 commands.cfg 中添加監控mysql的命令
# 'check_mysql' command definition
definecommand{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$
}
在services.cfg中添加監控mysql
##########################check_mysql
define service{
use local-service
host_name xi_gua.example.com
service_description MYSQL
check_command check_mysql!nagios!nagios
notifications_enabled 0
}
在hosts.cfg中添加
define host{
use linux-server
host_name xi_gua.example.com
alias Manager
parents xi_gua.example.com
address 172.25.254.17
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
如圖表示成功檢測server3主機上的mysql
8.安裝Nrpe使nagios監控多臺主機;在172.25.254.17(xi_gua.example.com)上操作。
###解壓相關組件并創建nagios用戶;
tar zxfnrpe-2.15.tar.gz
tar zxf nagios-plugins-2.1.1.tar.gz
yum install mysql-devel openssl-devel -y
useradd -M -d /usr/local/nagios nagios
cd nagios-plugins-2.1.1
./configure
make all && make install
cd /usr/local/nagios/libexec/
chown nagios.nagios . -R
yum install xinetd
cd /root/nrpe-2.15
./configure
make all && make install
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
vim /etc/xinetd.d/nrpe
#設定監控主機為172.25.254.18
only_from = 172.25.254.18
vim /etc/services
nrpe 5666/tcp
/etc/init.d/xinetd start
cd /usr/local/nagios/etc/
vim nrpe.cfg
將command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/hda1改為
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p/ #監控根分區
/etc/init.d/xinetdrestart
cd /usr/local/nagios/libexec/
scp check_nrpe root@172.25.254.18:/usr/local/nagios/libexec/ 將check_nrpe遠程復制到pu_tao.exampl.com相應的目錄中。
返回172.25.254.18;做如下操作
cd /usr/local/nagios/libexec/
chown nagios.nagios check_nrpe
###檢測nrpe是否可用成功顯示nrpe版本號
./chek_nrpe -H 172.25.254.17
cd /usr/local/nagios/etc/objcts/
在 commands.cfg 中添加check_nrpe的命令
# 'check_nrpe' commanddefinition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$
}
在services.cfg中添加
define service{
use local-service
host_name xi_gua.example.com
service_description 根分區
check_command check_nrpe!check_disk
}
define service{
use local-service
host_name xi_gua.example.com
service_description 登錄用戶數
check_command check_nrpe!check_users
}
監控根分區和登錄人數
/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload
如圖可見監控成功
9.nagios的110云報警
到onealter官網下載所用的軟件包這里用的是
alert-agent-4.1.3.1-linux-x64.tar.gz
在onealter網頁添加nagios應用
獲取應用key
在xi_gua.example.com主機中:
tar zxf alert-agent-4.1.3.1-linux-x64.tar.gz
cp -R alert-agent /usr/local/nagios/libexec/ #將解壓好的包放入nagios插件目錄中
cp alert-agent/plugin/nagios-plugin/nagios /usr/local/nagios/libexec/
chmod +x /usr/local/nagios/libexec/nagios
cp alert-agent/plugin/nagios-plugin/110monitor.cfg/usr/local/nagios/etc/objects/ #將110配置文件放入nagios配置文件目錄
在110monitor.cfg文件中添加Key:
修改/usr/local/nagios/etc/objects/contacts.cfg,新增110monitor到默認聯系組
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,110monitor
}
修改/usr/local/nagios/etc/nagios.cfg,將110monitor.cfg新增到nagios.cfg中
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
到此,關于“怎么在RedHat6.5上部署Nagios”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。