初学puppet

初学puppet

  • puppet是什么?

puppet是一个开源的软件自动化配置和部署工具,不少大型IT公司均在使用puppet对集群中的软件进行管理和部署。html

  • Puppet简介

Puppet的目录是让管理员只集中于要管理的目标,而忽略实现的细节。Puppet便可以运行在单机上,也能够以C/S结构使用。在大规模使用puppet的状况下,一般使用C/S结构,在这种结构中puppet客户端只运行puppeclient,puppet服务端只运行puppemaster。node

 

  • Puppet的工做原理

1)  客户端puppet调用fast探测出主机的一些变量,如主机名、内存大小、IP地址等。Puppet把这些信息使用SSL链接发送给服务器端linux

2) 服务器端的puppetmaster经过fast工具分析检测客户端的主机名,而后找到项目的主配置文件manifest里面对应的node配置,并对该部份内容进行解析,fast发送过来的信息能够做为变量处理,node牵扯到的代码才被解析,没牵扯到的不解析,解析分为语法检查,若是语法没错,继续解析,解析结果生成一个结果‘伪代码’,而后把‘伪代码’发给客户端vim

3) 客户端收到‘伪代码’而且执行,客户端把执行结果发给服务器安全

4) 服务器端把客户端的执行结果写入日志服务器

 

  • Puppet工做过程当中的注意事项

1)  为了保证安全,Client和Master之间是基于SSL和证书的,只有经Master证书认证的Client能够与Master通讯dom

2)  Puppet会让系统保持在人们所指望的某种状态并一直维持下去,如检测某个文件并保证其一直存在,保证SSH服务始终开启,若是文件被删除了或者ssh服务关闭了,puppet下次执行时(默认30分钟)会从新建立该文件或者启动SSH服务ssh

 

  • Puppet服务端与客户端的安装

OS:Centos 6.5 x86_64工具

Puppet master:master.xiaohao.com(*.*.*.*)性能

Puppet agent:agent.xiaohao.com(*.*.*.*)

 

Puppet 要求全部机器有完整的域名,若是没有 DNS 服务器提供域名的话,能够在机器上设置主机名(注意:要先安装 Puppet以前设置主机名,由于安装 Puppet 时会把主机名写入证书,客户端和服务端通讯须要这个证书),为了简化安装过程我配置了/etc/hosts。

 

