温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos 6.2 puppet 安装

发布时间:2020-07-22 02:40:42 来源:网络 阅读:713 作者:secboy 栏目:编程语言

Centos 6.2 puppet 安装


Puppet 要求所有机器有完整的域名(FQDN),如果没有 DNS 服务器提供域名的话,可以在两台机器上设置主机名(注意要先设置主机名再安装 Puppet,因为安装 Puppet 时会把主机名写入证书,客户端和服务端通信需要这个证书):


# vi /etc/hosts

192.168.2.10 master master.test.net

192.168.2.11 client client.test.net

Puppet 要求所有机器上的时钟保持同步,所以需要安装和启用 ntp 服务(如果采用 CentOS-6.2-x86_64-minimal.iso 最小化安装,需要额外安装这个软件包)。


# yum install ntp


# chkconfig ntpd on


# ntpdate pool.ntp.org

29 Feb 15:22:47 ntpdate[15867]: step time server 196.25.1.1 offset 98.750417 sec


# service ntpd start

Starting ntpd: [ OK ]

安装 puppet 服务


Puppet 需要 Ruby 的支持,如果要查看命令行帮助的话需要额外 ruby-rdoc 这个软件包:


# yum install ruby ruby-libs ruby-rdoc

Puppet 不在 CentOS 的基本源中,需要加入 PuppetLabs 提供的官方源:


# yum -y install wget


# wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm


# yum install puppetlabs-release-6-1.noarch.rpm


# yum update

在 master 上安装和启用 puppet 服务:


# yum install puppet-server


# chkconfig puppet on


# service puppetmaster start

Starting puppetmaster: [ OK ]

关闭 iptables:


# /etc/init.d/iptables stop

iptables: Flushing firewall rules: [ OK ]

iptables: Setting chains to policy ACCEPT: filter [ OK ]

iptables: Unloading modules: [ OK ]

安装 puppet 客户端


在 client 上安装 puppet 客户端:


# yum install puppet

Puppet 客户端使用 HTTPS 和服务端(master)通信,为了和服务器端通信必须有合法的 SSL 认证,第一次运行 puppet 客户端的时候会生成一个 SSL 证书并指定发给 Puppet 服务端。


# puppet agent --no-daemonize --onetime --verbose --debug --server=master.test.net

Puppet 服务端接受到客户端的证书后必须签字(sign)才能允许客户端接入,sign 后用 puppet cert list –all 查看会发现 client.test.net 前面多了一个 + 后,表示 “加入” 成功:


# puppet cert list --all

client.test.net (65:3C:20:82:AE:F6:23:A8:0A:0B:09:EF:05:64:1D:BB)

+ master.test.net (AF:A0:32:78:D4:EB:D3:EE:02:1C:62:1C:83:3C:46:EC) (alt names: DNS:master, DNS:master.test.net)


# puppet cert --sign client.test.net

notice: Signed certificate request for client.test.net

notice: Removing file Puppet::SSL::CertificateRequest client.test.net at '/var/lib/puppet/ssl/ca/requests/client.test.net.pem'


# puppet cert list --all

+ client.test.net (65:3C:20:82:AE:F6:23:A8:0A:0B:09:EF:05:64:1D:BB)

+ master.test.net (AF:A0:32:78:D4:EB:D3:EE:02:1C:62:1C:83:3C:46:EC) (alt names: DNS:master, DNS:master.test.net)

这样,客户端和服务端就配置好了,双方可以通信了。


Hello, world


现在可以在服务端写个小例子来测试一下。这个例子作用很简单,用来在客户端的 /tmp 目录下新建一个 helloworld.txt 文件,内容为 hello, world. 在服务端编写代码:


# vi /etc/puppet/manifests/site.pp

node default {

file {

"/tmp/helloworld.txt": content => "hello, world";

}

}

在客户端上执行 puppet,运行成功后会在 /tmp 看到新生成的 helloworld.txt:


$ puppet agent --test --server=master.test.net

warning: peer certificate won't be verified in this SSL session

info: Caching certificate for client.test.net

info: Caching certificate_revocation_list for ca

info: Caching catalog for client.test.net

info: Applying configuration version '1330668451'

notice: /Stage[main]//Node[default]/File[/tmp/helloworld.txt]/ensure: defined content as '{md5}e4d7f1b4ed2e42d15898f4b27b019da4'

info: Creating state file /home/vpsee/.puppet/var/state/state.yaml

notice: Finished catalog run in 0.03 seconds


$ cat /tmp/helloworld.txt

hello, world


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI