puppet之crontab時間同步
puppet很重要的一點就是時間同步,所以在搭建puppet伺服器時首先要保證每臺客戶端和伺服器的時間要一致。可以在puppet伺服器上配置一個cron模組,所有客戶端每隔數分鐘同步一次時間,時間伺服器可以是任何一個可用的ntp,本文用的是上海交大的時間伺服器ntp.sjtu.edu.cn。
新建一個cron模組
[root@master modules]# tree cron/
cron/
`-- manifests
|-- addcron.pp
|-- base.pp
`-- init.pp
1 directory, 3 files
[root@master modules]#
定義新增cron類,指明同步的時間伺服器,更新頻率。
[root@master manifests]# cat addcron.pp
class cron::addcron {
cron {
ntpdate:
command => "/sbin/ntpdate ntp.sjtu.edu.cn",
ensure => "present",
user=> "root",
minute => "*/5",
}
}
定義cron服務類,crond服務要保持在執行狀態
[root@master manifests]# cat base.pp
class cron::base {
service {
crond:
ensure => running,
enable => true,
pattern => cron,
}
}
初始化
[root@master manifests]# cat init.pp
class cron {
include cron::base
include cron::addcron
}
匯入cron模組
[root@master puppet]# cat /etc/puppet/manifests/modules.pp
import "cron"
......
在每個節點檔案中,引入cron類
[root@master puppet]# cat /etc/puppet/manifests/nodes.pp
node 'agent1.andy.com' {
include cron
include java
include mysql
}
node 'agent2.andy.com' {
include cron
include java
include mysql
}
node 'agent3.andy.com' {
include cron
include java
include mysql
}
客戶端手動執行puppet agent --server master.andy.com --test 或配置定時更新可以在每個客戶端都新增一個crontab。
客戶端定時同步更新配置如下,每10分鐘同步更新一次
[root@agent1 ~]# cat /etc/puppet/puppet.conf
[main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
server = master.andy.com
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
runinterval = 600
[root@agent1 ~]#
結果如下
[root@agent1 ~]# crontab -l
# HEADER: This file was autogenerated at Mon Dec 02 12:20:16 +0800 2013 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: ntpdate
*/5 * * * * /sbin/ntpdate ntp.sjtu.edu.cn
新建一個cron模組
[root@master modules]# tree cron/
cron/
`-- manifests
|-- addcron.pp
|-- base.pp
`-- init.pp
1 directory, 3 files
[root@master modules]#
定義新增cron類,指明同步的時間伺服器,更新頻率。
[root@master manifests]# cat addcron.pp
class cron::addcron {
cron {
ntpdate:
command => "/sbin/ntpdate ntp.sjtu.edu.cn",
ensure => "present",
user=> "root",
minute => "*/5",
}
}
定義cron服務類,crond服務要保持在執行狀態
[root@master manifests]# cat base.pp
class cron::base {
service {
crond:
ensure => running,
enable => true,
pattern => cron,
}
}
初始化
[root@master manifests]# cat init.pp
class cron {
include cron::base
include cron::addcron
}
匯入cron模組
[root@master puppet]# cat /etc/puppet/manifests/modules.pp
import "cron"
......
在每個節點檔案中,引入cron類
[root@master puppet]# cat /etc/puppet/manifests/nodes.pp
node 'agent1.andy.com' {
include cron
include java
include mysql
}
node 'agent2.andy.com' {
include cron
include java
include mysql
}
node 'agent3.andy.com' {
include cron
include java
include mysql
}
客戶端手動執行puppet agent --server master.andy.com --test 或配置定時更新可以在每個客戶端都新增一個crontab。
客戶端定時同步更新配置如下,每10分鐘同步更新一次
[root@agent1 ~]# cat /etc/puppet/puppet.conf
[main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
server = master.andy.com
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
runinterval = 600
[root@agent1 ~]#
結果如下
[root@agent1 ~]# crontab -l
# HEADER: This file was autogenerated at Mon Dec 02 12:20:16 +0800 2013 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: ntpdate
*/5 * * * * /sbin/ntpdate ntp.sjtu.edu.cn
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-1062118/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- puppet agent定時同步更新
- 執行crontab最好的時間(轉)
- 同步vmware時間
- chrony時間同步
- centos:時間同步CentOS
- NTP時間同步
- ntpd 時間同步
- 時間同步 - rdate
- Centos 時間同步CentOS
- chrony 時間同步
- Oracle 10g RAC之配置時間同步Oracle 10g
- 【Django】Django定時任務之-crontabDjango
- linux之 crontab 定時任務Linux
- 叢集時間同步
- Linux同步時間Linux
- NTP配置時間同步
- Linux 時間同步Linux
- Linux時間同步Linux
- 同步vmware時間(ZT)
- NTP時間同步 For AIXAI
- Linux 時間同步Linux
- 時間同步的修改
- 再談時間同步
- 系統時間和硬體時間同步
- puppet之安裝配置
- crontab與系統時間不一致
- crontab 定時
- Linux下時間同步 ---夏令時Linux
- Linux下時間同步 --- 夏令時Linux
- Linux ntpdate同步時間Linux
- Oracle叢集時間同步Oracle
- Linux 時間同步配置Linux
- linux ntp時間同步Linux
- 時間同步(Arch Linux)Linux
- chrony時間同步服務
- ubuntu 修改時區或時間 及網路同步時間Ubuntu
- Linux使用ntp時間伺服器同步時間Linux伺服器
- linux 如何建立定時任務?crontab -e 定時任務使用的時間是系統時間Linux