[root@master ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

*.*.*.*  master.xiaohao.com

*.*.*.*  agent.xiaohao.com

 

修改设备主机名:

[root@master yum.repos.d]# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=master.xiaohao.com

 

关闭selinux内核防火墙:

#sed '/^SELINUX/s/=.*/=disabled/g' /etc/sysconfig/selinux -i

 

关闭iptables防火墙:

#iptables –F

#service iptables stop

#chkconfig iptables off

 

系统默认yum不使用,配置阿里的镜像yum源(百度搜索下“阿里镜像”)

 

本地系统是CentOS6.5,因此使用CentOS6的镜像yum源。

 

 

puppet server和两台应用服务器共三台机器依次执行下面的指令:

http://mirrors.aliyun.com/repo/Centos-6.repowget -O /etc/yum.repos.d/CentOS-Base.repo
 

修改yum源文件的release版本:
 #cd  /etc/yum.repos.d/
 #vim CentOS-Base.repo

注意:修改$releasever(版本)为6,共修改了20处,可使用yum安装软件包了。

Puppet软件包安装:
Puppet server和agent客户端安装epel-release源
 #rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm
Puppet server端安装puppet-server:
#yum –y install puppet-server puppet
Puppet agent客户端安装puppet:
#yum -y install puppet
 
查看三台机器安装的puppet版本:
#puppet –V
3.8.7 
疑问?--若是puppet server 是3.8,那么puppet agent是 2.6能正常运行吗? 
注释:
第一点:最多见的Puppet部署模型是客户端-服务端模型。许多人询问是否能使用不一样的Puppet版本做为master和agent。答案是能够,但前提是要遵守一些注意事项。第一点要注意的是master的版本必定要高于agent。例如,你能够将一个0.24.8版本的agent链接到一个2.6.0版本的master,可是反过来不行。
第二点:要注意的是,agent的版本越老,在与新版本的master搭配时正确运行的可能性就越小。一个0.20.0版本的agent搭配一个2.6.0的master基本不可能正确工做。一般,0.24.x版的agent都能正常链接到2.6.x和0.25.x版本的master而且工做正常。更新版本的master就可能没法彻底兼容早期的agent,一些功能和特性可能会出现异常。
最后,将2.6.x或更新版本的master与0.24.x及早期版本的agent混合使用意味着你没法得到2.6.x版本提供的所有性能提高。0.24.x版的agent依然会使用较慢的XML-RPC传输层来进行通信,从而没法利用新的REST接口。

设置ntp时间同步:
由于公司已经有ntp服务器,直接使用了,未从新搭建ntp
# service ntpd start
 
修改服务端puppet.conf主配置文件

[root@puppet-master ~]# vim /etc/puppet/puppet.conf

[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

[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

certname = master.xiaohao.com    

server  = master.xiaohao.com       ###设置agent认证链接master端的服务器名称,此名称必须得可以解析

[master]

certname = master.xiaohao.com     ###设置puppetmaster认证服务器名称

 
 
 
启动puppetmaster服务
# /etc/init.d/puppetmaster start
Starting puppetmaster:                               [OK]
# chkconfig puppetmaster on    ###设置开机启动 
# chkconfig --list|grep puppetmaster
puppetmaster    0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
  
修改客户端配置文件
[root@agent ~]# cat /etc/puppet/puppet.conf
[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
server = master.xiaohao.com
listen = true
 
启动puppet服务:
#service puppet start
#chkconfig puppet on 
 
  • Puppet证书申请

Puppet客户端与服务器端是经过SSL隧道通讯的,客户端安装完成后,须要向服务器端申请证书: 
首次链接服务器端会发起证书申请,在客户端执行命令以下:
puppet agent --server master.xiaohao.com -test

在服务器端能够用puppet cert -list命令查看到申请证书的客户端主机名。  
puppet cert  -s命令能够为特定的主机颁发证书,puppet cert –s and –a 表示给全部的主机颁发证书  
例如puppet cert –s agent.xiaohoa.com 为客户端颁发证书。  
# puppet cert --list -all    ###带“+”代表注册成功
+ "agent"              (SHA256) A7:19:D1:25:6E:64:AA:84:53:AF:F0:8B:63:C9:2D:B1:47:49:11:6E:C9:3A:5A:EF:00:72:F4:7B:6E:E7:24:65
 
  • 验证puppet配置  

在服务端写个例子测试一下。这个例子做用很简单,用来在客户端的/tmp目录下新建一个 test.txt 文件,内容为:hello,test!在服务端编写代码:【服务器端不须要新建这个文件】  
#vi /etc/puppet/manifests/site.pp  
node default {  
file {  
"/tmp/test.txt": content => "helo,test!";  
  }  
}
 
  • puppet客户端测试

在客户端执行 puppet,运行成功后会在 /tmp 看到新生成的 test.txt:  
#puppet agent -t 
执行命令后显示以下:
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent.xiaohao.com
Info: Applying configuration version '1534319026'
Notice: /Stage[main]/Main/Node[default]/File[/tmp/test.txt]/ensure: defined content as '{md5}bf2fcd5a98ca557c37106f400c2954be'
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 0.01 seconds
最后查看执行结果:
#cat /tmp/test.txt
Hello,test!
 
此致puppet服务器端和客户端安装完毕,接下来就是深刻的配置了。
 
附puppet自动签发证书步骤:
https://www.cnblogs.com/kaishirenshi/p/7767811.html
相关文章
相关标签/搜索