-
1、安装
参考:
server: vm centos6 192.168.1.111
client: vm centos6 192.168.1.100
时间同步,在各台机器执行
ntpdate time.nist.gov
Puppet是基于Ruby写成的,所以安装前要准备好Ruby环境。
在中心Server上安装puppet-server包,并运行 puppetmasterd进程;
在被管理机上安装puppet包,并运行puppetd进程;
在每台主机上配置好自己的hostname,之后每台机器要以hostname区分。
-
Server端:
安装ruby环境:
yum -y install ruby ruby-rdoc
先安装epel-release包,到下面的网站找最新的
http://yum.puppetlabs.com/el/6/products/i386/
再安装puppet-server,会自动安装依赖
yum -y install puppet-server
设置puppet服务自动启动
chkconfig --level 2345 puppetmaster on
修改hosts,添加下面行:
vi /etc/hosts
192.168.1.111 pptser.chuanliu.com pptser
192.168.1.100 server1.chuanliu.com server1
确认
hostname
vi /etc/sysconfig/network
puppetserver.chuanliu.com
增加端口识别:
vi /etc/sysconfig/iptables
添加8140 端口
客户端安装:
yum -y install puppet
chkconfig --level 2345 puppet on
修改hosts,添加下面行:
Vi /etc/hosts
192.168.1.111 pptser.chuanliu.com pptser
192.168.1.100 server1.chuanliu.com server1
192.168.1.100 server1.chuanliu.com server1
启动puppet
Server端首次运行前,编辑/etc/puppet/manifests/site.pp文件,内容可以用最基本的:
# Create “/tmp/testfile” if it doesn’t exist.
class test_class {
file { “/tmp/testfile”:
ensure => present,
mode => 644,
owner => root,
group => root
}
}
# tell puppet on which client to run the class
node web1.sina.com.cn {
include test_class
}
启动Server端:
service puppetmaster start
启动客户端:
第一次请求连接
puppetd --server pptser.chuanliu.com --test
这时客户机会去连server,但是由于连接是在ssl上的,而Server还没有sign过客户端的cert,客户机被断开。
到Server端执行:
puppetca --list
会显示等待签名的客户端的主机名,执行:
puppetca --sign server1.chuanliu.com
在Server端为server1.chuanliu.com授权,这时再到客户机上运行
puppetd --server pptser.chuanliu.com --test
即可看到客户在正常地连接server,并且应用Server上为客户端定制的配置策略
测试:
也可以将日志直接打印到终端上进行测试:
Server端:puppetmasterd -d –no-daemonize -v –trace
客户端:puppetd –test –trace –debug
2. puppet配置文件
主配置文件(puppet.conf):
1). 配置文件命名空间:
main 通用配置选项
puppetd 客户端配置选项
puppetmasterd 服务端配置选项
2). main命名空间选项:
confdir 配置文件目录,默认在/etc/puppet
vardir 动态数据目录,默认在/var/lib/puppet
logdir 日志目录,默认在/var/log/log
rundir puppet PID目录,默认在/var/run/puppet
statedir state目录,默认在$vardir/state
statefile state文件,默认在$statedir/state.yaml
ssldir SSL证书目录,默认在$vardir/ssl
trace 发生错误时显示跟踪信息,默认false
filetimeout 检测配置文件状态改变的时间周期,单位秒,默认15秒
syslogfacility 指定syslog功能为user级,默认为daemon级
3). puppetmasterd命名空间选项:
user 后台进程执行的用户
group 后台进程执行的组
mainfestdir mainfests文件存储目录,默认为$confdir/mainfests
mainfest mainfest站点文件的名字,默认为site.pp
bindaddress 后台进程绑定的网卡地址接口
masterport 后台进程执行的端口,默认为8140
4). puppet命名空间选项:
server puppet puppet服务器名,默认为puppet
runinterval seconds puppet应用配置的时间间隔,默认1800秒(0.5小时)
puppetdlockfie file puppet lock文件位置,默认$statedir/puppetdlock
puppetport port 后台进程执行的端口,默认8139
文件服务配置文件(fileserver.conf):
[files]
path /var/lib/puppet/files
allow 121.14.1.*
allow 60.28.228.0/24
allow *.house.sina.com.cn
deny *.sina.com.cn
path定义文件存放路径,通过allow/deny来控制访问权限。
3. puppet命令集
1). puppet 用于执行用户所写独立的mainfests文件
# puppet -l /tmp/manifest.log manifest.pp
2). puppetd 运行在被管理主机上的客户端程序
# puppetd –server puppet.leju.com
3). puppetmasterd 运行在管理机上的服务器程序
# puppetmasterd
4). puppetca puppet认证程序
# puppetca -l
pclient.leju.com
# puppetca -s pclient.leju.com
5). puppetrun 用于连接客户端,强制运行本地配置文件
# puppetrun -p 10 –host host1 –host host2 -t remotefile -t webserver
6). filebucket 客户端用于发送文件到puppet file bucket的工具
# filebucket -b /tmp/filebucket /my/file
7). ralsh 转换配置信息到puppet配置代码
# ralsh user luke
user { ‘luke’:
home => ‘/home/luke’,
uid => ‘100′,
ensure => ‘present’,
comment => ‘Luke Kanies,,,’,
gid => ‘1000′,
shell => ‘/bin/bash’,
groups => ['sysadmin','audio','video','puppet']
}
8). puppetdoc 打印puppet参考文档
# puppetdoc -r type > /tmp/type_reference.rst
# puppetdoc –outputdir /tmp/rdoc –mode rdoc /path/to/manifests
# puppetdoc /etc/puppet/manifests/site.pp
都说修改hostname是即时生效的我看未必啊,修改了好几次都没有成功
还是得重启机器
转载于:https://blog.51cto.com/jingxing05/775506