日志系统,突然从24号之后的都断层了,交易看不见。查了一下问题是MongoDB把硬盘撑爆了,看了下情况:

-bash-3.2$ du -h
82M     ./log
3.1G    ./db/journal
4.0K    ./db/ciflogs/_tmp
4.0G    ./db/ciflogs
4.0K    ./db/local/_tmp
1.1G    ./db/local
4.0K    ./db/_tmp
8.1G    ./db
8.2G    .

去google了两把,又去官网看了下,发现官网FAQ中有一段回答:(注意加粗部分)

Why are the files in my data directory larger than the data in my database?

  • Preallocated data files.

    mongod may allocate a 1 gigabyte data file that may be 90% empty. For most larger databases, unused allocated space is small compared to the database.

    On Unix-like systems, mongod preallocates an additional data file and initializes the disk space to 0. Preallocating data files in the background prevents significant delays when a new database file is next allocated.

    You can disable preallocation with the noprealloc run time option. However noprealloc is not intended for use in production environments: only use noprealloc for testing and with small data sets where you frequently drop databases.

    On Linux systems you can use hdparm to get an idea of how costly allocation might be:

    time hdparm --fallocate $((1024*1024)) testfile
    
  • oplog.

    Change the Size of the Oplog.

  • journal.

    Journaling Mechanics.

  • Empty records.

    MongoDB maintains lists of empty records in data files when deleting documents and collections. MongoDB can reuse this space, but will never return this space to the operating system.

    compact if you are critically low on disk space.

    Important

    compact only removes fragmentation from MongoDB data files and does not return any disk space to the operating system.

    http://docs.mongodb.org/manual/faq/storage/

然后在Journaling Mechanics页面又有详细对于Journa的介绍:

Journal Files

/data/db by default. The journal directory holds journal files, which contain write-ahead redo logs. The directory also holds a last-sequence-number file. A clean shutdown removes all the files in the journal directory.

j._. When a journal file holds 1 gigabyte of data, MongoDB creates a new journal file. Once MongoDB applies all the write operations in the journal files, it deletes these files. Unless you write many bytes of data per-second, the journal directory should contain only two or three journal files.

mongod.

To speed the frequent sequential writes that occur to the current journal file, you can ensure that the journal directory is on a different filesystem.

Important

 If you place the journal on a different filesystem from your data files you cannot use a filesystem snapshot alone to capture valid backups of a dbpath directory. In this case, use fsyncLock() to ensure that database files are consistent before the snapshot and fsyncUnlock() once the snapshot is complete.

Note

 Depending on your filesystem, you might experience a preallocation lag the first time you start a mongod instance with journaling enabled.

mongod process determines that it is more efficient to preallocate journal files than create new journal files as needed. The amount of time required to pre-allocate lag might last several minutes, during which you will not be able to connect to the database. This is a one-time preallocation and does not occur with future invocations.

http://docs.mongodb.org/manual/core/journaling/

 

文中可以看出,journa最多只有3个文件。也就是最大只会占用3G硬盘,而且停止之后会自动删除。启动时使用-smallfiles则会让mongo的journa最大128M。

另外删除的纪录不会立刻释放硬盘,但会在下次写入的时候重新利用。

OK,停一下Mongo,删掉journa,用smallfiles参数。另外删掉一些太早的日志纪录。

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2021-10-06
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2021-11-07
  • 2021-12-19
相关资源
相似解决方案