您好,登錄后才能下訂單哦!
一、創建nagios用戶和用戶組。
[root@localhost ~]#useradd -s /sbin/nologin nagios [root@localhost ~]#mkdir /usr/local/nagios [root@localhost ~]#chown -R nagios:nagios /usr/local/nagios
二、編譯安裝nagios
[root@localhost ~]# tar -zxvf nagios-3.5.0.tar.gz [root@localhost ~]# cd nagios [root@localhost nagios]#./configure --prefix=/usr/local/nagios [root@localhost ~]# tar -zxvf nagios-3.5.0.tar.gz [root@localhost ~]# cd nagios [root@localhost nagios]#./configure --prefix=/usr/local/nagios [root@localhost nagios]#make all [root@localhost nagios]#make install [root@localhost nagios]# make install-init #在/etc/rc.d/init.d目錄下創建nagios啟動腳本 [root@localhost nagios]# make install-config #安裝示例配置文件 [root@localhost nagios]# make install-commandmode #配置目錄權限
三、nagios目錄對應功能說明:
bin:可執行程序所在目錄
etc:配置文件所在目錄
sbin:cgi文件所在目錄,也就是執行外部命令所需文件所在目錄
share:網頁文件所在目錄
libexec:外部插件所在目錄
var:日志文件,lock等文件所在目錄。修改日志文件時間格式,修改拷貝的文件(perl -i -pe '($t) = ($_ =~ m/^\[(\d+)\]/); $nice=scalar localtime $t; s/^\[(\d+)\]/[$nice]/' nagios.log)
var/archives:日志自動歸檔目錄
var/rw:用來存放外部命令文件的目錄
四、安裝nagios插件。
[root@localhost ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz [root@localhost ~]# yum -y install openssl* [root@localhost ~]# cd nagios-plugins-1.4.16 [root@localhost nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios [root@localhost nagios-plugins-1.4.16]# make [root@localhost nagios-plugins-1.4.16]# make install
五、安裝并配置httpd和php
[root@localhost ~]# yum -y install php httpd [root@localhost ~]# vim /etc/httpd/conf/httpd.conf User nagios Group nagios DirectoryIndex index.html index.html.var index.php AddType application/x-httpd-php .php ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin"> AuthType Basic options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/usr/local/nagios/share"> AuthType Basic Options None AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user </Directory> [root@localhost ~]# htpasswd -cm /usr/local/nagios /etc/htpasswd USER [root@localhost ~]# service httpd restart [root@localhost ~]# service nagios restart #訪問http://ip/nagios 輸入用戶/密碼就可以看到nagios管理界面
六、安裝插件NRPE
[root@localhost ~]# tar -zxvf nrpe-2.14.tar.gz [root@localhost ~]# cd nrpe-2.14 [root@localhost nrpe-2.14]# ./configure [root@localhost nrpe-2.14]# make all [root@localhost nrpe-2.14]# make install-plugin [root@localhost ~]# cd /usr/local/nagios/etc [root@localhost etc]# mkdir monitor [root@localhost etc]# cp -R objects/* monitor/ [root@localhost etc]# vim monitor/commands.cfg define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } [root@localhost libexec]# ./check_nrpe -H 192.168.1.1 #檢查與被監控對象的連通性
七、定義被監控主機和服務。
[root@localhost ~]# vim /usr/local/nagios/etc/cgi.cfg #將用戶名修改為nagios界面登錄的用戶名 default_user_name=USER [root@localhost ~]# vim /usr/local/nagios/etc/nagios.cfg cfg_dir=/usr/local/nagios/etc/monitor #注釋掉cfg_file開頭的行 [root@localhost ~]# vim /usr/local/nagios/etc/monitor/contacts.cfg #需要指定聯系人才能實現監控 define contact{ contact_name USER #必須改為http驗證用戶 use generic-contact alias Nagios Admin email admin@domain.com } define contactgroup{ contactgroup_name admins alias Nagios Administrators members USER } [root@localhost ~]# service postfix restart #重啟郵件服務 [root@localhost ~]# vim /usr/local/nagios/etc/monitor/hosts.cfg #定義主機 define host{ use windows-server #引用模板windows-server的屬性信息 host_name test-server #主機命名 alias test #別名 address ip_address #ip地址 } define hostgroup{ #必須定義組 hostgroup_name windows-servers alias windows Servers members test-server } [root@localhost ~]# vim /usr/local/nagios/etc/monitor/services.cfg #定義服務 define service{ use local-service host_name test-server service_description EXAMPLE check_command check-host-alive } [root@localhost ~]# cd /sbin [root@localhost sbin]# ln -s /usr/local/nagios/bin/nagios nagios [root@localhost sbin]# nagios -v /usr/local/nagios/etc/nagios.cfg #檢查主配置文件
八、客戶端安裝nrpe和nagios-plugin。
[root@localhost ~]# useradd nagios [root@localhost ~]# yum -y install openssl [root@localhost ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz [root@localhost ~]# cd nagios-plugins-1.4.16 [root@localhost nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios [root@localhost nagios-plugins-1.4.16]# make&make install check_http.c: In function ‘process_arguments’: check_http.c:312: error: ‘ssl_version’ undeclared (first use in this function) check_http.c:312: error: (Each undeclared identifier is reported only once check_http.c:312: error: for each function it appears in.) [root@localhost ~]# make clean #清除掉之前make的殘余信息 [root@localhost ~]# ./configure --prefix=/usr/local/nagios [root@localhost ~]# make&make install [root@localhost ~]# chown nagios:nagios /usr/local/nagios [root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/libexec/ [root@localhost ~]# tar -zxvf nrpe-2.14.tar.gz [root@localhost ~]# cd nrpe-2.14 [root@localhost nrpe-2.14]# ./configure [root@localhost nrpe-2.14]# make all [root@localhost nrpe-2.14]# make install-plugin [root@localhost nrpe-2.14]# make install-daemon [root@localhost nrpe-2.14]# make install-daemon-config [root@localhost nrpe-2.14]# make install-xinetd [root@localhost ~]# vim /etc/xinetd.d/nrpe service nrpe { flags = REUSE socket_type = stream port = 5666 wait = no user = nagios group = nagios server = /usr/local/nagios/bin/nrpe server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd log_on_failure += USERID disable = no only_from = 127.0.0.1 192.168.1.10 #指定監控主機的IP } [root@localhost ~]# vim /etc/services nrpe 5666/tcp # nrpe [root@localhost ~]# service xinetd restart [root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H localhost #測試本地nrpe daemon是否正常 [root@localhost ~]# vim /usr/local/nagios/etc/nrpe.cfg #添加監控服務 command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1 -w 5 -c 10 #以下在服務端添加 [root@localhost ~]# vim /usr/local/nagios/etc/monitor/services.cfg define service{ use local-service host_name test-linux service_description linux check_command check_nrpe!check_http }
九、配置Fetion短信報警。
[root@localhost ~]# tar -zxvf fetion20101113.tar.gz [root@localhost ~]# cd fetion20101113 [root@localhost ~]# mv fetion /bin #剪切主程序到/bin [root@localhost ~]# mkdir /usr/local/fetion [root@localhost ~]# mv fetion20101113/* /usr/local/fetion/ [root@localhost ~]# vim /etc/ld.so.conf.d/fetion.conf /usr/local/fetion #指向Fetion的庫文件目錄 [root@localhost ~]# ldconfig #重新讀取庫文件 [root@localhost ~]# fetion --help #測試命令是否可執行 [root@localhost ~]# yum -y install libgcc_s.so.1 #安裝缺失的庫文件 [root@localhost ~]# fetion --mobile=10086 --pwd=123456 --to=10010 --msg-utf8=Test --debug #發送測試短信,接收人必須是飛信好友,首次發送需填寫驗證碼:/bin/10086.jpg [root@nagios ~]# vim /usr/local/nagios/etc/monitor/commands.cfg #修改commands配置文件 # 'notify-host-by-fetion' command definition define command{ command_name notify-host-by-fetion command_line /bin/fetion --mobile=10086 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" } # 'notify-service-by-fetion' command definition define command{ command_name notify-service-by-fetion command_line /bin/fetion --mobile=10086 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" } [root@nagios ~]# vim /usr/local/nagios/etc/monitor/contacts.cfg #修改聯系人配置文件 define contact{ contact_name Tom use generic-contact alias Monitor user email Tom@gmail.com service_notification_commands notify-service-by-fetion host_notification_commands notify-host-by-fetion pager 10086 #手機號碼 } define contact{ contact_name Tony use generic-contact alias Monitor user email Tony@gmail.com service_notification_commands notify-service-by-fetion host_notification_commands notify-host-by-fetion pager 10010 } define contactgroup{ contactgroup_name admins alias Nagios Administrators members Tom,Tony } [root@localhost ~]#
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。