13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MongoDBでlogrotate

Posted at

rpm(mongo-10gen)でインストールしたらログローテート入ってなかった

あっ・・・

$ ll -h /var/log/mongo/
合計 651M
-rw-r----- 1 mongod mongod 651M  7月 27 16:02 2015 mongod.log

logrotateでやってみる

適当にやってみる

$ cat /etc/logrotate.d/mongo
/var/log/mongo/mongod.log
{
        rotate 4
        daily
        missingok
        create 0644 mongod mongod
}
$ logrotate -f /etc/logrotate.conf

ローテート後の 1196765 の inode 見ちゃってる

$ lsof | grep mongod.log
mongod    28392    mongod    1w      REG                8,3        71    1196765 /var/log/mongo/mongod.log-20150727
$ ls -li /var/log/mongo/
合計 8
1196912 -rw-r--r-- 1 mongod mongod   0  7月 27 15:11 2015 mongod.log
1196765 -rw-r--r-- 1 mongod mongod 210  7月 27 15:12 2015 mongod.log-20150727

公式

http://docs.mongodb.org/manual/tutorial/rotate-log-files/
SIGUSR1 でやるみたいです

直した

pid出すようにしてないのでkillallで。出しとけばよかった(´Д`)

$ cat /etc/logrotate.d/mongo
/var/log/mongo/mongod.log
{
        rotate 4
        daily
        missingok
        nocreate
        sharedscripts
        postrotate
                killall -SIGUSR1 mongod >/dev/null 2>&1 || true
        endscript
}

もう1回確認

1188640 の inode 見てる。

$ ls -li /var/log/mongo/
合計 8
1188640 -rw-r--r-- 1 mongod mongod 584  7月 27 15:26 2015 mongod.log
$ lsof | grep mongod.log
mongod    32353    mongod    1w      REG                8,3       584    1188640 /var/log/mongo/mongod.log

ローテート実行

$ logrotate -f /etc/logrotate.conf

正しくローテートできた。(1196912 の inode を見てる)

$ ls -li /var/log/mongo/
合計 12
1196912 -rw-r--r-- 1 mongod mongod  71  7月 27 15:26 2015 mongod.log
1188640 -rw-r--r-- 1 mongod mongod 584  7月 27 15:26 2015 mongod.log-20150727
$ lsof | grep mongod.log
mongod    32353    mongod    1w      REG                8,3        71    1196912 /var/log/mongo/mongod.log

参考サイト

13
12
0

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
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?