puppet计划之(安装篇)
准备工作
1、准备好2台测试服务器,都为Centos6.5 第一台为192.168.30.54主机名:master.kylinyunwei.com充当服务器端,第二台为192.168.30.55主机名为agent.kylinyunwei.com充当客户端。
2、因为配置需要解析,要搭建DNS服务器,使2台能够相互解析
DNS搭建
cd /var/named/chroot/etc
vi named.conf
options {
directory "/var/named";
};
zone "kylinyunwei.com" IN {
type master;
file "kylinyunwei.com.zone";
allow-transfer { 192.168.30.54; };
};
zone "30.168.192.in-addr.arpa" IN {
type master;
file "192.168.30.arpa";
allow-transfer { 192.168.30.54; };
};
配置区域文件
cd /var/named/chroot/var/named
vi kylinyunwei.com.zone
$TTL 86400
@ SOA kylinyunwei.com. admin.kylinyunwei.com. (
2014022001
3H ; refresh
15M ; retry
12H ; expiry
1D
) ; minimum
@ IN NS master.kylinyunwei.com.
IN A 192.168.30.54
master IN A 192.168.30.54
agent IN A 192.168.30.55
反向解析
vi 192.168.30.arpa
$TTL 86400
@ SOA kylinyunwei.com. admin.kylinyunwei.com. (
2014022001 ; serial (d. adams)
4H ; retry
30M
12H ; expiry
1D
) ; minimum
IN NS master.kylinyunwei.com.
54 IN PTR master.kylinyunwei.com.
55 IN PTR agent.kylinyunwei.com.
puppet安装
1、Master的安装
yum-y install ruby ruby-libs ruby-shadow
wgetftp://ftp.sunet.se/pub/Linux/distributions/yellowdog/yum/6.2/extras/RPMS/epel-release-5-3.noarch.rpm
rpm-Uvh epel-release-5-3.noarch.rpm
yum-y install puppet puppet-server facter
2、Agent的安装
yum install ruby ruby-libs ruby-shadow
wgetftp://ftp.sunet.se/pub/Linux/distributions/yellowdog/yum/6.2/extras/RPMS/epel-release-5-3.noarch.rpm
rpm-Uvh epel-release-5-3.noarch.rpm
yum-y install puppet facter
至此如果安装过程不报错的话,puppet已经安装成功了
三、Puppet的简单配置
1. Master的配置
先来看看puppet主目录下都有什么文件已经每个文件是做什么用的:
ls -1 /etc/puppet/
auth.conf #定义puppet master的acl文件
fileserver.conf #定义puppet master文件服务器的配置文件
manifests #puppet脚本主文件目录,site.pp文件必须存在
modules #puppet模块目录
puppet.conf #puppet主配置文件
ssl #存放ssl证书的目录
刚开始的话, puppet.conf不需要配置就可以满足。
需要更改hosts文件,注意hosts要和主机名对应。
vim /etc/hosts添加如下内容:
192.168.30.54 master.kylinyunwei.commaster
192.168.30.55 agent.kylinyunwei.comagent
2. Agent的配置
Agent的配置主要是更改agent上的/etc/puppet/puppet.conf文件的[agent]部分。
在agent上vim/etc/puppet/puppet.conf 添加如下配置
server = master.kylinyunwei.com #master服务器的地址
runinterval = 3600 #每隔多久的时间进行自动更新,时间单位为秒
listen = true #客户端作为一个服务进行监听,允许其它的机器触发puppet运行允许远程触发puppet的节点配置
四、puppet的启动和停止
1. Master的启动和停止
Master的启动
/etc/rc.d/init.d/puppetmaster start
也可以以采用 service puppetmaster start启动
第一次启动建议采用puppet master --verbose--no-daemonize方式启动,有助于测试和调试错误,如果采用后面这种方式,你可以看到启动的整个过程,启动过程会做一些初始化的工作,为master创建本地证书认证中心,证书和key。并打开socket等待client的连接。你可以在/etc/puppet/ssl目录看到相关的文件和目录。
Master的停止
/etc/rc.d/init.d/puppetmaster stop
也可以以采用 service puppetmaster stop停止
更改多选项可以使用/etc/rc.d/init.d/puppetmaster �Ch查看
2. Agent的启动和停止
Agent的启动
/etc/rc.d/init.d/puppet start
也可以采用service puppet start来启动
调试的时候可以采用
puppet agent --server=puppet.zhang.com--no-daemonize �Cverbose
的方式来启动,这样启动我们可以看到agent是如何和master建立连接的。
Agent的停止
/etc/rc.d/init.d/puppet stop
也可以采用service puppet stop来停止。
安装及启动过程中的报错
1、连接master的时候出现如下报错:
dnsdomainname: Unknown host
解决办法:检查机器主机名的设置,以及是否添加进hosts。本次测试就直接搭建DNS,顺便复习一下DNS的搭建
2、启动puppetmaster报错
[root@master puppet]# servicepuppetmaster restart
停止 puppetmaster: [失败]
启动 puppetmaster:/usr/lib/ruby/site_ruby/1.8/puppet/util/pidlock.rb:77:in`unlink': Permission denied - /var/lib/puppet/run/master.pid (Errno::EACCES)from/usr/lib/ruby/site_ruby/1.8/puppet/util/pidlock.rb:77:in `clear_if_stale'
from/usr/lib/ruby/site_ruby/1.8/puppet/util/pidlock.rb:11:in `locked?'
from/usr/lib/ruby/site_ruby/1.8/puppet/util/pidlock.rb:33:in `lock'
from /usr/lib/ruby/site_ruby/1.8/puppet/daemon.rb:46:in`create_pidfile'
from/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:44:in `synchronize_on'
from /usr/lib/ruby/1.8/sync.rb:230:in`synchronize'
from/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:44:in `synchronize_on'
from/usr/lib/ruby/site_ruby/1.8/puppet/daemon.rb:45:in `create_pidfile'
from/usr/lib/ruby/site_ruby/1.8/puppet/daemon.rb:21:in `daemonize'
from/usr/lib/ruby/site_ruby/1.8/puppet/application/master.rb:193:in `main'
from/usr/lib/ruby/site_ruby/1.8/puppet/application/master.rb:146:in `run_command'
from/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:309:in `run'
from/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:416:in `hook'
from/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:309:in `run'
from/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:407:in `exit_on_fail'
from/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:309:in `run'
from /usr/sbin/puppetmasterd:4
[确定]
解决办法:因为创建puppet用户,所以权限不对,更改权限即可
[root@master lib]# chown -R puppet.puppet /var/lib/puppet/,再次启动即可
3、在客户端进行测试,返回正常结果如下
[root@agent named]# clear
[root@agent named]# telnetmaster.kylinyunwei.com 8140
Trying 192.168.30.54...
Connected tomaster.kylinyunwei.com.
Escape character is '^]'.
4服务端收到请求,会有如下提示
[root@master lib]# puppetcert --list
"agent.kylinyunwei.com"(AA:EF:AC:D4:B6:27:5D:2D:D7:77:24:0B:33:FF:0D:45)