一、創(chuàng)建nagios用戶和用戶組。
遂川網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,遂川網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為遂川數(shù)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的遂川做網(wǎng)站的公司定做![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目錄下創(chuàng)建nagios啟動腳本 [root@localhost nagios]# make install-config #安裝示例配置文件 [root@localhost nagios]# make install-commandmode #配置目錄權(quán)限
三、nagios目錄對應(yīng)功能說明:
bin:可執(zhí)行程序所在目錄
etc:配置文件所在目錄
sbin:cgi文件所在目錄,也就是執(zhí)行外部命令所需文件所在目錄
share:網(wǎng)頁文件所在目錄
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"AuthType Basic options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user Alias /nagios "/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 [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 #檢查與被監(jiān)控對象的連通性
七、定義被監(jiān)控主機和服務(wù)。
[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 #需要指定聯(lián)系人才能實現(xiàn)監(jiān)控 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 #重啟郵件服務(wù) [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 #定義服務(wù) 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 #指定監(jiān)控主機的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 #添加監(jiān)控服務(wù) command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1 -w 5 -c 10 #以下在服務(wù)端添加 [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 #測試命令是否可執(zhí)行 [root@localhost ~]# yum -y install libgcc_s.so.1 #安裝缺失的庫文件 [root@localhost ~]# fetion --mobile=10086 --pwd=123456 --to=10010 --msg-utf8=Test --debug #發(fā)送測試短信,接收人必須是飛信好友,首次發(fā)送需填寫驗證碼:/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 #修改聯(lián)系人配置文件 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 ~]#
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。