温馨提示×

温馨提示×

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

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

puppet的安装和配置步骤

发布时间:2021-07-30 17:18:26 来源:亿速云 阅读:186 作者:chen 栏目:编程语言

这篇文章主要介绍“puppet的安装和配置步骤”,在日常操作中,相信很多人在puppet的安装和配置步骤问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”puppet的安装和配置步骤”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

  Puuppet是一个开源的新一代的集中化配置管理工具,它由自己所声明的语言表达系统配置,通过客户端与服务端直接的连接,维护着关系库。

  Puppet是一个跨平台的集中化配置管理系统,它使用自由的描述语言,可管理配置文件、用户、Cron、软件包,系统服务等,Puppet把这些统称为“资源”。

  Puppet是基于Ruby语言并使用Apache协议授权的开源软件,它既能以客户端-服务端(C/S)的方式运行,也能独立运行。客户端默认每30分钟会与服务端确认一次更新,以确保配置的一致性。

 Puppet的安装步骤

1)安装Ruby、Ruby-libs和Ruby-shadow,用于进行用户和组管理。

2)安装Facter、Puppet和Puppet-server。

3)设置主机名、域名解析或指定hosts。

4)通过命令/etc/init.d/puppetmaster start启动Server或者以非进程的方式启动Server。通过命令puppet master --no-daemonize --verbose可以查看到相关日志与输出。

5)在客户端配置文件Puppet.conf中指定Server端,在终端运行Puppet agent-test命令或直接运行puppet agent --test --server server.domain.com 与Master交互完成签名认证。

6)在Server上配置节点信息,告诉客户端要做什么。

7)检查语法是否正确(通长采用puppet parser validate test.pp命令进行语法检查)。

8)客户端再次运行配置(puppet agent --test)

 一、 本文以Centos6.4操作系统下,安装和配置Puppet。

(1)根据操作系统版本配置Yum源

rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm 3

 (2)在服务器端安装Puppet。运行如下代码会自动匹配安装Facter等相关依赖包

yum -y install puppet-server

运行如下命令来检查Puppet的安装

[root@node1 ~]# puppet -V
3.7.3
[root@node1 ~]# facter -v
2.3.0

(3)在客户端安装Puppet。

yum -y install puppet

二、配置Puppet

1)服务的启用方法如下:

主:[root@node1 ~]# /etc/init.d/puppetmaster 
Usage: /etc/init.d/puppetmaster {start|stop|status|restart|reload|force-reload|condrestart|genconfig}
客:[root@node2 ~]# /etc/rc.d/init.d/puppet 
Usage: /etc/rc.d/init.d/puppet {start|stop|status|restart|reload|force-reload|condrestart|once|genconfig}

2)设定主机名指定hosts

[root@node1 ~]# cat /etc/hosts
192.168.254.2             node1.jiabin.com
192.168.254.5             node2.jiabin.com

[root@node2 ~]# cat /etc/hosts
192.168.254.2             node1.jiabin.com
192.168.254.5             node2.jiabin.com

3)配置防火墙。

Puppet会监听8140端口,因此我们需要开放8140端口

 iptables -A INPUT -p tcp --dport 8140 -j ACCEPT

4)配置一个文件进行测试

[root@node1 ~]# cat /etc/puppet/manifests/site.pp 

node default {
        file {
                "/tmp/helloworld.txt": content => "hello, world";
        }
}

5)客户端发起验证,命令如下

root@node2 ~]# puppet agent --server node1.jiabin.com --test
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for node2.jiabin.com
Info: Certificate Request fingerprint (SHA256): 9D:26:8A:44:54:D4:B0:2A:73:0B:B6:BE:72:C3:E4:19:3C:13:CA:3F:C7:B8:03:99:69:70:06:9A:C1:DF:AD:69
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled

Agent发起了一个证书验证请求并且使用一个私钥来加密连接。Puppet使用SSL证书来验证Master和Agent之间的连接。Agent会持续每两分钟检查一次是否存在被签名的证书。

6)服务器完成验证。

[root@node1 ~]# puppet cert --list
  "node2.jiabin.com" (SHA256) 9D:26:8A:44:54:D4:B0:2A:73:0B:B6:BE:72:C3:E4:19:3C:13:CA:3F:C7:B8:03:99:69:70:06:9A:C1:DF:AD:69
[root@node1 ~]# puppet cert sign node2.jiabin.com
Notice: Signed certificate request for node2.jiabin.com
Notice: Removing file Puppet::SSL::CertificateRequest node2.jiabin.com at '/var/lib/puppet/ssl/ca/requests/node2.jiabin.com.pem'

