puppet master 192.168.122.2 server2.example.com
puppet client 192.168.122.3 server3.example.com
puppet client 192.168.122.4 server4.exmaple.com
4:用户组定义:
group { "linux": gid => 600 }
5. 用户定义
user { "linux":
uid => 600,
gid => 600,
home => "/home/linux",
shell => "/bin/bash" ,
password => linux
}
file { "/home/linux":
owner => linux,
group => linux,
mode => 700,
ensure => directory
}
file { "/home/linux/.bash_logout":
source => "/etc/skel/.bash_logout",
owner => linux,group => linux
}
file { "/home/linux/.bash_profile":
source => "/etc/skel/.bash_profile",
owner => linux,
group => linux
}
file { "/home/linux/.bashrc":
source => "/etc/skel/.bashrc",
owner => linux,
group => linux
}
user { "test": uid => 900,
home => "/home/test",
shell => "/bin/bash",
provider => useradd,
managehome => true,
ensure => present
}
exec { "echo linux | passwd --stdin test":
path => "/usr/bin:/usr/sbin:/bin",
onlyif => "id test"
}
6. 文件系统挂载
首先确保有共享文件可供使用,这里使用nfs文件系统作为共享文件。在client端可以看见192.168.122.2这台主机上的共享文件
client 端:
showmount -e 192.168.122.2
Export list for 192.168.122.2:
/share *
编辑配置文件
file {"/public":
ensure => directory
}
mount { "/public":
device => "192.168.122.2:/share",
fstype => "nfs",
options => "defaults",
ensure => mounted
}
clients 端可以看见服务端的共享文件已被成功挂载
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 6926264 953980 5620440 15% /
tmpfs 510200 0 510200 0% /dev/shm
/dev/sda1 495844 33469 436775 8% /boot
192.168.122.2:/share 6926336 948864 5625600 15% /public
7. crontab 任务
ron { echo:
command => "/bin/echo `/bin/date` >> /tmp/echo",
user => root,
hour => ['2-4'], #注意这个时执行任务的时间区间
minute => '*/10'
}
# 任务会在 client 上/var/spool/cron 目录中生成。
# cat /var/spool/cron/root
*/10 16-20 * * * /bin/echo `/bin/date` >> /tmp/echo
8:不同节点的定义:
a. 在 puppetmaster 上编辑 site.pp
# vim /etc/puppet/manifests/site.pp
import "nodes/*.pp"
# mkdir /etc/puppet/manifests/nodes/
b. 建立节点文件
# vim /etc/puppet/manifests/nodes/server3.example.com.pp
node 'server3.example.com'{
file{"/var/www/html/index.html":
content => "server3.example.com"
}
}
# vim /etc/puppet/manifests/nodes/server4.example.com.pp
node 'server4.example.com' {
file { "/var/www/html/index.html":
content => "server4.example.com"
}
}
9:编写模块:
# mkdir -p /etc/puppet/modules/httpd/{files,manifests,templates}
# cd /etc/puppet/modules/httpd/manifests
vim install.pp
class httpd::install {
package { "httpd":
ensure => present
}
}
# vim config.pp
class httpd::config {
file { "/etc/httpd/conf/httpd.conf":
ensure => present,
source => "puppet:///modules/httpd/httpd.conf", #实际路径在/etc/puppet/modules/httpd/files/httpd.conf
require => Class["httpd::install"],
notify => Class["httpd::service"]
}
}
# vim service.pp
class httpd::service {
service { "httpd":ensure => running,
require => Class["httpd::install","httpd::config"]
}
}
# vim init.pp
class httpd {
include httpd::install,httpd::config,httpd::service
}
# vim /etc/puppet/manifests/nodes/server3.example.com
node 'server3.example.com'{
file{"/var/www/html/index.html":
content => "server3.example.com"
}
include httpd
}
# vim /etc/puppet/modules/httpd/files/httpd.conf
#Listen 12.34.56.78:80
Listen 8080
# service puppetmaster reload
client 端再次登录时:
# netstat -antulp | grep httpd
tcp 0 0 :::8080 :::* LISTEN 5206/httpd
阅读(2259) | 评论(0) | 转发(0) |