设为首页 收藏本站
查看: 1736|回复: 0

[经验分享] CentOS6.6+Puppet3.7.4分布式部署Nagios监控系统

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-2-6 08:07:16 | 显示全部楼层 |阅读模式
测试框架
1  CentOS-6.6-x86_64(minimal)         
2  puppet-3.7.4         
3  nagios-4.0.8.tar.gz         
4  nagios-plugins-2.0.3.tar.gz         
5  nrpe-2.15.tar.gz         
6  192.168.188.10 mirrors.redking.com         
7  192.168.188.20 master.redking.com         
8  192.168.188.20 nagios.redking.com         
9  192.168.188.31 agent1.redking.com         
10 192.168.188.32 agent2.redking.com         
11 192.168.188.33 agent3.redking.com         


Puppet 要求所有机器有完整的域名(FQDN),如果没有 DNS 服务器提供域名的话,可以在两台机器上设置主机名(注意要先设置主机名再安装 Puppet,因为安装 Puppet 时会把主机名写入证书,客户端和服务端通信需要这个证书),因为我配置了DNS,所以就不用改hosts了,如果没有就需要改hosts文件指定。
1.关闭selinux,iptables,并设置ntp      
采用CentOS-6.6-x86_64.iso进行minimal最小化安装
关闭selinux
1  [iyunv@master ~]# cat /etc/selinux/config        
2  # This file controls the state of SELinux on the system.        
3  # SELINUX= can take one of these three values:        
4  # enforcing - SELinux security policy is enforced.        
5  # permissive - SELinux prints warnings instead of enforcing.        
6  # disabled - No SELinux policy is loaded.        
7  SELINUX=enforcing        
8  # SELINUXTYPE= can take one of these two values:        
9  # targeted - Targeted processes are protected,        
10 # mls - Multi Level Security protection.        
11 SELINUXTYPE=targeted        
12 [iyunv@master ~]# sed -i '/SELINUX/ s/enforcing/disabled/g' /etc/selinux/config        
13 [iyunv@master ~]# cat /etc/selinux/config        
14 # This file controls the state of SELinux on the system.        
15 # SELINUX= can take one of these three values:        
16 # enforcing - SELinux security policy is enforced.        
17 # permissive - SELinux prints warnings instead of enforcing.        
18 # disabled - No SELinux policy is loaded.        
19 SELINUX=disabled        
20 # SELINUXTYPE= can take one of these two values:        
21 # targeted - Targeted processes are protected,        
22 # mls - Multi Level Security protection.        
23 SELINUXTYPE=targeted        
24 [iyunv@master ~]# setenforce 0      

停止iptables
1  [iyunv@node1 ~]# chkconfig --list |grep tables        
2  ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off        
3  iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off        
4  [iyunv@node1 ~]# chkconfig ip6tables off        
5  [iyunv@node1 ~]# chkconfig iptables off        
6  [iyunv@node1 ~]# service ip6tables stop        
7  ip6tables: Setting chains to policy ACCEPT: filter [ OK ]        
8  ip6tables: Flushing firewall rules: [ OK ]        
9  ip6tables: Unloading modules: [ OK ]        
10 [iyunv@node1 ~]# service iptables stop        
11 iptables: Setting chains to policy ACCEPT: filter [ OK ]        
12 iptables: Flushing firewall rules: [ OK ]        
13 iptables: Unloading modules: [ OK ]        
14 [iyunv@node1 ~]#      

设置ntp
1 [iyunv@master ~]# ntpdate pool.ntp.org      
2 [iyunv@master ~]# chkconfig --list|grep ntp        
3 ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off        
4 ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off        
5 [iyunv@master ~]# chkconfig ntpd on        
6 [iyunv@master ~]# service ntpd start        
7 Starting ntpd: [ OK ]        
8 [iyunv@master ~]#   

2.安装puppet服务     
puppet不在CentOS的基本源中,需要加入 PuppetLabs 提供的官方源:
1  [iyunv@master ~]# wget http://yum.puppetlabs.com/el/6/p ... ease-6-7.noarch.rpm     
2  [iyunv@master ~]# rpm -ivh puppetlabs-release-6-7.noarch.rpm     
3  [iyunv@master ~]# yum update -y   


在 master上安装和启用 puppet 服务:   
1  [iyunv@master ~]# yum install -y puppet-server   
2  [iyunv@master ~]# chkconfig puppet on     
3  [iyunv@master ~]# chkconfig puppetmaster on   
4  [iyunv@master ~]# service puppet start   
5  Starting puppet agent:                                     [  OK  ]   
6  [iyunv@master ~]# service puppetmaster start   
7  Starting puppetmaster:                                     [  OK  ]   
8  [iyunv@master ~]#     

