Merge pull request #2406 from soooogreen/master

Update 20150126 Improve system performance by moving your log files to RAM Using Ramlog
干得好!
This commit is contained in:
Xingyu.Wang 2015-02-11 23:41:14 +08:00
commit b523fd3d42
2 changed files with 111 additions and 113 deletions

View File

@ -1,113 +0,0 @@
translating by soooogreen
Improve system performance by moving your log files to RAM Using Ramlog
================================================================================
Ramlog act as a system daemon. On startup it creates ramdisk, it copies files from /var/log into ramdisk and mounts ramdisk as /var/log. All logs after that will be updated on ramdisk. Logs on harddrive are kept in folder /var/log.hdd which is updated when ramlog is restarted or stopped. On shutdown it saves log files back to harddisk so logs are consistent. Ramlog 2.x is using tmpfs by default, ramfs and kernel ramdisk are suppored as well. Program rsync is used for log synchronization.
Note: Logs not saved to harddrive are lost in case of power outage or kernel panic.
Install ramlog if you have enough of free memory and you want to keep your logs on ramdisk. It is good for notebook users, for systems with UPS or for systems running from flash -- to save some write cycles.
How it works and what it does:
1.Ramlog starts among the first daemons (it depends on other daemons you have installed).
2.Directory /var/log.hdd is created and hardlinked to /var/log.
3.In case tmpfs (default) or ramfs is used, it is mounted over /var/log
If kernel ramdisk is used, ramdisk created in /dev/ram9 and it is mounted to /var/log, by default ramlog takes all ramdisk memory specified by kernel argument "ramdisk_size".
5.All other daemons are started and all logs are updated in ramdisk. Logrotate works on ramdisk as well.
6.In case ramlog is restarted (by default it is one time per day), directory /var/log.hdd is synchronized with /var/log using rsync. Frequency of the automatic log saves can be controller via cron, by default, the ramlog file is placed into /etc/cron.daily
7.On shutdown ramlog shuts among the last daemons.
8. During ramlog stop phase files from /var/log.hdd are synchronized with /var/log
Then /var/log is unmounted, /var/log.hdd is unmounted as well and empty directory /var/log.hdd is deleted.
**Note:- This article is for advanced users only**
### Install Ramlog in Ubuntu ###
First you need to download the .deb package from [here][1] using the following command
wget http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb
Now you should be having ramlog_2.0.0_all.deb package install this package using the following command
sudo dpkg -i ramlog_2.0.0_all.deb
This will complete the installation now you need to run the following commands
sudo update-rc.d ramlog start 2 2 3 4 5 . stop 99 0 1 6 .
#Now update sysklogd in init levels, so it is stopped properly before ramlog is stopped:
sudo update-rc.d -f sysklogd remove
sudo update-rc.d sysklogd start 10 2 3 4 5 . stop 90 0 1 6 .
Now you need to restart your system
sudo reboot
After rebooting you need to run ramlog getlogsize' to determine the size of your actual /var/log.Add about 40% to that number to ensure your ramdisk has sufficient size -- this will be the ramdisk size
Edit your boot manager config file such as /etc/grub.conf, /boot/grub/menu.lst or /etc/lilo.conf and add update the actual kernel by adding kernel paramter ramdisk_size=xxx' where xxx is calculated ramdisk size
### Configuring Ramlog ###
Ramlog configuration file is located in /etc/default/ramlog on deb based systems and you can set there below variables:
Variable (with default value):
Description:
RAMDISKTYPE=0
# Values:
# 0 -- tmpfs (can be swapped) -- default
# 1 -- ramfs (no max size in older kernels,
# cannot be swapped, not SELinux friendly)
# 2 -- old kernel ramdisk
TMPFS_RAMFS_SIZE=
#Maximum size of memory to be used by tmpfs or ramfs.
# The value can be percentage of total RAM or size in megabytes -- for example:
# TMPFS_RAMFS_SIZE=40%
# TMPFS_RAMFS_SIZE=100m
# Empty value means default tmpfs/ramfs size which is 50% of total RAM.
# For more options please check man mount', section Mount options for tmpfs'
# (btw -- ramfs supports size limit in newer kernels
# as well despite man says there are no mount options)
# It has only effect if RAMDISKTYPE=0 or 1
KERNEL_RAMDISK_SIZE=MAX
#Kernel ramdisk size in kilobytes or MAX to use entire ramdisk.
#It has only effect if RAMDISKTYPE=2
LOGGING=1
# 0=off, 1=on Logs can be found in /var/log/ramdisk
LOGNAME=ramlog
# name of the ramlog log file (makes sense if LOGGING=1)
VERBOSE=1
# 0=off, 1=on (if 1, teststartstop puts detials
# to the logs and it is called after start or stop fails)
### How to uninstall Ubuntu ###
Open the terminal and run the following command
sudo dpkg -P ramlog
Note: If ramlog was running before you uninstalled it, you should reboot your box to finish uninstallation procedure.
--------------------------------------------------------------------------------
via: http://www.ubuntugeek.com/improve-system-performance-by-moving-your-log-files-to-ram-using-ramlog.html
作者:[ruchi][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.ubuntugeek.com/author/ubuntufix
[1]:http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb

View File

@ -0,0 +1,111 @@
系统性能优化支招使用Ramlog将日志文件转移到RAM
================================================================================
Ramlog以系统守护进程的形式存在。它系统启动的时候创建了虚拟磁盘ramdisk将文件从目录/var/log复制到虚拟磁盘中同时把虚拟磁盘挂载为/var/log。接着更新虚拟磁盘上所有的日志。硬盘上的日志会保留在目录/var/log中直到ramlog重启或停止时被更新。而关机的时候ramdisk上的日志文件会重新保存到硬盘上以确保日志一致性。Ramlog 2.x默认使用tmpfs文件系统同时也可以支持ramfs和内核ramdisk。使用rsync译注Linux数据镜像备份工具这个工具来同步日志。
注意没有保存进硬盘的日志将在断电或者内核混乱kernel panic的情况下丢失。
如果你拥有空间足够的可用内存而又想把日志放进虚拟磁盘就安装ramlog吧。它是笔记本用户、UPS系统或是直接在flash中运行的系统节省写周期的优良选择。
Ramlog的运行机制以及步骤
1.Ramlog在第一个守护进程这取决于你所安装过的其它守护进程的基础上启动。
2.然后创建目录/var/log.hdd并将其硬链至/var/log。
3.如果使用的是tmpfs默认或者ramfs之一的文件系统将其挂载到/var/log上。
而如果使用的是内核ramdiskramdisk将在/dev/ram9中创建并将挂载至/var/log。默认情况下ramlog会占用所有ramdisk的内存其大小由内核参数"ramdisk_size"指定。
5.接着其它的守护进程被启动并在ramdisk中更新日志。Logrotate译注Linux日志轮替工具也是在ramdiks之上运行。
6.重启默认一天一次ramlog时目录/var/log.hdd将借助rsync与/var/log保持同步。日志自动保存的频率可以通过cron译注Linux例行性工作调度来控制。默认情况下ramlog文件放置在目录/etc/cron.daily下。
7.系统关机时ramlog在最后一个守护进程关闭之前关闭。
在ramlog关闭期间/var/log.hdd中的文件将被同步至/var/log接着/var/log和/var/log.hdd都被卸载然后删除空目录/var/log.hdd。
**注意:- 此文仅面向高级用户**
### 在Ubuntu中安装Ramlog ###
首先需要用以下命令,从[这里][1]下载.deb安装包
wget http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb
下载ramlog_2.0.0_all.deb安装包完毕使用以下命令进行安装
sudo dpkg -i ramlog_2.0.0_all.deb
这一步会完成整个安装,现在你需要运行以下命令:
sudo update-rc.d ramlog start 2 2 3 4 5 . stop 99 0 1 6 .
#现在在初始状态下升级sysklogd使之能在ramlog停止运行前正确关闭
sudo update-rc.d -f sysklogd remove
sudo update-rc.d sysklogd start 10 2 3 4 5 . stop 90 0 1 6 .
然后重启系统:
sudo reboot
系统重启完毕,运行'ramlog getlogsize'获取/var/log的空间大小。在此基础之上多分配40%的空间确保ramdisk有足够的空间这整个都将作为ramdisk的空间大小
编辑引导配置文件,如/etc/grub.conf,、/boot/grub/menu.lst 或/etc/lilo.conf译注具体哪个配置文件视不同引导加载程序而定kernel参数新增项'ramdisk_size=xxx'以更新当前内核其中xxx是ramdisk的空间大小。
### 配置Ramlog ###
基于deb的系统中Ramlog的配置文件位于/etc/default/ramlog你可以在该目录下设置以下变量
Variable (with default value):
Description:
RAMDISKTYPE=0
# Values:
# 0 -- tmpfs (can be swapped) -- default
# 1 -- ramfs (no max size in older kernels,
# cannot be swapped, not SELinux friendly)
# 2 -- old kernel ramdisk
TMPFS_RAMFS_SIZE=
#Maximum size of memory to be used by tmpfs or ramfs.
# The value can be percentage of total RAM or size in megabytes -- for example:
# TMPFS_RAMFS_SIZE=40%
# TMPFS_RAMFS_SIZE=100m
# Empty value means default tmpfs/ramfs size which is 50% of total RAM.
# For more options please check man mount', section Mount options for tmpfs'
# (btw -- ramfs supports size limit in newer kernels
# as well despite man says there are no mount options)
# It has only effect if RAMDISKTYPE=0 or 1
KERNEL_RAMDISK_SIZE=MAX
#Kernel ramdisk size in kilobytes or MAX to use entire ramdisk.
#It has only effect if RAMDISKTYPE=2
LOGGING=1
# 0=off, 1=on Logs can be found in /var/log/ramdisk
LOGNAME=ramlog
# name of the ramlog log file (makes sense if LOGGING=1)
VERBOSE=1
# 0=off, 1=on (if 1, teststartstop puts detials
# to the logs and it is called after start or stop fails)
### 在Ubuntu中卸载ramlog ###
打开终端运行以下命令:
sudo dpkg -P ramlog
注意如果ramlog卸载之前仍在运行需要重启系统完成整个卸载工作。
--------------------------------------------------------------------------------
via: http://www.ubuntugeek.com/improve-system-performance-by-moving-your-log-files-to-ram-using-ramlog.html
作者:[ruchi][a]
译者:[soooogreen](https://github.com/soooogreen)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.ubuntugeek.com/author/ubuntufix
[1]:http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb