Performance Optimization: Use Ramlog to transfer log files to memory

Source: Internet
Author: User

Performance Optimization: Use Ramlog to transfer log files to memory

Ramlog runs as a system daemon. When the system starts, it creates a virtual disk (ramdisk), Copies files under/var/log to the virtual disk, and mounts the virtual disk to/var/log. Then all the logs are updated to the virtual disk. When ramlog is restarted or stopped, logs that need to be recorded on the hard disk are stored in the/var/log. hdd directory. When the server is shut down, the log files (on ramdisk) are resaved to the hard disk to ensure log consistency. Ramlog 2.x uses the tmpfs File System by default, and supports ramfs and kernel ramdisk. Use rsync to synchronize logs.

Note: logs that are not stored in the hard disk will be lost when a sudden power failure or kernel panic occurs.

If you have enough available memory and want to put logs into the virtual disk, install ramlog. It is a good choice for notebook users, systems with UPS, or systems running directly in flash, which can save the writing time of logs.

The Ramlog operating mechanism and steps are as follows:

  1. Ramlog is started by the first daemon (depending on other daemon you have installed.

  2. Then create the directory/var/log. hdd and hard link it to/var/log.

  3. If tmpfs (default) or ramfs is used, mount it to/var/log.

  4. If the kernel ramdisk is used, ramdisk is created in/dev/ram9 and mounted to/var/log. By default, ramlog occupies the memory of all ramdisks, which is specified by the Kernel Parameter ramdisk_size.

  5. Then other daemon are started and the logs are updated in ramdisk. Logrotate works well with ramdisk.

  6. When you restart ramlog (once a day by default), the directory/var/log. hdd will be synchronized with/var/log through rsync. The frequency of automatic log storage can be controlled by cron. By default, the scheduling tasks of ramlog are stored in the/etc/cron. daily directory.

  7. When the system is shut down, ramlog is shut down before the last daemon is shut down.

  8. When ramlog is disabled,/var/log. files in hdd will be synchronized to/var/log, and then/var/log and/var/log. all hdds are uninstalled, And the empty directory/var/log is deleted. hdd.

Note:-This article is only intended for advanced users.

 

Install Ramlog in Ubuntu

First, run the following command to download the. deb installation package:

  1. wget http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb

After downloading the ramlog_2.0.0_all.deb installation package, run the following command to install it:

  1. sudo dpkg -i ramlog_2.0.0_all.deb

This step completes the entire installation. Now you need to run the following command:

  1. sudo update-rc.d ramlog start 22345. stop 99016.

Now, update the initialization sequence of sysklogd so that it can be disabled correctly before ramlog stops running:

  1. sudo update-rc.d -f sysklogd remove
  2. sudo update-rc.d sysklogd start 102345. stop 90016.

Then restart the system:

  1. sudo reboot

After the system is restarted, run 'ramlog getlogsize' to obtain the space of your current/var/log. On this basis, allocate 40% more space to ensure that the ramdisk has enough space (the entire space will be used as the size of the ramdisk ).

Edit the boot configuration file, such as/etc/grub. conf,/boot/grub/menu. lst or/etc/lilo. conf (Note: Which configuration file depends on different boot loader), to your current kernel New Option 'ramdisk _ size = XXX ', xxx indicates the size of ramdisk space.

 

Configure Ramlog

In deb-based systems, the Ramlog configuration file is located in/etc/default/ramlog. You can set the following variables in this configuration file:

  1. RAMDISKTYPE=0
  2. # Values:
  3. #0 -- tmpfs (SWAp to swap partition) -- default
  4. #1 -- ramfs (the maximum space size cannot be set for the old kernel,
  5. # Cannot be switched to the swap partition, which is incompatible with SELinux)
  6. #2 -- older kernel ramdisk
  7. TMPFS_RAMFS_SIZE=
  8. # Maximum memory size that can be used for tmpfs or ramfs
  9. # The value can be either a percentage or a value (unit: Mb). For example:
  10. # TMPFS_RAMFS_SIZE=40%
  11. # TMPFS_RAMFS_SIZE=100m
  12. # If this value is null, the size of tmpfs/ramfs is 50% of the total memory.
  13. # For more options, refer to the 'mount options for tmpfs' section in 'Man mount '.
  14. # (In addition, ramfs supports the size limit in newer kernels,
  15. # This mounting option is not available in man)
  16. # This option is only used when RAMDISKTYPE = 0 or 1
  17. KERNEL_RAMDISK_SIZE=MAX
  18. # Specify the kernel ramdisk size in kb, or use MAX to use the entire ramdisk.
  19. # This option is only used when RAMDISKTYPE = 2
  20. LOGGING=1
  21. #0 = disabled, 1 = enabled. Record your own logs to/var/log/ramdisk
  22. LOGNAME=ramlog
  23. # Log File Name (for LOGGING = 1)
  24. VERBOSE=1
  25. #0 = close, 1 = open (when set to 1, teststartstop will be called when the start or stop fails to detail
  26. # Writing to logs)

 

Uninstall ramlog in Ubuntu

Open the terminal and run the following command:

sudo dpkg -P ramlog

NOTE: If ramlog is still running before it is detached, restart the system to complete the uninstallation.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.