3.4. 定义日志轮转策略
目录服务器定期轮转当前日志文件并创建一个新文件。但是,您可以使用命令行或 Web 控制台设置轮转策略来更改默认行为。
您可以管理以下轮转设置:
- 最大日志数
-
设置要保留的日志文件的最大数量。达到文件数量时,Directory 服务器会在创建新日志文件前删除最旧的日志文件。默认情况下,访问日志为
10,其他日志为1。 - 最大日志大小(以 MB 为单位)
-
在轮转日志文件前以 MB 为单位设置日志文件的最大大小。默认情况下,所有日志都是
100MB。 - 每次创建新日志
- 设置日志文件的最长期限。默认情况下,Directory 服务器每周轮转所有日志。
- 一天的时间
- 设置轮转日志文件的时间。所有日志都不默认启用此设置。
- 访问模式
-
访问模式在新创建的日志文件上设置文件权限。默认情况下,所有日志都是
600。
3.4.1. 使用命令行配置日志轮转策略 复制链接链接已复制到粘贴板!
您可以使用 dsconf config replace 命令修改管理轮转策略的 cn=config DN 条目中的以下属性:
| 访问日志 | 错误日志 | 审计日志 | 审计失败日志 | 安全日志 | |
|---|---|---|---|---|---|
| 最大日志数 | nsslapd-accesslog-maxlogsperdir | nsslapd-errorlog-maxlogsperdir | nsslapd-auditlog-maxlogsperdir | nsslapd-auditfaillog-maxlogsperdir | nsslapd-securitylog-maxlogsperdir |
| 最大日志大小(以 MB 为单位) | nsslapd-accesslog-maxlogsize | nsslapd-errorlog-maxlogsize | nsslapd-auditlog-maxlogsize | nsslapd-auditfaillog-maxlogsize | nsslapd-securitylog-maxlogsize |
| 每次创建新日志 | nsslapd-accesslog-logrotationtime, nsslapd-accesslog-logrotationtimeunit | nsslapd-errorlog-logrotationtime, nsslapd-errorlog-logrotationtimeunit | nsslapd-auditlog-logrotationtime, nsslapd-auditlog-logrotationtimeunit | nsslapd-auditfaillog-logrotationtime, nsslapd-auditfaillog-logrotationtimeunit | nsslapd-securitylog-logrotationtime, nsslapd-securitylog-logrotationtimeunit |
| 一天的时间 | nsslapd-accesslog-logrotationsynchour, nsslapd-accesslog-logrotationsyncmin | nsslapd-errorlog-logrotationsynchour, nsslapd-errorlog-logrotationsyncmin | nsslapd-auditlog-logrotationsynchour, nsslapd-auditlog-logrotationsyncmin | nsslapd-auditfaillog-logrotationsynchour, nsslapd-auditfaillog-logrotationsyncmin | nsslapd-securitylog-logrotationsynchour, nsslapd-securitylog-logrotationsyncmin |
| 访问模式 | nsslapd-accesslog-mode | nsslapd-errorlog-mode | nsslapd-auditlog-mode | nsslapd-auditfaillog-mode | nsslapd-securitylog-mode |
流程
要将错误日志配置为使用访问模式 600,以保持最大 2 个日志,并使用 100 MB 或每 5 天轮转日志文件,请输入:
# dsconf -D "cn=Directory Manager" instance_name config replace nsslapd-errorlog-mode=600 nsslapd-errorlog-maxlogsperdir=2 nsslapd-errorlog-maxlogsize=100 nsslapd-errorlog-logrotationtime=5 nsslapd-errorlog-logrotationtimeunit=day有关轮转策略属性的详情,请参阅 Core server configuration attributes description 中的对应部分。