测试框架
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
CentOS-6.6-x86_64(minimal)
puppet-3.7.4
nagios-4.0.8. tar .gz
nagios-plugins-2.0.3. tar .gz
nrpe-2.15. tar .gz
192.168.188.10 mirrors.redking.com
192.168.188.20 master.redking.com
192.168.188.20 nagios.redking.com
192.168.188.31 agent1.redking.com
192.168.188.32 agent2.redking.com
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
[root@master ~]
SELINUX=enforcing
SELINUXTYPE=targeted
[root@master ~]
[root@master ~]
SELINUX=disabled
SELINUXTYPE=targeted
[root@master ~]
|
停止iptables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@node1 ~]
ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@node1 ~]
[root@node1 ~]
[root@node1 ~]
ip6tables: Setting chains to policy ACCEPT: filter [ OK ]
ip6tables: Flushing firewall rules: [ OK ]
ip6tables: Unloading modules: [ OK ]
[root@node1 ~]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@node1 ~]
|
设置ntp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@master ~]
[root@master ~]
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@master ~]
[root@master ~]
Starting ntpd: [ OK ]
[root@master ~]
|
2.安装puppet服务
puppet不在CentOS的基本源中,需要加入 PuppetLabs 提供的官方源:
1
2
3
4
5
|
[root@master ~]
[root@master ~]
[root@master ~]
|
在 master上安装和启用 puppet 服务:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@master ~]
[root@master ~]
[root@master ~]
[root@master ~]
Starting puppet agent: [ OK ]
[root@master ~]
Starting puppetmaster: [ OK ]
[root@master ~]
|
在clients上安装puppet客户端
1
2
3
4
5
|
[root@agent1 ~]
[root@agent1 ~]
[root@agent1 ~]
|
3.配置puppet
对于puppet 客户端,修改/etc/puppet/puppet.conf,指定master服务器
![clipboard[1] clipboard[1]](http://s3.51cto.com/wyfs02/M02/59/7E/wKioL1TU1NLR0nZDAALxt-AFf18239.jpg)
并重启puppet服务
4.Client申请证书
服务端自动签发证书设置
设置master自动签发所有的证书,我们只需要在/etc/puppet目录下创建 autosign.conf文件。(不需要修改 /etc/puppet/puppet.conf文件,因为我默认的autosign.conf 文件的位置没有修改)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@master ~]
> *.redking.com
> EOF
[root@master ~]
Stopping puppetmaster: [ OK ]
Starting puppetmaster: [ OK ]
[root@master ~]
|
这样就会对所有来自fisteam2.com的机器的请求,都自动签名。 client需要向服务器端发出请求, 让服务器对客户端进行管理. 这其实是一个证书签发的过程. 第一次运行 puppet 客户端的时候会生成一个 SSL 证书并指定发给 Puppet 服务端, 服务器端如果同意管理客户端,就会对这个证书进行签发,可以用这个命令来签发证书,由于我们已经在客户端设置了server地址,因此不需要跟服务端地址
![clipboard[2] clipboard[2]](http://s3.51cto.com/wyfs02/M00/59/7E/wKioL1TU1NaDuEaJAAE3NS7kIwo417.jpg)
就可以申请证书了,由于我配置的自动签发证书,所以直接就签发了,在服务端执行
![clipboard[3] clipboard[3]](http://s3.51cto.com/wyfs02/M01/59/7E/wKioL1TU1NnhvPYnAAFG23LrUV8288.jpg)
Nagios服务器安装
1.安装Nagios相关依赖包
2.创建Nagios用户与组
1
2
3
|
[root@master ~]
[root@master ~]
|
创建nagcmd用户组以执行来自Web接口命令,并添加nagios和apache用户到此用户组
1
2
3
4
5
|
[root@master ~]
[root@master ~]
[root@master ~]
|
3.下载Nagios和Plugins软件包
http://www.nagios.org/download/下载Nagios Core和Nagios Plugins
![clipboard[4] clipboard[4]](http://s3.51cto.com/wyfs02/M02/59/7E/wKioL1TU1Nux2kKpAAD4NHY-H_k750.jpg)
4.编译安装Nagios
1
2
3
|
[root@master tmp]
[root@master tmp]
|
#运行Nagios配置脚本,并把nagcmd更改为之前所创建的组
1
|
[root@master nagios-4.0.8]
|
#编译Nagios源码
1
|
[root@master nagios-4.0.8]
|
#安装二进制文件、init脚本文件、sample配置文件,设置外部命令目录权限
1
2
3
4
5
6
7
|
[root@master nagios-4.0.8]
[root@master nagios-4.0.8]
[root@master nagios-4.0.8]
[root@master nagios-4.0.8]
|
5.修改配置文件
样式配置文件位于/usr/local/nagios/etc目录,可以更改email地址
1
|
[root@master nagios-4.0.8]
|
6.配置Web界面
在Apache的conf.d目录中安装Nagios Web配置文件
1
|
[root@master nagios-4.0.8]
|
创建nagiosadmin帐号登录Nagios Web接口
1
2
3
4
5
6
7
|
[root@master nagios-4.0.8]
[root@master nagios-4.0.8]
Starting httpd: [ OK ]
[root@master nagios-4.0.8]
|
开启httpd服务使配置生效并设置开机自启
![clipboard[5] clipboard[5]](http://s3.51cto.com/wyfs02/M00/59/7F/wKioL1TU1N7jo2WQAAFazKMJkvs101.jpg)
7.编译安装Nagios Plugins
1
2
3
4
5
6
7
|
[root@master tmp]
[root@master tmp]
[root@master nagios-plugins-2.0.3]
[root@master nagios-plugins-2.0.3]
|
8.编译安装Nrpe
1
2
3
4
5
6
7
8
9
10
11
|
[root@master tmp]
[root@master nrpe-2.15]
[root@master nrpe-2.15]
[root@master nrpe-2.15]
[root@master nrpe-2.15]
[root@master nrpe-2.15]
|
![clipboard[6] clipboard[6]](http://s3.51cto.com/wyfs02/M00/59/7F/wKioL1TU1OWjS2BAAAN5AXtiGiE951.jpg)
9.启动Nagios
本机监控HTTP SSH的Notifications显示警告错误,解决方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
[root@master ~]
define service{
use local -service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 1
}
define service{
use local -service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 1
}
[root@master ~]
|
启动Nagios之前测试配置文件
![clipboard[7] clipboard[7]](http://s3.51cto.com/wyfs02/M01/59/82/wKiom1TU0_3QFtQIAAJwdzd0h4I238.jpg)
启动Nagios、nrpe并设置开机自启
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@master ~]
[root@master ~]
nagios 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@master ~]
[root@master ~]
Starting nagios: done .
[root@master ~]
[root@master nrpe-2.15]
[root@master nrpe-2.15]
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 70100 /nrpe
tcp 0 0 :::5666 :::* LISTEN 70100 /nrpe
[root@master nrpe-2.15]
|
执行/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1检查连接是否正常
![clipboard[8] clipboard[8]](http://s3.51cto.com/wyfs02/M02/59/82/wKiom1TU0_7R2tYaAABi7ImUiIw052.jpg)
使用之前定义的nagiosadmin帐号与密码登录Nagios,地址:http://192.168.188.20/nagios/
![clipboard[9] clipboard[9]](http://s3.51cto.com/wyfs02/M01/59/7F/wKioL1TU1PiDNPpnAAIP6Fq-9sY697.jpg)
![clipboard[10] clipboard[10]](http://s3.51cto.com/wyfs02/M01/59/7F/wKioL1TU1kOBV9HyAAHVsXootsk017.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
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@master ~]
[root@master ~]
[root@master ~]
[root@master ~]
[root@master ~]
[master]
modulepath = /etc/puppet/modules/
|
![clipboard[11] clipboard[11]](http://s3.51cto.com/wyfs02/M02/59/7F/wKioL1TU1kbymtaUAAKKTRjJ-UA850.jpg)
2.创建agent节点组配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@master ~]
[root@master ~]
node /^agent\d+\.redking\.com$/ {
include stdlib
include epel
class { 'puppi' : }
class { 'nrpe' :
require => Class[ 'epel' ],
allowed_hosts => [ '127.0.0.1' ,$::ipaddress, '192.168.188.20' ],
template => 'nrpe/nrpe.cfg.erb' ,
}
}
[root@master ~]
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
2
3
4
5
6
7
8
9
10
11
|
[root@master ~]
define command {
command_name check_nrpe
command_line $USER1$ /check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
|
修改/usr/local/nagios/etc/nagios.cfg
1
2
3
4
5
6
7
|
[root@master ~]
cfg_file= /usr/local/nagios/etc/objects/agent1 .redking.com.cfg
cfg_file= /usr/local/nagios/etc/objects/agnet2 .redking.com.cfg
cfg_file= /usr/local/nagios/etc/objects/agent3 .redking.com.cfg
|
增加agent1~3.redking.com.cfg配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
define host{
use linux-server
host_name agent1.redking.com
alias agent1.redking.com
address 192.168.188.31
}
define service{
use generic-service
host_name agent1.redking.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service
host_name agent1.redking.com
service_description Current Users
check_command check_nrpe!check_users!10!5
}
define service{
use generic-service
host_name agent1.redking.com
service_description Current Load
check_command check_nrpe!check_load!15,10,5!30,25,20
}
define service{
use generic-service
host_name agent1.redking.com
service_description Swap Usage
check_command check_nrpe!check_swap!20!40
}
|
检测Nagios服务并重启使配置生效
1
2
3
4
5
|
[root@master ~]
[root@master ~]
[root@master ~]
|
![clipboard[12] clipboard[12]](http://s3.51cto.com/wyfs02/M00/59/7F/wKioL1TU1krDbsngAAJZwPkh_ag648.jpg)
客户端测试
客户端自动部署nrpe
![clipboard[13] clipboard[13]](http://s3.51cto.com/wyfs02/M01/59/7F/wKioL1TU1laBcnLDAAOuN4H8wGI393.jpg)
下面我们来看下客户端自动化部署nrpe后采集信息的nagios监控界面
![clipboard[14] clipboard[14]](http://s3.51cto.com/wyfs02/M02/59/7F/wKioL1TU1mCDbMIBAAGqOhTzr2I983.jpg)
![clipboard[15] clipboard[15]](http://s3.51cto.com/wyfs02/M00/59/7F/wKioL1TU1mfBrizTAAFH_UH8M-s751.jpg)
![clipboard[16] clipboard[16]](http://s3.51cto.com/wyfs02/M01/59/7F/wKioL1TU1m_i4afjAAF_dj12u9U570.jpg)
![clipboard[17] clipboard[17]](http://s3.51cto.com/wyfs02/M02/59/7F/wKioL1TU1oHBvFnCAALTzYIdhd8522.jpg)
![clipboard[18] clipboard[18]](http://s3.51cto.com/wyfs02/M00/59/7F/wKioL1TU1pGQbAFEAAI9s6rNtqs904.jpg)
![clipboard[19] clipboard[19]](http://s3.51cto.com/wyfs02/M01/59/7F/wKioL1TU1qPA6jHPAALc1NKqUbw390.jpg)
NRPE模块中定义的nrpe.cfg包含大量脚本,我们可以直接拿来使用当然也可以自己修改nrpe.cfg.erb模板内容。在批量部署时可以分别采用自己编写的模块或者现有模块来实现,利用现有模块几乎能实现系统管理日常工作中90%任务,剩余的10%我们可以根据生产业务来自己定制。
![clipboard[20] clipboard[20]](http://s3.51cto.com/wyfs02/M02/59/7F/wKioL1TU1rGDrR7LAAIk7TuVdL0861.jpg)
========================END=================================
本文转自redking51CTO博客,原文链接:http://blog.51cto.com/redking/1612136,如需转载请自行联系原作者