您的位置:首页 > 移动开发 > IOS开发

生产环境下搭建 nagios+nconf+cacti+npc的整合

2017-08-19 18:17 537 查看
系统:CentOS6.5 内核版本系统:2.6.32-431.23.3.el6.x86_64关闭iptables 、selinuxchkconfig iptables off安装前的准备工作yum install -y httpd-*  mysql-* php-*  net-snmp*  gcc glibc glibc-common gd gd-devel openssl*一、nagios 环境的搭建1.安装nagiosuseradd nagiostar zxf nagios-3.2.0.tar.gzcd nagios-3.2.0./configure -prefix=/var/www/html/nagiosmake allmake install && make install-init && make install-commandmode && make install-config && make install-webconf2.安装中文的nagios这个比较简单就跟打补丁一样tar zxf nagios-cn-3.2.0.tar.bz2cd nagios-cn-3.2.0./configure -prefix=/var/www/html/nagiosmake allmake install && make install-init && make install-commandmode && make install-config && make install-webconf3.增加nagios登陆认证文件,一定要用默认的nagiosadmin作为用户htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin*否则需要修改/var/www/html/nagios/etc/cgi.cfg这个文件vi  /etc/nagios/cgi.cfgauthorized_for_system_information=nagiosadminauthorized_for_configuration_information=nagiosadminauthorized_for_system_commands=nagiosadminauthorized_for_all_services=nagiosadminauthorized_for_all_hosts=nagiosadminauthorized_for_all_service_commands=nagiosadminauthorized_for_all_host_commands=nagiosadmin  4.安装插件:tar xf nagios-plugins-1.4.14.tar.gzcd nagios-plugins-1.4.14./configure -prefix=/var/www/html/nagios/makemake install 5.将运行Apache的用户添加到nagios组里,这样Apache才有权限读取文件usermod -G nagios apache    ##将apache用户加到nagios组。6.阶段测试chown nagios.nagios /var/www/html/nagios/ -Rservice httpd restart chkconfig httpd on  /etc/init.d/nagios start*问http://IP/nagios 看看账号密码对不对二:cacti环境的搭建1.rrdtool的安装这里需要安装的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php, rrdtool-python我用的rrdtools的版本是 1.3.8-7.el6.x86_64,由于我用的是阿里云yum里有rrdtool 所以我就直接yum install rrdtool* 来进行安装rrdtool-devel-1.3.8-7.el6.x86_64rrdtool-perl-1.3.8-7.el6.x86_64rrdtool-1.3.8-7.el6.x86_64rrdtool-php-1.3.8-7.el6.x86_64rrdtool-python-1.3.8-7.el6.x86_64如果没有自行下载。下载完成后,本地yum安装。(百度云里面有1.4的)yum localinstall -y --nogpgcheck rrdtool-*service mysqld start2.配置snmpvim /etc/snmp/snmpd.confcom2sec notConfigUser  127.0.0.1       publicaccess  notConfigGroup ""      any       noauth    exact  all none noneview all    included  .1                               80*前两行是修改最后一行是取消注释service snmpd restartsnmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 2IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 3显示以上信息,则snmp配置成功,xxx.xxx.xxx.xxx会根据你本机的IP信息配置而不同。3.安装cacticacti-0.8.7e-cn-utf8.tar.gzmv cacti-0.8.7e-cn-utf8 /var/www/html/cacti4.创建cacti数据库#mysqlmysql>create database cacti default character set utf8;    //数据库字符集设置utf8,否则乱码mysql>grant all privileges on cacti.* to cacti@localhost identified by ‘cacti’ with grant option;mysql>flush privileges;
5.将cacti的表内容导入创建的数据库cd /var/www/html/cacti mysql -ucacti -pcacti cacti < cacti.sql6.编辑.php文件,以适应环境。vim /var/www/html/cacti/include/config.php修改内容如下$database_type = "mysql";$database_default = "cacti";$database_hostname = "localhost";$database_username = "cacti";$database_password = "cacti";  useradd -r -M cactichown -R cacti /var/www/html/cacti/rra/chown -R cacti /var/www/html/cacti/log/7.在cacti用户下创建计划任务以画图vim /etc/crontab*/5 * * * * root php /var/www/html/cacti/poller.php &>/dev/nullphp /var/www/html/cacti/poller.php > /dev/null 2>&18.安装中文字体否则图像文字上是乱码mkdir /ttfmv ttf-arphic-ukai_0.2.20080216.1.orig.tar.gz /ttfcd /ttftar xf ttf-arphic-ukai_0.2.20080216.1.orig.tar.gzmv ukai.ttc /usr/share/fonts/ukai.ttcrm –rf /ttf9.从web页面启动cacti,安装,并查看图形化界面控制面板 > 设备 > 本机 > SNMP选项 > SNMP 版本 选择 版本1  > 保存控制面板 > 设置 > 路径 > RRDTool默认字体路径  /usr/share/fonts/ukai.ttc > 保存如果配置正确,隔几分钟,我们的cacti就会有数据了,如图,你也可以手动执行以下命令手动生成rrd图像php /var/www/html/cacti/poller.php
 