在clients上安装puppet客户端
1  [iyunv@agent1 ~]# yum install -y puppet     
2  [iyunv@agent1 ~]# chkconfig puppet on     
3  [iyunv@agent1 ~]# service puppet start   

3.配置puppet
对于puppet 客户端,修改/etc/puppet/puppet.conf,指定master服务器
wKiom1TTf6mj_2YBAALxt-AFf18473.jpg
并重启puppet服务
1  [iyunv@agent1 ~]# service puppet restart     

4.Client申请证书     
服务端自动签发证书设置     
设置master自动签发所有的证书,我们只需要在/etc/puppet目录下创建 autosign.conf文件。(不需要修改 /etc/puppet/puppet.conf文件,因为我默认的autosign.conf 文件的位置没有修改)
1  [iyunv@master ~]# cat > /etc/puppet/autosign.conf <<eof
2  > *.redking.com   
3  > EOF   
4  [iyunv@master ~]# service puppetmaster restart     
5  Stopping puppetmaster:                                     [  OK  ]   
6  Starting puppetmaster:                                     [  OK  ]   
7  [iyunv@master ~]#     

这样就会对所有来自fisteam2.com的机器的请求,都自动签名。     
client需要向服务器端发出请求, 让服务器对客户端进行管理. 这其实是一个证书签发的过程. 第一次运行 puppet 客户端的时候会生成一个 SSL 证书并指定发给 Puppet 服务端, 服务器端如果同意管理客户端,就会对这个证书进行签发,可以用这个命令来签发证书,由于我们已经在客户端设置了server地址,因此不需要跟服务端地址
1  [iyunv@agent1 ~]# puppet agent --test   

wKiom1TTf63BVXXeAAE3NS7kIwo542.jpg
就可以申请证书了,由于我配置的自动签发证书,所以直接就签发了,在服务端执行
1  [iyunv@master ~]# puppet cert list --all   

wKiom1TTf7ChEKgzAAFG23LrUV8994.jpg
Nagios服务器安装
1.安装Nagios相关依赖包
1  [iyunv@master ~]# yum install -y httpd php gcc glibc glibc-common gd gd-devel openssl-devel   

2.创建Nagios用户与组
1  [iyunv@master ~]# useradd -m nagios   
2  [iyunv@master ~]# passwd nagios   

创建nagcmd用户组以执行来自Web接口命令,并添加nagios和apache用户到此用户组
1  [iyunv@master ~]# groupadd nagcmd   
2  [iyunv@master ~]# usermod -a -G nagcmd nagios   
3  [iyunv@master ~]# usermod -a -G nagcmd apache   

3.下载Nagios和Plugins软件包
http://www.nagios.org/download/下载Nagios Core和Nagios Plugins
wKiom1TTf7OR7UVmAAD4NHY-H_k752.jpg
4.编译安装Nagios
1  [iyunv@master tmp]# tar zxf nagios-4.0.8.tar.gz     
2  [iyunv@master tmp]# cd nagios-4.0.8   

#运行Nagios配置脚本,并把nagcmd更改为之前所创建的组
1  [iyunv@master nagios-4.0.8]# ./configure --with-command-group=nagcmd   

#编译Nagios源码
1  [iyunv@master nagios-4.0.8]# make all   

#安装二进制文件、init脚本文件、sample配置文件,设置外部命令目录权限
1  [iyunv@master nagios-4.0.8]# make install      
2  [iyunv@master nagios-4.0.8]# make install-init      
3  [iyunv@master nagios-4.0.8]# make install-config      
4  [iyunv@master nagios-4.0.8]# make install-commandmode      

5.修改配置文件
样式配置文件位于/usr/local/nagios/etc目录,可以更改email地址
1  [iyunv@master nagios-4.0.8]# vim /usr/local/nagios/etc/objects/contacts.cfg     

6.配置Web界面
在Apache的conf.d目录中安装Nagios Web配置文件
1  [iyunv@master nagios-4.0.8]# make install-webconf   

创建nagiosadmin帐号登录Nagios Web接口
1  [iyunv@master nagios-4.0.8]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin   
2  [iyunv@master nagios-4.0.8]# service httpd start   
3  Starting httpd:                                            [  OK  ]   
4  [iyunv@master nagios-4.0.8]# chkconfig httpd on   