7)客户端再次运行配置。

[root@node2 ~]# puppet agent --server node1.jiabin.com --test
Info: Caching certificate for node2.jiabin.com
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for node2.jiabin.com
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node2.jiabin.com
Info: Applying configuration version '1419922755'
Notice: Finished catalog run in 0.31 seconds

8)验证配置

[root@node2 ~]# more /tmp/node2.txt 
Hello World!

如果遇到签名故障,最直接的一种方法。删除主客ssl整个目录

rm -rf /var/lib/puppet/ssl

三、配置一个测试节点

1)创建test模块。模块目录为test,class类名也必须是test。test类里有一个File资源,File资源的目的是在/tmp目录中创建一个以Node2主机名的txt文件,其内容为"Hello World!"

主节点:

[root@node1 ~]# mkdir -p /etc/puppet/modules/test/{manifests,templates,files}
[root@node1 ~]# vim /etc/puppet/modules/test/manifests/init.pp 

class test {
    file { "/tmp/$hostname.txt": content => "Hello World!";}
}

2)在模块配置文件中定义一个变量“$hostname",需要将变量传递给ERB模块文件中,

[root@node1 ~]# vim /etc/puppet/modules/test/templates/test.erb 

hostname <%= fqdn %>

3)创建测试节点

[root@node1 ~]# vim /etc/puppet/manifests/nodes/node2.jiabin.com.pp 

node 'node2.jiabin.com' {
include test
include httpd
}

4)载入测试节点到Puppet

[root@node1 ~]# vim /etc/puppet/manifests/site.pp 

import "nodes/node2.jiabin.com.pp"

node default {
        file {
                "/tmp/helloworld.txt": content => "hello, world";
        }
}
~

import指令告诉Puppet载入nodes目录中所有以.pp结尾的文件。

四、检测配置文件

检测语法分两部分,第一步是在Puppet Master服务端采用puppet parser validate命令,

第二步是在Puppet Agent客户端采用--noop参数检测语法及代码。

[root@node1 ~]# puppet parser validate /etc/puppet/modules/test/manifests/init.pp

linux中没显示就是最好的结果

客户端检测

[root@node2 ~]# puppet agent --test --server node1.jiabin.com --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node2.jiabin.com
Info: Applying configuration version '1419922755'
Notice: Finished catalog run in 0.33 seconds

增加httpd模块

1)创建httpd模块相应的目录

[root@node1 ~]# mkdir -p /etc/puppet/modules/httpd/{manifests,templates,files}

2)编辑httpd模块文件,指定资源配置

[root@node1 ~]# vim /etc/puppet/modules/httpd/manifests/init.pp 

class httpd {
yumrepo  { "repo163":
 descr   => "163 repo",
 baseurl => "http://mirrors.163.com/centos/6/os/x86_64/",
 gpgcheck => "0",
 enabled => "1";
 }

package {
        "httpd":
        ensure => installed,
        require => Yumrepo["repo163"];
        }
}

3)修改node2.jiabin.com.pp,增加httpd模块

[root@node1 ~]# vim /etc/puppet/manifests/nodes/node2.jiabin.com.pp 
node 'node2.jiabin.com' {
include test
include httpd
}

4)检查配置文件语法的正确性

[root@node1 ~]# puppet parser validate /etc/puppet/modules/test/manifests/init.pp

linux中没显示就是最好的结果

5)在客户端运行配置,命令如下:

[root@node2 ~]# puppet agent --server node1.jiabin.com --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node2.jiabin.com
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please exp
   (at /usr/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Info: Applying configuration version '1419926864'
Notice: Finished catalog run in 0.85 seconds

出现一个警告,不影响程序运行。可以在服务器端的 pp文件中的package 中加入 :allow_virtual => false,  来解决出现的警告。

[root@node1 ~]# vim /etc/puppet/modules/httpd/manifests/init.pp 

class httpd {
yumrepo  { "repo163":
 descr   => "163 repo",
 baseurl => "http://mirrors.163.com/centos/6/os/x86_64/",
 gpgcheck => "0",
 enabled => "1";
 }

package {
        "httpd":
        ensure => installed,
        require => Yumrepo["repo163"],
        allow_virtual => false;
        }
}

6)检查httpd是否已经成功安装

[root@node2 ~]# rpm -q httpd
httpd-2.2.15-26.el6.centos.x86_64

到此,关于“puppet的安装和配置步骤”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

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

AI