1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[VIOS] /var 容量を圧迫するcronログを自動でローテート・圧縮する設定手順

Last updated at Posted at 2025-06-27

1. はじめに

VIOSを運用していると、cronのログがローテートされずに蓄積し、/varファイルシステムの容量を圧迫することがあります。

この記事では、/etc/cronlog.confファイルを利用して、VIOSのcronログを自動でローテート・圧縮する設定手順を紹介します。

【重要】サポート対象外の設定です
本手順で利用するoem_setup_env環境での設定は、IBMの公式サポート対象外となります。実施の際は、リスクを理解した上で自己責任でご対応ください。

(注) VIOSとは?
VIOS (Virtual I/O Server) は、IBM Power Systems環境において、物理I/Oリソース(ディスクやネットワークなど)を複数の論理区画(LPAR)で共有するための仮想化機能を提供する専用サーバーです。


2. 環境

VIOS 3.1.4.10

$ ioslevel
3.1.4.10
$

oem_setup_env コマンドについて

今回の設定で使用するoem_setup_envは、VIOSの制限されたpadminシェルから、root権限を持つ通常のUNIXシェル環境へ移行するためのコマンドです。

IBMの公式ドキュメントには、以下のように記載されています。

oem_setup_env コマンド
(抜粋)
注: oem_setup_env コマンドは、 padmin ユーザーを、 /home/padmin ディレクトリーにホーム・ディレクトリーを持つ非制限 UNIX ルート・シェルに入れます。 ユーザーは、root ユーザーが使用できるすべてのコマンドを実行できます。 これは、サポートされている Virtual I/O Server 管理方式ではありません。 このコマンドの目的は、デバイス・ドライバーなどのベンダー・ソフトウェアをインストールできるようにすることです。


3. 設定手順

3.1. 【事前確認】現在のログファイルの状態を確認

oem_setup_envコマンドでroot環境に入り、現在のcronログの状態を確認します。

$ oem_setup_env
#

lsコマンドで確認すると、VIOSのデフォルト状態ではログローテートの設定がなく、ログファイルが肥大化していることが分かります。(この例では約273MB)

# ls -l /var/adm/cron
total 534416
prw-------    1 root     cron              0 Apr 18 2023  FIFO
-rw-r-----    1 bin      cron              4 May 09 2018  at.deny
-rw-r-----    1 root     system           12 Nov 21 2022  cron.allow
-rw-r-----    1 bin      cron              3 May 09 2018  cron.deny
-rw-rw----    1 bin      cron      273375738 Jun 26 19:15 log
-rw-r--r--    1 root     sys            1313 Sep 18 2014  queuedefs

3.2. /etc/cronlog.conf の作成と編集

VIOSはAIXをベースとしているため、AIXと同様に/etc/cronlog.confファイルでcronのログ動作を制御できます。

AIX マニュアル: /etc/cronlog.conf ファイル

# vi /etc/cronlog.conf

viなどのエディタでファイルを開き、以下の設定を追記します。

# ログファイルのパスを指定
logfile=/var/adm/cron/log
# 50KBに達したらローテート
size=50K
# 4世代分を保持
rotate=4
# ローテートしたファイルを圧縮する
compress

50K で小さいと思われる場合は、適宜増やしていただければと思います。


下記は追記したファイルの全量です。

【参考】/etc/cronlog.conf の全内容(クリックで展開)
# cat /etc/cronlog.conf
# @(#)90        1.2  src/bos/etc/cron/cronlog.conf, cmdcntl, bos720 11/3/06 01:08:26
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# bos720 src/bos/etc/cron/cronlog.conf 1.2
#
# Licensed Materials - Property of IBM
#
# Restricted Materials of IBM
#
# COPYRIGHT International Business Machines Corp. 2004,2006
# All Rights Reserved
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# IBM_PROLOG_END_TAG

# The configuration file informs the cron daemon where and how to log the information.
# If you do not use the -f flag, the cron daemon reads the default "/etc/cronlog.conf"
# configuration file.
# If cron fails to open the configuration file it continues with "/var/adm/cron/log".

# The cron daemon ignores blank lines and lines beginning with a # (pound sign).

# Format

# logfile Full path name of the log file. File is created with permission 664 if it doesn't exist.
# Log file should not be created in "/" file system. If cron is not able to create
# the logfile name, it creates a log of its activities in /var/adm/cron/log file
# and all the below features will be turned off.