开启httpd服务使配置生效并设置开机自启
wKiom1TTf7iBH-dLAAFazKMJkvs360.jpg
7.编译安装Nagios Plugins
1  [iyunv@master tmp]# tar zxvf nagios-plugins-2.0.3.tar.gz     
2  [iyunv@master tmp]# cd nagios-plugins-2.0.3   
3  [iyunv@master nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios   
4  [iyunv@master nagios-plugins-2.0.3]# make && make install   

8.编译安装Nrpe
1  [iyunv@master tmp]# tar zxvf nrpe-2.15.tar.gz   
2  [iyunv@master nrpe-2.15]# ./configure   
3  [iyunv@master nrpe-2.15]# make all   
4  [iyunv@master nrpe-2.15]# make install-plugin   
5  [iyunv@master nrpe-2.15]# make install-daemon   
6  [iyunv@master nrpe-2.15]# make install-daemon-config   

wKiom1TTf8CCVqC-AAN5AXtiGiE547.jpg
9.启动Nagios
本机监控HTTP SSH的Notifications显示警告错误,解决方法
1   [iyunv@master ~]# vim /usr/local/nagios/etc/objects/localhost.cfg   
2   # Define a service to check SSH on the local machine.   
3   # Disable notifications for this service by default, as not all users may have SSH enabled.   
4   define service{   
5   use                             local-service         ; Name of service template to use   
6   host_name                       localhost   
7   service_description             SSH   
8   check_command                   check_ssh   
9   notifications_enabled           1  #改为1,即可   
10  }   
11  # Define a service to check HTTP on the local machine.   
12  # Disable notifications for this service by default, as not all users may have HTTP enabled.   
13  define service{   
14  use                             local-service         ; Name of service template to use   
15  host_name                       localhost   
16  service_description             HTTP   
17  check_command                   check_http   
18  notifications_enabled           1  #改为1,即可   
19  }   
20  [iyunv@master ~]# touch /var/www/html/index.html   

启动Nagios之前测试配置文件
1  [iyunv@master ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg     

wKiom1TTf8aT1OloAAJwdzd0h4I174.jpg
启动Nagios、nrpe并设置开机自启
1   [iyunv@master ~]# chkconfig nagios --add   
2   [iyunv@master ~]# chkconfig --list |grep nagios     
3   nagios          0:off   1:off   2:off   3:on    4:on    5:on    6:off   
4   [iyunv@master ~]# chkconfig nagios on   
5   [iyunv@master ~]# service nagios start   
6   Starting nagios: done.   
7   [iyunv@master ~]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local   
8   [iyunv@master nrpe-2.15]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d     
9   [iyunv@master nrpe-2.15]# netstat -tunpl |grep nrpe     
10  tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 70100/nrpe   
11  tcp 0 0 :::5666 :::* LISTEN 70100/nrpe   
12  [iyunv@master nrpe-2.15]#   

执行/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1检查连接是否正常
wKiom1TTf8mxAlb7AABi7ImUiIw992.jpg
使用之前定义的nagiosadmin帐号与密码登录Nagios,地址:http://192.168.188.20/nagios/
wKiom1TTf9XQ5UXnAAIP6Fq-9sY790.jpg
wKiom1TTf-CiJdOVAAHVsXootsk103.jpg
创建Nagios客户端监控
1.Puppet Master安装相应模块
Nagios没有目前没有提供官方软件源,在批量部署时可以使用第三方epel源,采用Example42所提供的puppet-nrpe来实现Linux服务器批量部署。部署客户端使用官方3个模块:epel、nrpe、puppi。
epel模块用于安装nrpe软件,nrpe模块用于收集主机信息,puppi属于Example42模块组件,使用Example42模块时都需要加载此模块。
Puppi是一个Puppet模块和CLI命令,他可以标准化和自动化快速部署应用程序,并提供快速和标准查询命令,检查系统资源。
1  [iyunv@master ~]# git clone https://github.com/puppetlabs/puppetlabs-stdlib /etc/puppet/modules/stdlib   
2  [iyunv@master ~]# git clone https://github.com/example42/puppi /etc/puppet/modules/puppi   
3  [iyunv@master ~]# git clone https://github.com/example42/puppet-nrpe /etc/puppet/modules/nrpe   
4  [iyunv@master ~]# puppet module install stahnma/epel   
5  [iyunv@master ~]# vim /etc/puppet/puppet.conf     
6  [master]   
7  modulepath = /etc/puppet/modules/   

wKiom1TTf-PgiYlHAAKKTRjJ-UA137.jpg
2.创建agent节点组配置文件
1   [iyunv@master ~]# mkdir /etc/puppet/manifests/nodes   
2   [iyunv@master ~]# vim /etc/puppet/manifests/nodes/agentgroup.pp   
3   node /^agentd+.redking.com$/ {   
4   include stdlib   
5   include epel   
6   class { 'puppi': }   
7   class { 'nrpe':     
8   require => Class['epel'],   
9   allowed_hosts => ['127.0.0.1',$::ipaddress,'192.168.188.20'],   
10  template => 'nrpe/nrpe.cfg.erb',   
11  }   
12  }   
13  [iyunv@master ~]# vim /etc/puppet/manifests/site.pp   
14  import "nodes/agentgroup.pp"   

3.配置Nagios添加agent.redking.com主机监控
修改/usr/local/nagios/etc/objects/commands.cfg
command_name check_nrpe ——定义命令名称为check_nrpe,services.cfg必须使用
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ ——用$USER1$代替/usr/local/nagios/libexec
这是定义实际运行的插件程序.这个命令行的书写要完全按照check_nrpe这个命令的用法.不知道用法的就用check_nrpe –h查看; -c后面带的$ARG1$参数是传给nrpe daemon执行的检测命令,它必须是nrpe.cfg中所定义的5条命令中的其中一条。
1  [iyunv@master ~]# vim /usr/local/nagios/etc/objects/commands.cfg     
2  # 'check_nrpe' command definition   
3  define command{   
4  command_name check_nrpe   
5  command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$   
6  }   

修改/usr/local/nagios/etc/nagios.cfg
1  [iyunv@master ~]# vim /usr/local/nagios/etc/nagios.cfg     
2  cfg_file=/usr/local/nagios/etc/objects/agent1.redking.com.cfg   
3  cfg_file=/usr/local/nagios/etc/objects/agnet2.redking.com.cfg   
4  cfg_file=/usr/local/nagios/etc/objects/agent3.redking.com.cfg   

增加agent1~3.redking.com.cfg配置文件
1   # vim /usr/local/nagios/etc/objects/agent1.redking.com.cfg   
2   define host{   
3   use             linux-server   
4   host_name       agent1.redking.com   
5   alias agent1.redking.com   
6   address         192.168.188.31   
7   }   
8      
9   define service{   
10  use                     generic-service   
11  host_name               agent1.redking.com   
12  service_description     PING   
13  check_command           check_ping!100.0,20%!500.0,60%   
14  }   
15      
16  define service{   
17  use                     generic-service   
18  host_name               agent1.redking.com   
19  service_description     Current Users   
20  check_command           check_nrpe!check_users!10!5   
21  }   
22      
23  define service{   
24  use                     generic-service   
25  host_name               agent1.redking.com   
26  service_description     Current Load   
27  check_command           check_nrpe!check_load!15,10,5!30,25,20   
28  }   
29      
30  define service{   
31  use                     generic-service   
32  host_name               agent1.redking.com   
33  service_description     Swap Usage   
34  check_command           check_nrpe!check_swap!20!40   
35  }   

检测Nagios服务并重启使配置生效
1  [iyunv@master ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg     
2  [iyunv@master ~]# service nagios restart   
3  [iyunv@master ~]# service puppetmaster restart     

wKiom1TTf-bT_RhxAAJZwPkh_ag589.jpg
客户端测试
1  [iyunv@agent1 ~]# puppet agent --test   

客户端自动部署nrpe
wKioL1TTgOLhSJjcAAOuN4H8wGI560.jpg
下面我们来看下客户端自动化部署nrpe后采集信息的nagios监控界面
wKioL1TTgO6iBwxoAAGqOhTzr2I830.jpg
wKioL1TTgPWwvizzAAFH_UH8M-s327.jpg
wKioL1TTgP3iFShzAAF_dj12u9U657.jpg
wKioL1TTgQ7CmA4wAALTzYIdhd8384.jpg
wKioL1TTgR2jniI9AAI9s6rNtqs237.jpg
wKiom1TTgEHi9A-FAALgzfbA8xg886.jpg
NRPE模块中定义的nrpe.cfg包含大量脚本,我们可以直接拿来使用当然也可以自己修改nrpe.cfg.erb模板内容。在批量部署时可以分别采用自己编写的模块或者现有模块来实现,利用现有模块几乎能实现系统管理日常工作中90%任务,剩余的10%我们可以根据生产业务来自己定制。
wKioL1TTgTqhffLuAAIk7TuVdL0638.jpg


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-42022-1-1.html 上篇帖子: puppet(三)语法和命令参数 下篇帖子: Puppet之安装dashboard 成功版 监控系统
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表