日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

监控实用篇

發(fā)布時間:2025/1/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 监控实用篇 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

生產(chǎn)環(huán)境開源監(jiān)控系統(tǒng)整合 Nagios+Cacti+Nconf

個人實踐過,好文章。

公司要換監(jiān)控系統(tǒng)了,以前采用的是Nagios+Centreon這兩款軟件的整合然后做出來的,但是Centreon的畫圖是在令人感覺慘不忍睹,而且統(tǒng)計出來的數(shù)據(jù),也不是非常準(zhǔn)確和人性化……所以,在研究了之后我們決定換監(jiān)控系統(tǒng),而最終的方案就是使用Naigos來捕獲數(shù)據(jù)和報警,使用Cacti來畫圖,使用Nconf來配置多臺主機,方便管理。 那么ok,先說一下我們的環(huán)境平臺。 監(jiān)控機采用的是R410的服務(wù)器,8G內(nèi)存和16核cpu,采用CentOS 5.5 x86_64的操作系統(tǒng)。好的,配置好網(wǎng)絡(luò)之后,我們開始! 注意:這里默認(rèn)關(guān)閉了Selinux(生產(chǎn)環(huán)境也是關(guān)的,放心吧。)以及關(guān)閉了iptables。如有開啟的需要,請根據(jù)網(wǎng)絡(luò)酌情添加相關(guān)內(nèi)容。 準(zhǔn)備環(huán)境: 為以后的配置搭建安裝環(huán)境
  • yum install -y http*
  • yum install -y mysql*
  • yum install -y php-*
  • yum install -y net-snmp*
  • yum install -y httpd gcc glibc glibc-common gd gd-devel php php-gd ntp
  • 一:Nagios環(huán)境的搭建 1.安裝nagios
  • wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz
  • tar zxf nagios-3.3.1.tar.gz
  • cd nagios
  • ./configure --prefix=/var/www/html/nagios
  • make all
  • useradd nagios
  • make install && make install-init && make install-commandmode && make install-config && make install-webconf
  • 2.增加nagios登陸認(rèn)證文件,一定要用默認(rèn)的nagiosadmin作為用戶,否則需要修改其他文件。
  • htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin
  • 3. 安裝插件:
  • wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
  • tar -zvxf nagios-plugins-1.4.15.tar.gz
  • cd nagios-plugins-1.4.15
  • ./configure --prefix=/var/www/html/nagios/
  • make
  • make install
  • 4.將運行Apache的用戶添加到nagios組里,這樣Apache才有權(quán)限讀取文件
  • usermod -G nagios apache ##將apache用戶加到nagios組。
  • 5.階段測試
  • chown nagios.nagios /var/www/html/nagios/ -R
  • service httpd restart
  • chkconfig httpd on
  • /etc/init.d/nagios start
  • 二:cacti環(huán)境的搭建 1.rrdtool的安裝,這里需要安裝的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php,我用的rrdtools的版本是1.4.4.1_x86_64。

    在這里沒有提供rrdtool的工具,需要下載可以去這里下載上述的3個軟件包

    rrdtool、rrdtool-devel的地址:http://packages.express.org/rrdtool/ rrdtool-php的地址:http://pkgs.org/download/rrdtool-php 注意,rrdtool的組件和附加組件版本盡量一致,而由于rrdtool-php這個包非常稀有,所以,盡量請以rrdtool-php的版本來決定rrdtool以及rrdtool-devel的版本。還有一定要對應(yīng)環(huán)境,別安裝成了fedora的版本了=。=
    下載完成后,本地yum安裝
  • yum localinstall -y --nogpgcheck rrdtool-*
  • service mysqld start
  • 2.配置snmp
  • vim /etc/snmp/snmpd.conf
  • # 修改3項 127.0.0.1 、 all、啟用項(修改的內(nèi)容詳見我Cacti的安裝文檔,上面有非常詳細(xì)的內(nèi)容介紹)
  • service snmpd restart
  • 3.安裝cacti
  • wget http://www.cacti.net/downloads/cacti-0.8.7h.tar.gz
  • tar zxvf cacti-0.8.7h.tar.gz
  • mv cacti-0.8.7h /var/www/html/cacti
  • 4.創(chuàng)建cacti數(shù)據(jù)庫
  • mysql> create database cacti;
  • mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti';
  • mysql> flush privileges;
  • 5.將cacti的表內(nèi)容導(dǎo)入創(chuàng)建的數(shù)據(jù)庫
  • cd /var/www/html/cacti
  • mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql
  • 6.分別編輯兩個.php文件,以適應(yīng)環(huán)境,修改內(nèi)容相同。
  • vim /var/www/html/cacti/include/config.php
  • vim /var/www/html/cacti/include/global.php
  • $database_default = "cacti"; //默認(rèn)數(shù)據(jù)庫名

    $database_hostname = "localhost"; //主機名 $database_username = "cacti"; //登陸數(shù)據(jù)庫用戶名 $database_password = "cacti"; //登陸數(shù)據(jù)庫密碼 $database_port = "3306";
  • useradd –r –M cacti
  • chown –R cacti /var/www/html/cacti/rra/
  • chown –R cacti /var/www/html/cacti/log/
  • 7.在cacti用戶下創(chuàng)建計劃任務(wù)以畫圖
  • su cacti
  • crontab –e
  • */5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
  • php /var/www/html/cacti/poller.php > /dev/null 2>&1
  • exit
  • 8.從web頁面啟動cacti,安裝,并查看圖形化界面 三:整合Nagios與Cacti 1.下載并安裝ndoutils
  • wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download
  • tar zxvf ndoutils-1.4b9.tar.gz
  • cd ndoutils-1.4b9
  • ./configure --prefix=/var/www/html/nagios --enable-mysql --disable-pgsql --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
  • make
  • 2.準(zhǔn)備配置文件
  • cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /var/www/html/nagios/bin
  • cd db
  • ./installdb -ucacti -pcacti -hlocalhost -d cacti
  • cd ..
  • cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /var/www/html/nagios/etc
  • mv /var/www/html/nagios/etc/ndo2db.cfg-sample /var/www/html/nagios/etc/ndo2db.cfg
  • mv /var/www/html/nagios/etc/ndomod.cfg-sample /var/www/html/nagios/etc/ndomod.cfg
  • chmod 644 /var/www/html/nagios/etc/ndo*
  • chown nagios:nagios /var/www/html/nagios/etc/*
  • chown nagios:nagios /var/www/html/nagios/bin/*
  • 3.修改nagios.cfg配置文件以適應(yīng)當(dāng)前環(huán)境
  • vim /var/www/html/nagios/etc/nagios.cfg
  • # 在文件中添加:
  • broker_module=/var/www/html/nagios/bin/ndomod-3x.o config_file=/var/www/html/nagios/etc/ndomod.cfg
  • # 檢查
  • event_broker_options=-1 ## 為Nagios開啟event broker
  • 4.修改ndo2db.cfg以適應(yīng)當(dāng)前環(huán)境
  • vim /var/www/html/nagios/etc/ndo2db.cfg
  • # 確保下列內(nèi)容為唯一項
  • socket_type=tcp
  • db_servertype=mysql
  • db_host=localhost
  • db_port=3306
  • db_name=cacti
  • db_prefix=nagios_
  • db_user=cacti
  • db_pass=cacti
  • 5.修改ndomod.cfg以適應(yīng)當(dāng)前環(huán)境
  • vim /var/www/html/nagios/etc/ndomod.cfg
  • # 確保下列項的唯一內(nèi)容為
  • output_type=tcpsocket
  • output=127.0.0.1
  • 6.為ndo2db添加啟動進程
  • cp ./daemon-init /etc/init.d/ndo2db
  • vim /etc/init.d/ndo2db
  • # 檢查里面的路徑確保不會出現(xiàn)“//",并將Ndo2dbBin修改成下面的值:
  • Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3x
  • chmod +x /etc/init.d/ndo2db
  • 7.啟動守護進程與nagios
  • service ndo2db start
  • tail -20 /var/log/messages ## 查看其中是否有錯誤出現(xiàn)。如無報錯請繼續(xù)
  • service nagios start
  • 四:安裝ncp,以在Cacti中展現(xiàn)Nagios 1.先安裝cacti擴展模塊
  • wget http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz
  • tar xvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
  • cp -R cacti-plugin-arch/* /var/www/html/cacti/
  • cd /var/www/html/cacti/
  • mysql -ucacti -pcacti cacti < pa.sql
  • patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff
  • ## 為cacti配置文件打補丁的時候注意在為include/config.php打補丁的時候有可能它將 include/config.php.dist給打補丁了,我們只需要手動加入下面的內(nèi)容即可。
  • vim include/config.php
  • # 修改(或新加入)為
  • $url_path = "/cacti/";
  • 從web進入cacti,啟用cacti plugin擴展 2.安裝npc
  • tar zxvf npc-2.0.4.tar.gz
  • mv npc /var/www/html/cacti/plugins/
  • vim /var/www/html/cacti/include/config.php
  • # 加入:
  • $plugins[] = 'npc';
  • 3.安裝 npc支持:json
  • wget http://pkgs.fedoraproject.org/repo/pkgs/php-pecl-json/json-1.2.1.tgz/d8904d2f004ceec85eeacf524cd25539/json-1.2.1.tgz
  • tar zxvf json-1.2.1.tgz
  • cd json-1.2.1
  • phpize ## 如果發(fā)現(xiàn)沒有Phpize文件,則是因為php-devel包沒有安裝導(dǎo)致的
  • ./configure
  • make && make install
  • php -i | grep php.ini ## 查看是否有導(dǎo)入信息
  • 4.打開php.ini文件添加對json的支持
  • vim /etc/php.ini
  • # 添加
  • extension=json.so
  • 5.為apache添加php支持。
  • vim /etc/httpd/conf/httpd.conf
  • # 添加一行:
  • AddType application/x-httpd-php .php .phtml
  • # 修改原DirectoryIndex內(nèi)容為:
  • DirectoryIndex index.html index.html.var index.php
  • usermod -G cacti apache
  • service httpd restart ## 重啟apache以讓php生效
  • php -m ## 查看是否有json被加載
  • 6.修改配置文件以讓npc讀取到新的數(shù)據(jù)。
  • vim /var/www/html/nagios/etc/ndo2db.cfg
  • db_prefix=npc_
  • 6.1 從Web進入Cacti,確保正確使用npc選項。 6.2 修改mysql中的表結(jié)構(gòu):
  • ./mysql -ucacti -p cacti
  • mysql> use cacti;
  • mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
  • mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
  • 7.重啟ndo2db進程,重新加載配置文件重啟nagios服務(wù)。
  • service ndo2db restart
  • service nagios restart
  • 8.在Web上配置NPC以使之正常讀取工作。 在Settings->npc中 ,勾上Remote Commands Nagios Command File Path= /var/www/html/nagios/var/rw/nagios.cmd Nagios URL=你的地址(http://ocalhost/nagios/) 接下來刷新npc就可以看到數(shù)據(jù)啦: 五:Nconf的安裝與配置 1.nconf的準(zhǔn)備工作
  • # 進入mysql數(shù)據(jù)庫
  • mysql> create database nconf;
  • # 創(chuàng)建nconf數(shù)據(jù)庫
  • mysql> grant all privileges on nconf.* to nconf@localhost identified by 'nconf';
  • # 創(chuàng)建nconf用戶并賦權(quán)
  • mysql> flush privileges;
  • # 刷新特權(quán)表
  • mysql> quit
  • 2.安裝nconf
  • wget http://sourceforge.net/projects/nconf/files/nconf/1.2.6-0/nconf-1.2.6-0.tgz/download
  • tar -zxf nconf-1.2.6-0.tgz -C /var/www/html/
  • cd /var/www/html/nconf
  • chown -R apache.apache config/ temp/ static_cfg/ output/
  • 3.進入Web頁面在web頁面按照安裝提示一步步安裝 4.使用剛才創(chuàng)建的nconf數(shù)據(jù)庫和nconf數(shù)據(jù)庫用戶/密碼 5.成功連接mysql數(shù)據(jù)庫,之后一切保持默認(rèn),直到下面的,設(shè)置nconf管理員密碼,此時默認(rèn)登錄用戶為admin 6.之后,網(wǎng)頁安裝完成。
  • rm -rf INSTALL INSTALL.php UPDATE UPDATE.php
  • # 刪除安裝所需的初始化文件
  • ln -s /var/www/html/nagios/bin/nagios bin/nagios
  • chmod +x /var/www/html/nconf/bin/generate_config.pl
  • chown -R apache.apache bin
  • chmod +x /var/www/html/nagios/bin/nagios
  • chmod +x /var/www/html/nconf/ADD-ONS/deploy_local.sh
  • vim /var/www/html/nconf/ADD-ONS/deploy_local.sh
  • 修改里面的Nagios路徑為 /var/www/html/nagios/etc/
  • 7.重新刷新頁面,輸入admin/您設(shè)置的密碼,進入nconf頁面 8.點擊Generate Nagios config嘗試生成配置文件,以測試是否與nagios成功關(guān)聯(lián) 9.最后的設(shè)置 web頁面對監(jiān)控服務(wù)和主機配置完畢,點擊Generate Nagios config ②deploy_local.shnconf自帶配置文件導(dǎo)入腳本
  • /var/www/html/nconf/ADD-ONS/deploy_local.sh
  • 手動執(zhí)行此腳本,將在/var/www/html/nagios/etc下生成兩目錄Default_collectorglobal 修改nagios主配置文件
  • vim /var/www/html/nagios/etc/nagios.cfg
  • # 將其中cfg_file=*******字段全部注釋 ,并加入
  • cfg_dir=/var/www/html/nagios/etc/Default_collector
  • cfg_dir=/var/www/html/nagios/etc/global
  • service nagios reload
  • # 重載nagios配置文件使之生效

  • 六:錯誤總結(jié): 1.啟動ndo2db發(fā)現(xiàn)日志報錯:

    ndomod: Could not open data sink! I'll keep trying, but some output may get lost...

    解決辦法: 檢查 /nagios/etc目錄的權(quán)限是否足夠的大 確保/var/www/html/nagios/etc/nagios.cfg中有如下行出現(xiàn),否則,請自行添加: event_broker_options=-1 檢查ndo2db.cfg中的配置,確保使用tcp連接 socket_type=tcp 檢查ndomod.cfg中的配置,確保使用tcp套接字 output_type=tcpsocket

    2.在npc安裝過程中進行表操作時報錯

    mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
    ERROR 1146 (42S02): Table 'cacti.npc_eventhandlers' doesn't exist

    解決辦法:要先在cacti頁面下正確的啟用npc插件,正確的啟用~一個向上的箭頭和一個向右的箭頭都要開啟才行~

    ?

    3.在應(yīng)用nconf的時候報錯

    點 nconf --> Generate Nagios config --> 報錯了。

    Error accessing or executing Nagios / Icinga binary '/var/www/html/nconf/bin/nagios'.
    Cannot run the mandatory syntax check.

    解決辦法:

    檢查你的/var/www/html/nconf/bin/nagios這個文件所鏈接的那個原始文件的權(quán)限,確保是777或者775

    ?

    4....當(dāng)然還沒有發(fā)現(xiàn)錯誤,如果有,將會繼續(xù)補充,歡迎網(wǎng)友在安裝部署的過程中發(fā)現(xiàn)錯誤將錯誤積極交流,我將一一添加……

    七:最后的樣式

    nagios定義服務(wù)

    vim /var/www/html/nagios/etc/nagios.cfg

    添加定義的東西,cfg_file=/var/www/html/nagios/etc/objects/115.cfg

    cd /var/www/html/nagios/etc/objects

    define host{
    use linux-server ; Name of host template to use
    host_name ser-115
    alias ser-115
    address 192.168.8.115
    }

    ?

    ###############################################################################
    ###############################################################################
    #
    # HOST GROUP DEFINITION
    #
    ###############################################################################
    ###############################################################################

    #define hostgroup{
    # hostgroup_name linux-servers ; The name of the hostgroup
    # alias Linux Servers ; Long name of the group
    # }

    ?

    ###############################################################################
    ###############################################################################
    #
    ###############################################################################
    ###############################################################################


    # Define a service to "ping" the local machine

    define service{
    host_name ser-115
    service_description PING


    # Define a service to check the disk space of the root partition
    # on the local machine. Warning if < 20% free, critical if
    # < 10% free space on partition.

    define service{
    host_name ser-115
    service_description Root Partition

    ?

    # Define a service to check the number of currently logged in
    # users on the local machine. Warning if > 20 users, critical
    # if > 50 users.

    define service{
    check_command check_local_users!20!50
    }


    # Define a service to check the number of currently running procs
    # on the local machine. Warning if > 250 processes, critical if
    # > 400 users.

    define service{
    check_command check_local_procs!250!400!RSZDT
    }

    ?

    # Define a service to check the load on the local machine.

    define service{
    host_name ser-115
    service_description Current Load

    ?

    # Define a service to check the swap usage the local machine.
    # Critical if less than 10% of swap is free, warning if less than 20% is free

    define service{
    host_name ser-115
    service_description Swap Usage
    check_command check_local_swap!20!10
    }

    ?

    # Define a service to check SSH on the local machine.

    define service{
    host_name ser-115
    notifications_enabled 0
    }
    normal_check_interval 1
    use generic-service
    host_name ser-115
    service_description check_8080port
    check_command check_tcp!8080
    }


    define service{
    normal_check_interval 1
    use generic-service
    host_name ser-115
    service_description check_7080port
    check_command check_tcp!7080
    }

    # Define a service to check HTTP on the local machine.

    #define service{
    # host_name localhost
    # service_description HTTP
    # check_command check_http
    # notifications_enabled 0
    # }

    define service{
    normal_check_interval 1
    use generic-service
    host_name ser-115
    service_description check_tomcat8080
    check_command check_tomcat_8080
    }


    define service{
    normal_check_interval 1
    use generic-service
    host_name ser-115
    service_description check_tomcat7080
    check_command check_tomcat_7080
    }
    vim commands.cfg

    define command{
    command_name check_tomcat_8080
    command_line /var/www/html/nagios/libexec/check_http -I $HOSTADDRESS$ -p 8080 -u /f5.jsp -e 200
    }

    define command{
    command_name check_tomcat_7080
    command_line /var/www/html/nagios/libexec/check_http -I $HOSTADDRESS$ -p 7080 -u /f5.jsp -e 200
    }

    轉(zhuǎn)載于:https://blog.51cto.com/loveqianqian/1011630

    總結(jié)

    以上是生活随笔為你收集整理的监控实用篇的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。