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:
Ramlog is started by the first daemon (depending on other daemon you have installed.
Then create the directory/var/log. hdd and hard link it to/var/log.
If tmpfs (default) or ramfs is used, mount it to/var/log.
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.
Then other daemon are started and the logs are updated in ramdisk. Logrotate works well with ramdisk.
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.
When the system is shut down, ramlog is shut down before the last daemon is shut down.
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:
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:
sudo dpkg -i ramlog_2.0.0_all.deb
This step completes the entire installation. Now you need to run the following command:
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:
sudo update-rc.d -f sysklogd remove
sudo update-rc.d sysklogd start 102345. stop 90016.
Then restart the system:
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:
RAMDISKTYPE=0
# Values:
#0 -- tmpfs (SWAp to swap partition) -- default
#1 -- ramfs (the maximum space size cannot be set for the old kernel,
# Cannot be switched to the swap partition, which is incompatible with SELinux)
#2 -- older kernel ramdisk
TMPFS_RAMFS_SIZE=
# Maximum memory size that can be used for tmpfs or ramfs
# The value can be either a percentage or a value (unit: Mb). For example:
# TMPFS_RAMFS_SIZE=40%
# TMPFS_RAMFS_SIZE=100m
# If this value is null, the size of tmpfs/ramfs is 50% of the total memory.
# For more options, refer to the 'mount options for tmpfs' section in 'Man mount '.
# (In addition, ramfs supports the size limit in newer kernels,
# This mounting option is not available in man)
# This option is only used when RAMDISKTYPE = 0 or 1
KERNEL_RAMDISK_SIZE=MAX
# Specify the kernel ramdisk size in kb, or use MAX to use the entire ramdisk.
# This option is only used when RAMDISKTYPE = 2
LOGGING=1
#0 = disabled, 1 = enabled. Record your own logs to/var/log/ramdisk
LOGNAME=ramlog
# Log File Name (for LOGGING = 1)
VERBOSE=1
#0 = close, 1 = open (when set to 1, teststartstop will be called when the start or stop fails to detail
# 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: