1时间问题

agent与master端务必要保持时间的一致性,最好使用ntp服务

检查ntp服务是否安装

[root@master-elk ~]# rpm -qa|grep ntp
ntpdate-4.2.6p5-.el6.centos..x86_64
ntp-4.2.6p5-.el6.centos..x86_64

由于我使用的阿里云的服务器,这个已经默认配置好了,如下

 cat  /etc/ntp.conf

 # ntp.conf

 driftfile  /var/lib/ntp/drift
pidfile /var/run/ntpd.pid
logfile /var/log/ntp.log # Access Control Support
restrict default kod nomodify notrap nopeer noquery
restrict - default kod nomodify notrap nopeer noquery
restrict 127.0.0.1 # local clock
server 127.127.1.0
fudge 127.127.1.0 stratum server ntp1.aliyun.com iburst minpoll maxpoll
restrict ntp1.aliyun.com nomodify notrap nopeer noquery
server ntp2.aliyun.com iburst minpoll maxpoll
restrict ntp2.aliyun.com nomodify notrap nopeer noquery
server ntp3.aliyun.com iburst minpoll maxpoll
restrict ntp3.aliyun.com nomodify notrap nopeer noquery
server ntp4.aliyun.com iburst minpoll maxpoll
restrict ntp4.aliyun.com nomodify notrap nopeer noquery
server ntp5.aliyun.com iburst minpoll maxpoll
restrict ntp5.aliyun.com nomodify notrap nopeer noquery
server ntp6.aliyun.com iburst minpoll maxpoll
restrict ntp6.aliyun.com nomodify notrap nopeer noquery
server ntp1.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp1.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp2.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp2.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp3.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp3.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp4.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp4.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp5.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp5.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp6.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp6.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp7.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp7.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp8.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp8.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp9.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp9.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp10.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp10.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp11.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp11.cloud.aliyuncs.com nomodify notrap nopeer noquery
server ntp12.cloud.aliyuncs.com iburst minpoll maxpoll
restrict ntp12.cloud.aliyuncs.com nomodify notrap nopeer noquery

启动并且加入开启启动

 /etc/init.d/ntpd  start
chkconfig ntpd on

最好在计划任务里面加上

   * * * ntpdate cn.pool.ntp.org && hwclock -w

重启计划任务

  /etc/init.d/crond restart

补充:

先来了解一下puppet的配置文件

 # puppet主配置及目录结构

 /etc/puppet
auth.conf - Agent访问Master的权限控制文件
authsign.conf - Master对Agent证书自动签名的配置文件
fileserver.conf - Master向Agent同步静态文件的配置文件(Master挂载目录位置和挂载目录的授权信息)
puppet.conf - Master守护进程的主要配置文件,定义了运行环境、启动加载文件、配置管理程序、授权Agent的证书目录等信息
tagmail.conf - Puppet邮件发送配置文件
namespaceauth.conf - 名称空间配置文件
files/ - Master存放的静态文件
manifests/ - Agent入口的导航文件和逻辑文件
site.pp
modules/ - Puppet的基础模块
ssl/ - Master在此目录存放CA证书和已签名授权的Agent证书文件列表,Agent在此目录存放被Master授权的证书文件

参考:http://www.justontheway.com/blog/archives/%E9%9B%86%E7%BE%A4%E8%87%AA%E5%8A%A8%E5%8C%96%E7%AE%A1%E7%90%86puppet%E4%BB%8B%E7%BB%8D/

2配置puppet.conf(master)

