puppet 安装文档—Ubuntu

1)安装环境:

两台ubuntu 12.04 的实例
server(master):  ip:192.168.254.234  host:vm234.com
client:                 ip:192.168.254.235   host:vm235.com

2)安装前的准备:

  1. 请务必先给各自的主机的/etc/hosts 添加上hostname和ip,在服务节点,添加自己的hostname和所有client节点的host和ip;在client节点,只需添加server和自己的hostname和ip;这是因为在server的日志记录里都是以hostname来区别不同的节点。
  2. server是通过端口8140(由ruby占有)与client通信的,所以请确认设置防火墙,开放此端口。
  3. 为了各个节点能协同的运行服务,必须统一各个节点的时间,请给各个节点装ntp。以server节点的时间为标准。

3)安装:

在server节点安装 puppetmaster:
#sudo apt-get install puppetmaster
可通过脚本 /etc/init.d/puppetmaster 来控制状态(start,restart,stop,status)
在client节点安装 puppet:
#sudo apt-get install puppet 
注:如系统未安装运行puppet所需的ruby环境,上述两条指令会自动安装。

然后配置文件 /etc/puppet/puppet.conf。这是puppet的主要配置文件。
在server节点,打开/etc/puppet/puppet.conf后,在[master]下添加当前机器的certname

[master]
certname=vm234.com

保存后重启服务:
#service puppetmaster restart 

在client节点,打开/etc/puppet/puppet.conf后,添加:

[agent]
certname=vm235.com
server=vm234.com
report=true
#pluginsync=true

注:当有插件需要同步的时候,再取消pluginsync的注释。
保存退出后,再打开 /etc/default/puppet , 将START=on 改为 START=yes。将puppet设置为开机默认启动项。这是puppet在client端强制要求的。
然后重启puppet服务

#service puppet restart

4)服务连接:

首先在路径 /etc/puppet/manifests/ 下创建 site.pp

然后是client端向server发起认证的请求:

#puppet agent --server=vm234.com --no-daemonize --verbose

然后在server节点列出当前请求认证者的hostname

#puppet cert --list

结果是:

"vm235.com" (一长串密钥的指纹)

然后server接受特定client的请求:

#puppet cert --sign  vm235.com

或者是接受所有client的请求:

#puppet cert --sign --all 

notice: Signed certificate request for vm235.com
notice: Removing file Puppet::SSL::CertificateRequest vm235.com at '/var/lib/puppet/ssl/ca/requests/vm235.com.pem'

认证后,client的公钥放在文件夹 /var/lib/puppet/ssl/ca/signed/

然后在client端显示:

info: Caching certificate for vm235.com
notice: Starting Puppet client version 2.7.11

至此认证请求完毕,可暂停client的agent ,即按 ctrl + c;也可等它自行结束,就是时间可能会久点。但是一定要出现 notice: Starting Puppet client version 2.7.11 的信息确认认证成功后才可暂停。

可用下面小段代码测试是puppet是否配置成功:

在 /etc/puppet/manifests/site.pp 输入

node 'vm235.com'{
      file{
            "/root/helloWorld":
             content=>"hello world\n" ,
             mode => 0644;
      }
}
保存后。在client端输入
#puppet agent --test

将在后台运行的 agent 放到终端显示,显示的信息如下:

info: Caching catalog for vm235.com
info: Applying configuration version '1374052357'
notice: /Stage[main]//Node[vm235.com]/File[/root/helloWorld]/ensure: defined content as '{md5}6f5902ac237024bdd0c176cb93063dc4'
notice: Finished catalog run in 0.03 seconds

这时,在如在client生成文件 /root/helloWorld,文件的内容是hello world,则证明puppet已经能正常工作了。

5)常用小技巧:

在server节点的路径 /var/lib/puppet/ssl/ca/signed 可查看server目前已经接受的client的公钥

6)常见bug:

 命令 service puppet status 可查看当前服务的状态,如果遇到错误:could not access PID file for agent 。这是因为服务发生异常而关闭了,

请重启服务 service puppet restart。

输入指令puppet agent --server=vm234.com --no-daemonize --verbose,遇到错误 Could not run: Could not create PID file: /var/run/puppet/agent.pid。这是因为已有puppet agent 启动了,请删除之前的进程(可用 pgrep和pkill),再重新启动服务puppet agent --server=……

更详细的信息请参阅puppet的官方文档 http://docs.puppetlabs.com/ 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 Ubuntu安装 Puppet 的步骤: 1. 打开终端并更新软件包列表: ``` sudo apt update ``` 2. 安装 Puppet: ``` sudo apt install puppet ``` 3. 验证 Puppet 是否安装成功: ``` puppet --version ``` 如果 Puppet 安装成功,将会输出 Puppet 的版本号。 4. 编辑 Puppet 的配置文件 /etc/puppet/puppet.conf,配置 Puppet 的 agent: ``` [main] server = puppet.example.com [agent] certname = ubuntu.example.com ``` 其中,server 指定 Puppet master 的地址,certname 指定 Puppet agent 的名称。 5. 启动 Puppet agent: ``` sudo systemctl start puppet ``` 6. 验证 Puppet agent 是否启动成功: ``` sudo systemctl status puppet ``` 如果 Puppet agent 启动成功,将会输出类似以下内容: ``` ● puppet.service - Puppet agent Loaded: loaded (/lib/systemd/system/puppet.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-08-23 14:12:39 UTC; 1min 23s ago Main PID: 1234 (puppet) Tasks: 2 (limit: 1137) CGroup: /system.slice/puppet.service └─1234 /usr/bin/ruby /usr/bin/puppet agent --no-daemonize Aug 23 14:12:39 ubuntu.example.com puppet-agent[1234]: Starting Puppet client version 6.24.0 Aug 23 14:12:41 ubuntu.example.com puppet-agent[1234]: Using cached certificate for ca Aug 23 14:12:42 ubuntu.example.com puppet-agent[1234]: Caching certificate for ubuntu.example.com Aug 23 14:12:42 ubuntu.example.com puppet-agent[1234]: Using cached certificate for ubuntu.example.com Aug 23 14:12:42 ubuntu.example.com puppet-agent[1234]: Retrieving pluginfacts Aug 23 14:12:42 ubuntu.example.com puppet-agent[1234]: Retrieving plugin Aug 23 14:12:42 ubuntu.example.com puppet-agent[1234]: Retrieving locales Aug 23 14:12:43 ubuntu.example.com puppet-agent[1234]: Retrieving facts Aug 23 14:12:44 ubuntu.example.com puppet-agent[1234]: Retrieving catalog Aug 23 14:12:45 ubuntu.example.com puppet-agent[1234]: Caching catalog for ubuntu.example.com ``` 现在,你已经成功在 Ubuntu安装Puppet

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值