SNMP 版本号

字体路径中文的图表

三:安装cacti-spine1. cacti-spine的安装由于默认cmd.php来轮询数据,速度会很慢,特别是在监控节点比较多的情况下,cmd.php就更显不足了,因此我们采用Spine来轮询数据。cacti-spine是一个由C语言开发的,用于替代cmd.php的快速获取速度的引擎。tar xf cacti-spine-0.8.7e.tar.gzcd cacti-spine-0.8.7e./configure#make && make installvi /usr/local/spine/etc/spine.conf修改内容如下:DB_Host         localhostDB_Database     cactiDB_User         cactiDB_Pass         cactiDB_Port         3306/usr/local/spine/bin/spineecho /usr/local/spine/bin/spine >>/etc/rc.d/rc.local*如果你直接成功了那么恭喜你请直接看2.cacti-spine的应用,如果出现报错*[root@iZ2314cchhjZ cacti-spine-0.8.7e]# ./configureconfigure: error: cannot run /bin/sh config/config.sub[root@iZ2314cchhjZ cacti-spine-0.8.7e]# 解决步骤cd cacti-spine-0.8.7e/configll -hrm -rf config.guess config.sub ltmain.shln -s -f /usr/share/libtool/config/config.sub config.subln -s -f /usr/share/libtool/config/config.guess config.guessln -s -f /usr/share/libtool/config/ltmain.sh ltmain.shcd .../configuremakemake installvi /usr/local/spine/etc/spine.conf修改内容如下:DB_Host         localhostDB_Database     cactiDB_User         cactiDB_Pass         cactiDB_Port         3306/usr/local/spine/bin/spineecho /usr/local/spine/bin/spine >>/etc/rc.d/rc.local*如果你make 成功了请忽略这里*这时候你make 报错,这是因为你可能没有装 libtool 或者libtool的版本不匹配./libtool: line 467: CDPATH: command not found./libtool: line 1145: func_opt_split: command not foundlibtool: Version mismatch error.  This is libtool 2.2.6b, but thelibtool: definition of this LT_INIT comes from an older release.libtool: You should recreate aclocal.m4 with macros from libtool 2.2.6blibtool: and run autoconf again.make: *** [spine] 错误 63先检查你有没有安装libtool 如果没有就yum install libtool*  然后在进行尝试如果还不行的[root@iZ2314cchhjZ cacti-spine-0.8.7e]# autoreconf --force --install[root@iZ2314cchhjZ cacti-spine-0.8.7e]# makemake installvi /usr/local/spine/etc/spine.conf修改内容如下:DB_Host         localhostDB_Database     cactiDB_User         cactiDB_Pass         cactiDB_Port         3306/usr/local/spine/bin/spineecho /usr/local/spine/bin/spine >>/etc/rc.d/rc.local2.cacti-spine的应用控制面板 > 设置 >  路径 > Spine轮询器路径  /usr/local/spine/bin/spine   控制面板 > 设置 > 轮询器 >  轮询器类型  spine


  四:整合Nagios与Cacti1.下载并安装ndoutilstar 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/mysqlmake2.准备配置文件cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /var/www/html/nagios/bincd db./installdb -ucacti -pcacti -hlocalhost -d cacticd ..cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /var/www/html/nagios/etcmv /var/www/html/nagios/etc/ndo2db.cfg-sample /var/www/html/nagios/etc/ndo2db.cfgmv /var/www/html/nagios/etc/ndomod.cfg-sample /var/www/html/nagios/etc/ndomod.cfgchmod 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配置文件以适应当前环境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 broker4.修改ndo2db.cfg以适应当前环境vim /var/www/html/nagios/etc/ndo2db.cfg # 确保下列内容为唯一项     socket_type=unix     db_servertype=mysql      db_host=localhost      db_port=3306      db_name=cacti      db_prefix=nagios_      db_user=cacti      db_pass=cacti 5.修改ndomod.cfg以适应当前环境vim /var/www/html/nagios/etc/ndomod.cfg   # 确保下列项的唯一内容为    output_type=unixsocket    output=127.0.0.1 6.为ndo2db添加启动进程cp ./daemon-init /etc/init.d/ndo2dbvim /etc/init.d/ndo2db    # 并将Ndo2dbBin修改成下面的值:     Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3x chmod +x /etc/init.d/ndo2db 7.启动守护进程与nagiosservice ndo2db starttail -20 /var/log/messages    ## 查看其中是否有错误出现。如无报错请继续service nagios restart五:安装cacti-plugin 插件管理Cacti-Plugin安装过程如下:gunzip cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff.gzmv cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff /var/www/cacti/cd /var/www/html/cactimysql -ucacti -pcacti cacti < pa.sql patch -p1 -N < cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff如果你的cacti访问时候是使用http://ip/cacti,你需要修改/var/www/cacti/include/global.php修改如下:$database_type = "mysql";$database_default = "cacti";$database_hostname = "localhost";$database_username = "cacti";$database_password = "cacti";$database_port = "3306"; $config['url_path'] = '/cacti/';          #记住是修改不是添加 配置Cacti控制面板 > 用户管理 > admin > 区域权限,选择”插件管理” > 保存然后我们就能够在控制面板的”配置”下面看到多出一个”插件管理”的选项
  

 六:安装NPC 插件 tar zxvf npc-2.0.4.tar.gzmv npc /var/www/html/cacti/plugins/vim /var/www/html/cacti/include/config.php    # 加入:     $plugins[] = 'npc';

