【问题标题】:Puppet Logrotate木偶日志旋转
【发布时间】:2018-06-01 21:38:21
【问题描述】:

我正在尝试使用 puppet 为 logrotate 创建一个测试配置。但似乎我遗漏了一些东西,因为它没有创建旋转文件。 我的要求是如果日志文件超过 x 大小,它应该轮换日志。

下面是人偶代码sn-p。

$conf_params = {
        dateext  => true,
        compress => true,
        ifempty  => false,
        mail     => false,
        olddir   => false,
      }
      $configdir     = '/etc'
      $root_group    = 'root'
      $logrotate_bin = '/usr/sbin/logrotate'
      $base_rules = {
        'test' => {
          path         => '/root/test/logs/test.log'
          create_mode  => '0775',
          copytruncate => true,
          size         => '10M',
        },
      }
      $rule_default = {
        missingok    => true,
        create       => true,
        size         => '10M',
        create_owner => 'root',
        create_group => 'root',
}
}

【问题讨论】:

  • 这就是我的logrotate.conf 文件的样子compress create dateext nomail noolddir notifempty rotate 4 weekly # configurable file rotations include /etc/logrotate.d
  • 这些只是变量。您需要某种资源来管理 logrotate 配置文件。

标签: puppet logrotate puppet-enterprise


【解决方案1】:

正如https://stackoverflow.com/users/5343387/matt-schuchard 所提到的,您只声明了变量并且没有调用任何东西。从示例看来,您可能正在尝试使用 voxpupuli-logrotate 模块。

如果是这样,您可能不需要设置$configdir$root_group$logrotate_bin,因为您指定的值是除FreeBSD 之外的所有值的默认值。您不能真正覆盖 base_rules 和 rule_default,因为它们是在私有类中定义的。那就是说您可能不想更改这些值,如果您不想要默认规则,只需设置logrotate::create_base_rules: false。最后通过设置logrotate::rules 哈希创建您自己的规则。

把这些放在一起,我们有以下内容

$conf_params = {
  dateext  => true,
  compress => true,
  ifempty  => false,
  mail     => false,
  olddir   => false,
}
$rules = {
  'test' => {
    'path'         => '/root/test/logs/test.log',
    'create_mode'  => '0775',
    'copytruncate' => true,
    'size'         => '10M',
  }
}
class {'logrotate':
  config => $conf_params,
  rules  => $rules,
}

或者你也可以

include logrotate

然后使用hiera

logrotate::config:
  dateext: true
  compress: true
  ifempty: false
  mail: false
  olddir: false
logrotate::rules
  test:
    path: /root/test/logs/test.log
    create_mode: '0775'
    copytruncate: true
    size: 10M

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 2017-02-15
    • 2015-08-14
    • 2020-03-02
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多