# size This keyword limits the size of a logfile. It is followed by a number and either
# a k (kilobytes) or m(megabytes). The default and minimum size is 30K. If the size
# value is invalid then rotation feature is turned off.

# rotate This keyword specifies the total number of rotated files. It is followed by a number.
# if a number is not specified then there are unlimited number of rotated files.
# If keyword is not present then no rotation is done.
# If specified, then minimum of number of rotated files is 2.

# compress This keyword specifies that the saved rotated files will be compressed.
# If keyword is not present then no compression is done.

# archive This keyword specifies that the saved rotated files will be copied to a directory.
# It is followed by the directory name. If archive is not specified and rotation is
# valid then files are rotated in the directory of logfile.

# quiet This keyword specifies that cron logging will be disabled.

# Examples

# 1. To log information in directory /home/user, log file cron.out, size of 2M ,
# total number of rotated files = 4, archive in /usr/home, compress archive files,
# create the configuration file as follows:

# logfile=/home/user/cron.out
# size=2m
# rotate=4
# archive=/usr/home
# compress

# 2. To log information in directory /home/user, log file cron.out, size of 50k ,
# unlimited log files, archive in /usr/home, compress archive files,
# create the configuration file as follows:

# logfile=/home/user/cron.out
# size=50k
# rotate
# archive=/usr/home
# compress

# 3. To log information in directory /home/user, log file cron.out, size of 50k ,
# total number of rotated files = 4, create the configuration file as follows:

# logfile=/home/user/cron.out
# size=50K
# rotate=4
# As archive is not specified the files will be rotated in "/home/user".

# 4. To log information in directory /home/user, log file cron.out, size of 50k ,
# total number of rotated files = 4, archive in /usr/home, archive files without
# compression,  no logging of cron jobs, create the configuration file as follows:

# logfile=/home/user/cron.out
# size=50K
# rotate=4
# archive=/usr/home
# quiet
# In this case cron.out will contain only debug or error messages.

# For better performance the increase the size parameter and reduce the rotate parameter.

# --- 今回追記した設定 ---
logfile=/var/adm/cron/log
size=50K
rotate=4
compress


3.3. cronデーモンの再起動

設定を反映させるため、cronデーモンを再起動します。まずpsコマンドで現在のプロセスID(PID)を確認します。

# ps -ef | grep cron | grep -v grep
    root  5767622        1   0   Jun 18      -  0:05 /usr/sbin/cron

次に、killコマンドでプロセスを終了させます。cronデーモンはOSによって管理されているため、終了させると自動的に新しいプロセスとして再起動し、/etc/cronlog.confの設定を読み込みます。

# kill 5767622

再起動直後にpsコマンドを実行すると、新しいPIDでcronが起動し、さらに設定を読み込んで初回ローテート(圧縮)処理が動いている様子を確認できる場合があります。

#  ps -ef | grep cron | grep -v grep
    root  5767624        1   0 19:17:15      -  0:00 /usr/sbin/cron
    root 23265718  5767624  61 19:17:15      -  0:00 /bin/compress -f /var/adm/cron/log.0
#

4. 動作確認

最後に、ログファイルが正しくローテートされたかを確認します。

# ls -l /var/adm/cron
total 50032
prw-------    1 root     cron              0 Apr 18 2023  FIFO
-rw-r-----    1 bin      cron              4 May 09 2018  at.deny
-rw-r-----    1 root     system           12 Nov 21 2022  cron.allow
-rw-r-----    1 bin      cron              3 May 09 2018  cron.deny
-rw-rw----    1 bin      cron            245 Jun 26 19:18 log
-rw-rw----    1 bin      cron       25593467 Jun 26 19:17 log.0.Z
-rw-r--r--    1 root     sys            1313 Sep 18 2014  queuedefs

lsの結果から、以下の状態が確認できます。

  • logファイルが新しいファイルとなり、サイズが小さくなった。
  • 元々あった巨大なログファイルが、圧縮されてlog.0.Zとして保存された。

ログ・ローテートが確認できました。

なお、初回のlog.0.Zは設定変更前のログ全体をリネーム・圧縮したものであるためサイズが大きくなっていますが、今後は新しくなったlogファイルが50KBに達するたびに、正しくローテーションが行われます。

作業が完了後、exitコマンドでpadmin環境に戻ります。

# exit
$

おわりに


VIOSではcronログのローテートがデフォルトで有効になっていないため、/varの肥大化は比較的発生しやすい問題です。

今回紹介した方法はサポート対象外ではありますが、システムの安定運用に役立つTipsとして記載しました。


以上です。

1
0
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?