1.安装 npc支持:json    (看情况进行安装)先使用这条命令看看PHP里有没有JSON的模块php -m | grep json如果有了就略过。tar zxvf json-1.2.1.tgz cd json-1.2.1phpize   ## 如果发现没有Phpize文件,则是因为php-devel包没有安装导致的 ./configure make && make install php -i | grep php.ini  ## 查看是否有导入信息打开php.ini文件添加对json的支持vim /etc/php.ini   # 添加    extension=json.so  php -m   ## 查看是否有json被加载2.配置npc基本环境一.为apache添加php支持。vim /etc/httpd/conf/httpd.conf    # 添加一行:     AddType application/x-httpd-php .php .phtml   # 修改原DirectoryIndex内容为:     DirectoryIndex index.html index.html.var index.php usermod -G cacti apacheservice httpd restart    ## 重启apache以让php生效 学神科技有限公司Linux讲师:top  联系QQ 3059942361   想要深入学习Linux系统架构师,可以随时与我联系二.修改配置文件以让npc读取到新的数据。vim /var/www/html/nagios/etc/ndo2db.cfg     db_prefix=npc_  三. 修改mysql中的表结构:#mysql -ucacti -pcactimysql> 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;四.重启ndo2db进程,重新加载配置文件重启nagios服务。service ndo2db restartservice nagios restart五.在Web上配置NPC以使之正常读取工作。控制面板 > 插件管理 > 安装 > 启用控制面板 > 设置 > NPCNagios Command File Path= /var/www/html/nagios/var/rw/nagios.cmdNagios URL=你的地址(http://101.200.175.24/nagios)接下来刷新npc就可以看到数据啦 如果你点开NPC的时候状态是OFF的话。进行操作如下:vim /var/www/html/nagios/etc/ndomod.cfg# 修改output_type=tcpsocketvim /var/www/html/nagios/etc/ndo2db.cfg# 修改socket_type=tcp*一定要保证是唯一项*七:Nconf的安装与配置1.nconf的准备工作#mysqlmysql> create database nconf;  mysql> grant all privileges on nconf.* to nconf@localhost identified by ‘nconf’; mysql> flush privileges;mysql> quit 

2.安装nconftar -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页面按照安装提示一步步安装*使用刚才创建的nconf数据库和nconf数据库用户/密码4.成功连接mysql数据库之后一切保持默认,直到下面的,设置nconf管理员密码,此时默认登录用户为admin5.之后,网页安装完成。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/nagioschmod +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/

6.重新刷新网页7.点击Generate Nagios config尝试生成配置文件,以测试是否与nagios成功关联 8.最后的设置一.在web页面对监控服务和主机配置完毕,点击Generate Nagios config二.deploy_local.sh是nconf自带配置文件导入脚本/var/www/html/nconf/ADD-ONS/deploy_local.sh手动执行此脚本,将在/var/www/html/nagios/etc下生成两目录Default_collector与global三.修改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配置文件使之生效

本文出自 “xinsz08の平行时空” 博客,请务必保留此出处http://xinsz08.blog.51cto.com/10565212/1915915
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: