|
环境:
服务器端:192.168.2.60 master.king.com
客户端:192.168.2.147 slave.king.com
1、服务器端设置用户名及DNS:
[root@master manifests]# more /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=master.king.com
NETWORKING_IPV6=no
PEERNAT=no
GATEWAY=192.168.2.1
[root@master manifests]# more /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.60 master.king.com
192.168.2.147 slave.king.com
[root@master manifests]# more /etc/resolv.conf
search localdomain CNC
nameserver 8.8.8.8
2、安装puppet-server及puppet:
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# yum -y install puppet-server
# yum -y install puppet
chkconfig puppet on
chkconfig puppetmaster on
service puppetmaster start
service puppet start
lokkit -p 8140:tcp
# puppet cert list --all
3、客户端设置用户名及DNS:
[root@slave tmp]# more /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=slave.king.com
[root@slave tmp]# more /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.60 master.king.com
192.168.2.147 slave.king.com
[root@slave tmp]# more /etc/resolv.conf
# Generated by NetworkManager
search king.com
nameserver 219.141.140.10
nameserver 219.141.136.10
nameserver 8.8.8.8
4、客户端安装puppet
yum install puppet
chkconfig puppet on
service puppet start
编辑 /etc/puppet/puppet.conf, 添加一行,指定master服务器名称。
server=master.king.com
5、证书颁发:
# puppetd --server master.king.com --test
服务器端查看# puppetca -l
服务器端分发# puppetca -s slave.king.com
6、功能测试:
[root@master manifests]# more site.pp
node default {
file {"/tmp/Puppet_test.txt":
content=>"This is test of PUPPET";}
}
#service puppetmaster restart
[root@master manifests]# puppet /etc/puppet/manifests/site.pp
warning: Implicit invocation of 'puppet apply' by passing files (or flags) directly
to 'puppet' is deprecated, and will be removed in the 2.8 series. Please
invoke 'puppet apply' directly in the future.
notice: Finished catalog run in 0.02 seconds
客户端执行:
[root@slave tmp]# puppetd --test --server master.king.com
info: Caching catalog for slave.king.com
info: Applying configuration version '1417576906'
notice: /Stage[main]//Node[default]/File[/tmp/Puppet_test.txt]/ensure: defined content as '{md5}
0d31f0cb46dc51da999298473d3d26a3'
notice: Finished catalog run in 0.03 seconds
[root@slave tmp]# more Puppet_test.txt
This is test of PUPPET
7、文件分发功能:
服务器端:
[root@master manifests]# more /etc/puppet/fileserver.conf
[tmp]
path /tmp
allow *.king.com
[root@master manifests]# more site.pp
node default {
file {"/tmp/Puppet_test.txt":
content=>"This is test of PUPPET";}
}
file {
”/tmp/hello.sh”:
source => “puppet://master.king.com/tmp/hello.sh”,
owner => root,
group => root,
mode => 755
}
[root@master manifests]# more /tmp/hello.sh
#!/bin/bash
touch /root/bb
客户端:
[root@slave tmp]# ps -ef |grep puppet
root 2513 1 0 10:17 ? 00:00:03 /usr/bin/ruby /usr/sbin/puppetd
root 3424 2446 0 10:47 pts/0 00:00:00 /usr/bin/ruby /usr/bin/puppet --server master.king.com
root 7885 2446 0 11:50 pts/0 00:00:00 grep puppet
[root@slave tmp]# kill 2513
[root@slave tmp]# puppetd --server master.king.com --test
8、文件执行功能:
服务器端:
[root@master manifests]# more site.pp
node default {
file {"/tmp/Puppet_test.txt":
content=>"This is test of PUPPET";}
}
file { "/tmp/hello.sh":
owner => root,
group => root,
source => "puppet://master.king.com/tmp/hello.sh",
mode => 755,
}
exec {
"/tmp/hello.sh":
cwd => "/tmp",
timeout => 7200,
user => root,
path => ["/sbin","/usr/sbin","/usr/local/sbin","/usr/local/bin","/usr/bin","/bin
"],
}
客户端:
[root@slave tmp]# puppetd --server master.king.com --test
info: Caching catalog for slave.king.com
info: Applying configuration version '1417583652'
notice: /Stage[main]//Exec[/tmp/hello.sh]/returns: executed successfully
notice: Finished catalog run in 0.59 seconds
[root@slave tmp]# ls
hello.sh Puppet_test.txt
[root@slave tmp]# more hello.sh
#!/bin/bash
touch /root/bb
[root@slave tmp]# more /root/bb
9、自动同步功能:
客户端:
[root@slave tmp]# vi /etc/puppet/puppet.conf
server=master.king.com
listen=true
runinterval=900
[root@slave tmp]# puppetd
[root@slave tmp]# ps -ef | grep puppet
root 3424 2446 0 10:47 pts/0 00:00:00 /usr/bin/ruby /usr/bin/puppet --server master.king.com
root 10270 1 15 13:17 ? 00:00:01 /usr/bin/ruby /usr/sbin/puppetd
root 10436 2446 0 13:17 pts/0 00:00:00 grep puppet
[root@slave tmp]# tail -f /var/log/messages
Dec 3 13:17:39 slave puppet-agent[10270]: Reopening log files
Dec 3 13:17:41 slave puppet-agent[10270]: Starting Puppet client version 2.7.25
Dec 3 13:17:43 slave puppet-agent[10270]: (/Stage[main]//Exec[/tmp/hello.sh]/returns) executed successfully
10、强制同步功能:(服务器端发起)
编辑服务器端和客户端文件/etc/puppet/namespaceauth.conf
[root@master manifests]# more /etc/puppet/namespaceauth.conf
[fileserver]
allow *.king.com
[puppetmaster]
allow *.king.com
[pelementserver]
allow *.king.com
[puppetrunner]
allow *.king.com
[puppetbucket]
allow *.king.com
[puppetreports]
allow *.king.com
客户端:
编辑客户端文件/etc/puppet/auth.conf,将path /run 一段添加到path / 之前
#more /etc/puppet/auth.conf
path /run
method save
allow *
# this one is not stricly necessary, but it has the merit
# to show the default policy which is deny everything else
path /
auth any
重启:
[root@master manifests]# service puppetmaster restart
[root@master manifests]# service puppet restart
服务器端强制某台客户端立即读取site.pp
[root@master manifests]# puppetrun --host slave.king.com
客户端
[root@slave tmp]# tail -f /var/log/messages
Dec 3 13:32:59 slave puppet-agent[10601]: triggered run
Dec 3 13:33:00 slave puppet-agent[10601]: (/Stage[main]//Exec[/tmp/hello.sh]/returns) executed successfully
Dec 3 13:33:00 slave puppet-agent[10601]: Finished catalog run in 1.22 seconds
11、crontab文件管理功能:
服务器端:
[root@master manifests]# more site.pp
# Add a crontab for puppet client
cron { logrotate:
command => "/tmp/hello.sh",
user => root,
hour => 14,
minute => 22
}
客户端:
[root@slave tmp]# puppetd --server master.king.com --test
notice: Ignoring --listen on onetime run
info: Caching catalog for slave.king.com
info: Applying configuration version '1417585229'
notice: /Stage[main]//Cron[logrotate]/ensure: created
notice: /Stage[main]//Exec[/tmp/hello.sh]/returns: executed successfully
notice: Finished catalog run in 6.17 seconds
[root@slave tmp]# crontab -l
22 14 * * * /tmp/hello.sh
后续待补充。 |
|
|