默认配置如下:

 [main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet # Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet # Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl [agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt # Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig

现在配置如下,以生产的实际情况来做

 [master]
# storeconfigs = true
# storeconfigs_backend = puppetdb
autosign = true
# ca = true
# ssldir = /var/lib/puppet/ssl
# certname = puppetmaster.com
strict_variables = false
#environmentpath = /etc/puppet/modules
basemodulepath = /etc/puppet/modules
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY
reports = http
reporturl = http://puppetmaster.com:3000/reports/upload #报告发送地址,可配置在dashboard或foreman配置文件中
[main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet #默认日志存放路径 # Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet #pid存放路径 # Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl #默认证书存放目录,默认$vardir为/var/lib/puppet
autosign = $confdir/autosign.conf #自动证书签名默认在/etc/puppet/autosign.conf pluginsync = false #插件同步配置对facter自定义有效这里为false没开启
masterport = 8140 #master监听端口
environment = production
certname = puppetmaster.com
server = puppetmaster.com #master端
listen = false
splay = false
splaylimit =
runinterval = 1800 ##客户端默认探测时间,可按需求修改
noop = false
configtimeout =
usecacheonfailure = true [agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt #关联与检索配置文件目录 # Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig ##本地缓存配置目录

创建sitt.pp文件,会告诉puppet去哪里寻找并且载入指定的客户端配置,我们来创建它现在先让它为空

 [root@master-elk manifests]# pwd
/etc/puppet/manifests
[root@master-elk manifests]# ls
[root@master-elk manifests]# touch site.pp
[root@master-elk manifests]# ls
site.pp
[root@master-elk manifests]#

设置防火墙

 iptables -I  INPUT -p tcp -m state --state NEW -m tcp --dport  -j ACCEPT

启动:


puppetmasterd -v -d --no-daemonize # 前台测试启动 这是2.x测试命令
puppet master -v -d --no-daemonize #3.x测试命令
 service puppetmaster start  #正式启动
或者
/etc/init.d/puppetmaster restart
服务验证:ss -antupl |grep 8140

master启动后会创建一个本地的master认证中心,同时创建master的相关证书和密钥,可以在 /etc/puppet/ssl/目录下查看相关的证书和密钥(看配置文件里面你定义在哪里)

 tree  /etc/puppet/ssl/
├── ca
│   ├── ca_crl.pem
│   ├── ca_crt.pem
│   ├── ca_key.pem
│   ├── inventory.txt
│   ├── private
│   │   └── ca.pass
│   ├── requests
│   ├── serial
│   └── signed
| ├──puppetmaster.com.pem
├── certificate_requests
├── certs
│   ├── ca.pem
│   └──puppetmaster.com.pem
├── crl.pem
├── private
├── private_keys
│   └──puppetmaster.com.pem
└── public_keys
└──puppetmaster.com.pem

agent端配置(一般配置)

 cat   /etc/puppet/puppet.conf

 [main]
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl [agent]
listen = true #监听进程
classfile = $vardir/classes.txt ##关联与检索配置文件目录
localconfig = $vardir/localconfig # #本地缓存配置目录 server = puppetmaster.com
report = true #发送报告
runinterval = 1800
#certname 不写默认是hostname

客户端连接到master端,在客户端上执行命令

  puppet agent --server=puppetmaster.com --no-daemonize --verbose   #测试启动
--no-daemonize: 让puppet客户端工作到前台并输出日志到标准输出
--verbose:是客户端输出详细信息日志
也可以加上--debug,让日志更加详细。
简洁方式:
puppet agent --test
正常启动 service puppet start

上面的意思是agent发起了一个证书验证请求,并且使用加密私钥来连接,puppet使用ssl证书来验证agent和master之间的连接,agent想master发出证书验证请求,等待master签名并且返回证书。现在agent依然运行并且等待已被签名的证书,在证书到达或者退出之前,agent会每个2分钟来是否存在被签名的证书。

服务端确认:

master执行:

 puppet cert --list --all #查看认证情况      前面出现+表示认证过了

在真实很多台的线上环境执行这条命令的时候会出现如下错误

 [root@puppetmater~]# puppet cert --list all
Error: header too long

是由于机器空间不足造成的可以df-h查看机器空间

参见这里但是需要翻墙(不能翻墙的点击下面的)

我贴出来具体过程:

 Puppet Error: header too long
If you're working with Puppet and you find that you get this error:
puppet cert --list
Error: header too long
Be mindful of your free space! I've now rolled out 20 servers or so in my puppet setup (soon to be duplicated to over 142 servers once I get these running right. All I'll have to do is spin up a new server, give it an IP and hostname and tell it where the Puppet Master is and Puppet will handle the rest!), and I've found that I'm starting to easily fill up the drive with old reports. Especially when re-running puppet syncs more frequently than the normal min run-interval. I started getting the above error with a lot of various puppet commands, the simplest one, just trying to list certs. Then I checked a "df -h":
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 16G 15G % /
Oops! Using the following script I was able to clean up old reports easily. Set the "days" variable to as high as you want for your setup. I'm using Puppet Dashboard to pull in reports to a DB, so I don't need to keep the yaml's around too long.
#!/bin/sh
days="+1" # more than a day old for d in `find /var/lib/puppet/reports -mindepth -maxdepth -type d`
do
find $d -type f -name \*.yaml -mtime $days |
sort -r |
tail -n + |
xargs /bin/rm -f
done
In my case, since it tried to sync a new server ssl cert while the drive was full, the error came out to be due to not only the free space, but a corrupt cert. To find the offending cert and fix the issue, you'll need to look through the /var/lib/puppet dir for the file. The host I was looking for is 'betamem.example.com' and I found it like this:
# cd /var/lib/puppet
# find ./|grep betamem
./ssl/ca/requests/betamem.example.com
I then removed the cert (held in /var/lib/puppet/ssl/certificate_requests/) from the agent on 'betamem' and told it to try again by cycling it's puppet agent.
# rm -f /var/lib/puppet/ssl/certificate_requests/*
# /etc/init.d/puppet restart
Stopping puppet agent: [ OK ]
Starting puppet agent: [ OK ]
Tailing /var/log/messages on the master shows it's got a new request, so let's sign it:
# tail /var/log/messages -n1
puppet-master[22486]: betamem.example.com has a waiting certificate request
# puppet cert --sign betamem.example.com
Signed certificate request for betamem.example.com
Removing file Puppet::SSL::CertificateRequest at '/var/lib/puppet/ssl/ca/requests/betamem.example.com.pem'
Go back to the puppet agent and cycle it again, or just wait until the next run-interval and it should be back to normal!

Puppet Error: header too long

手动注册认证

 puppet cert --sign agent1.puppetmaster.com #注册agent1

另外一种查看认证的方式

 tree /var/lib/puppet/ssl/ #另外一种查看认证的方式

 /etc/puppet/ssl/
├── ca
│ ├── ca_crl.pem
│ ├── ca_crt.pem
│ ├── ca_key.pem
│ ├── inventory.txt
│ ├── private
│ │ └── ca.pass
│ ├── requests
│ ├── serial
│ └── signed
│ ├──puppetmaster.com.pem
│ ├──agent1.puppetmaster.com.pem #注册认证
├── certificate_requests
├── certs
│ ├── ca.pem
│ └── puppetmaster.com.pem
├── crl.pem
├── private
├── private_keys
│ └── puppetmaster.com.pem
└── public_keys
└── puppetmaster.com.pem

另外也可以在服务算(master)来做认证

在master服务端执行

 puppet agent --test #puppetmaster自己申请agent认证
puppet cert --sign --all #注册所有请求的节点
puppet cert --list --all #查看所有节点认证

但是当我们有上百台机器的时候,这样来做显得十分麻烦,所以puppet提供了一种更好地办法

自动签名认证模式

master端服务端配置

1 如下:

 [root@master-elk ~]# cd /etc/puppet/
[root@master-elk puppet]# ls
auth.conf environments fileserver.conf manifests modules puppet.conf
[root@master-elk puppet]# touch autosign.conf
[root@master-elk puppet]# vim autosign.conf
[root@master-elk puppet]# cat autosign.conf
*.puppetmaster.com
[root@master-elk puppet]#

创建autosign.conf,然后在里面添加要自动签名的agent

我这里写的*.puppetmaster.com是去匹配agent端hostname以这个结尾的全部自动签名认证

# 注:master端的任何修改,都要重新装载puppetmaster服务,即执行如下命令即可

service puppetmaster reload

2.修改fileserver.conf

创建mkdir /etc/puppet/files

向该文件授予/etc/puppet/files目录的权限

# vi /etc/puppet/fileserver.conf
1 [files]
path /etc/puppet/files
allow * #或者写成allow *.puppetmaster.com [modules]
allow * [plugins]
allow *

该文件就是一个file服务器,我们在里面可以定义需要同步的文件,一般在同步的时候用source来制定路径,如下一个简单的例子

 此案例为C/S结构,把master上面的hosts文件同步到agent上面,如果发现同步文件不一致,需要对源文件进行备份后再进行覆盖,在master上编

 辑/etc/puppet/manifests/site.pp
node default {
file {'/etc/hosts' :
backup => '.bak',
source => "puppet:///files/hosts",
}
}
file {'/etc/hosts' :
backup => '.bak',
source => "puppet:///bin/python2.7.zip",
}
}
我们可以没有bin模块,只需要在fileserver.conf里面定义好配置文件就行了 其中puppet:///挂载的路径由master上的fileserver.conf文件指定,如下:
# cat fileserver.conf
[files]
path /etc/puppet/files
allow *
[bin]
path /opt/file/
allow *
把hosts文件放到/etc/puppet/files路径下,设置好之后我们在agent上面执行查看
把python2..zip文件放到/opt/file/路径下,设置好之后我们在agent上面执行查看

3puppet agent客户端配置

3.1允许master发起kick命令,puppet客户端默认每30分钟很服务器通讯一次,但是有时,我们希望服务器能够给客户端紧急推送一些东西,于是就有了puppet kick

配置文件/etc/puppet/auth.conf加入如下内容(有些版本是默认自带)这个必须有path /这个

/etc/puppet/auth.conf文件配置签名的ACL列表,配置准许哪些ip或者域名来签名通过

 path ~ ^/catalog/([^/]+)$
method find
allow $ path ~ ^/node/([^/]+)$
method find
allow $ path /certificate_revocation_list/ca
method find
allow * path /report
method save
allow * path /file
allow * path /certificate/ca
auth any
method find
allow * path /certificate/
auth any
method find
allow * path /certificate_request
auth any
method find, save
allow * path /run
method save
allow pup.qeeyou.com path /
auth any

3.2

在客户端编辑或创建新文件/etc/puppet/namespaceauth.conf,包含下面内容

[puppetrunner]
allow puppetmaster.com #填写master端ip绑定的那个域名

推送方法,在服务器端运行命令(后边会讲解,这里简单提一下)

  puppet kick -p   agent1.puppetmaster.com

当有问题的时候我们需要清空删除证书,然后重新来认证如下

二、清除原有证书

如果原客户端已经签过证书需要执行以下操作清空旧的证书,否则认证将失败

1.在服务端上执行以下命令其中“puppet2.hnr.com”为相关客户端主机

# puppet cert clean puppet2.hnr.com

2.在客户端上执行以下命令

# find /var/lib/puppet/ssl -name puppet2.hnr.com.pem -delete

认证的方法和上面一样,这里就不多说了

puppet的配置的更多相关文章

  1. puppet安装配置及使用

     puppet安装前准备 一.服务器信息 master端:10.10.10.201 master.fansik.com slave端:10.10.10.156 slave.fansik.com 三台机 ...

  2. puppet的配置清单书写

    puppet的配置清单书写 1使用数组,合并同类的 例如你想安装很多软件,如果分开来写的话,很麻烦,不简洁,这时我们可以使用数组来完成 以前我们这样来写 class packages{ package ...

  3. 手动编写的几个简单的puppet管理配置

    puppet在自动化配置管理方面有很强大的优势,这里就不做过多介绍了,下面记录下几个简单的puppet管理配置: 一.首先在服务端和客户端安装puppet和facter 1)服务端 安装Puppet ...

  4. centos6.5环境自动化运维之puppet实现nginx反向代理功能及puppet安装配置详解

    puppet是一种Linux.Unix.windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统实体称之为资 ...

  5. Puppet 安装配置

    环境说明: OS:CentOS 5.4 i386 puppetmaster    192.168.0.12    hostname: puppetmaster.info.com client      ...

  6. puppet运维配置实列

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABQkAAAGBCAIAAABKMKAEAAAgAElEQVR4nOydeXwU9cH/t2o9WutR+7

  7. puppet 3+Unicorn+Nginx安装配置

    puppet 3+Unicorn+Nginx安装配置 2014-08-15 10:58 酒瓶不倒 酒瓶不倒的博客 字号:T | T 一键收藏,随时查看,分享好友! Unicorn 效率要比 Webri ...

  8. puppet(一种Linux、Unix、windows平台的集中配置管理系统)

    puppet是一种Linux.Unix.windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统实体称之为资 ...

  9. puppet报告系统Dashboard部署及配置详解

    Puppet Dasshboard是由支持Puppet开发的公司Puppetlabs创建的,是Ruby on Rails程序.可以作为一个ENC(外部节点分类器)以及一个报告工具,并且正在逐渐成为一个 ...

随机推荐

  1. Javascript的DOM操作 - 你真的了解吗?

    摘要 想稍微系统的说说对于DOM的操作,把Javascript和jQuery常用操作DOM的内容归纳成思维导图方便阅读,同时加入性能上的一些问题. 前言 在前端开发的过程中,javascript极为重 ...

  2. Map集合 总结

    (本人第一次写博客,部分内容有参照李刚老师的疯狂java系列图书,如有遗漏错误,请多指教,谢谢.) Java的集合类可分为Set.List.Map.Queue,其中Set.List.Queue都有共同 ...

  3. C#:DataTable映射成Model

    这是数据库开发中经常遇到的问题,当然,这可以用现成的ORM框架来解决,但有些时候,如果DataSet/DataTable是第三方接口返回的,ORM就不方便了,还得自己处理. 反射自然必不可少的,另外考 ...

  4. 金山快盘+TortoiseSVN构建版本控制仓库

    金山会盘+TortoiseSVN构建版本控制仓库 之前写过一篇文章介绍 如何利用花生壳和VisualSVN Server建立远程代码仓库,具体请参照: <如何利用花生壳和VisualSVN Se ...

  5. oracle 分组排序函数

    项目开发中,我们有时会碰到需要分组排序来解决问题的情况:1.要求取出按field1分组后,并在每组中按照field2排序:2.亦或更加要求取出1中已经分组排序好的前多少行的数据 这里通过一张表的示例和 ...

  6. Windows下Memcache的安装及PHP扩展配置

    一.下载 找到完整的memcache的Windows安装包,解压放在硬盘上,比如 F:\memcached.exe 二.安装 WIN7 64位双击打开这个exe可能只有一个空的窗口,不能输入任何命令, ...

  7. ajax请求过程中下载文件在火狐下的兼容问题

    项目中碰到的问题,记录如下. 需求很简单,点击一个文件链接下载该文件,同时向后台发送请求.需求很常见,用户点击下载后通常要进行下载量的统计,统计的话可以利用 script标签 或者 img标签(图片p ...

  8. 用H5+Boostrap做简单的音乐播放器

    前言:这个是综合一下我最近在学的东西做的小Demo,到实际使用还有距离,但是用来练手巩固知识点还是不错的,最近在二刷JS书和Boostrap.css的源码,做完这个Demo也算是暂告一段落,接下来是j ...

  9. DOM之表格与表单基础分享

    我是沐晴,好久不见.马上要放假啦,也是比较的忙. 今天来谈谈表格和表单的基本知识.前期的写的都是比较基础的知识,后期会慢慢增加实例.一起来学习吧. 先看表格,DOM中提供了一些属性,便于我们获取表单节 ...

  10. 浅谈JS继承

    今天呢,我们来谈谈继承,它也是JS语言中的一大重点,一般什么时候我们会用继承呢,比如有两个拖拽的面板,两个功能基本一致,只是第二个面板多了一些不同的东西,这个时候,我们就会希望,要是第二个直接能继承第 ...