A RAMDisk is a portion of RAM which is being used as if it were a disk drive. RAMDisks have fixed sizes, and act like regular disk partitions. Access time is much faster for a RAMDisk than for a real, physical disk. However, any data stored on a RAMDisk is lost when the system is shut down or powered off.
RAMDisks can be a great place to store temporary data. Perfect candidates would be :
1) Mounting Loopback file systems (such as run-from-floppy/CD distributions),
2) Working on unencrypted data from encrypted documents,
3) In many embedded Linux systems, a RAMDisk is used to load initrd (initial Ram Disk), initrd is the final root file system.
4) Things which do not change eg. web images or downloadable files, etc.
The Linux kernel version 2.4 or later have built-in support for ramdisks. You can check if ramdisk is setup by doing:
[root@test-db]# dmesg | grep RAMDISK
RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize
You should get above output on CentOS and RHEL. Other linux flavors will have similar output as well.
1) Changing the Kernel Parameters:
Ramdisk size is controlled by a command-line option that is passed to the kernel during boot. Since GRUB is the default bootloader for CentOs 6.2, I will modify /etc/grub.conf with the new kernel option. The kernel option for ramdisk size is: ramdisk_size=xxxxxx, where xxxxxx is the size expressed in 1024-byte blocks.
Here is what I will add to /etc/grub.conf to configure 4 GB ramdisks (ramdisk_size=4194304):
[root@test-db]# vi /etc/grub.conf
Find the line which looks similar to following:
kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vg_lvm-lv_root
add ramdisk_size=4194304 to the end of the line. Now your grub.conf should look like:
--------------------------------------------------------------------------------------
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_lvm-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-220.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vg_lvm-lv_root rd_LVM_LV=vg_lvm/lv_swap rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_lvm/lv_roo
t rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM ramdisk_size=4194304
initrd /initramfs-2.6.32-220.el6.x86_64.img
--------------------------------------------------------------------------------------
Save and exit grub.conf. At this point you have it configured to have ramdisk with new size but it does not take effect until you reboot your system.
Once you have rebooted your system, we can start doing rest of configurations.
2) Format the ramdisk :
There is no need to format the ramdisk as a journaling file system, so we will simply use the ubiquitous ext2 file system. I only want to use one ramdisk, so I will only format /dev/ram0:
[root@test-db]# mke2fs -m 0 /dev/ram0
The -m 0 option keeps mke2fs from reserving any space on the file system for the root user, which is the default behavior. I want all of the ramdisk space available to a regular user for working with encrypted files.
3) Create a mount point and mount the ramdisk :
Now that you have formatted the ramdisk, you must create a mount point for it. Then you can mount your ramdisk and use it. We will use the directory /mnt/rd for this operation.
[root@test-db]# mkdir /ramdisk
[root@test-db]# mount /dev/ram0 /ramdisk
Now verify the new ramdisk mount:
[root@test-db]# df -h | grep ram0
4) Performance benchmarking :
Now that it has been created, you can copy, move, delete, edit, and list files on the ramdisk exactly as if they were on a physical disk partiton. We can do a IO benchmark by using the dd command.
In the example below the "/hdisk" is a folder on the servers hard drive and "/ramdisk" is the mounted ramdisk.
[root@test-db]# dd if=/dev/zero of=/hdisk/X1 bs=128k count=10240
10240+0 records in
10240+0 records out
1342177280 bytes (1.3 GB) copied, 50.6943 s, 26.5 MB/s
[root@test-db]# dd if=/dev/zero of=/ramdisk/X1 bs=128k count=10240
10240+0 records in
10240+0 records out
1342177280 bytes (1.3 GB) copied, 4.34945 s, 309 MB/s
The difference is clearly visible.
RAMDisk is also a great place to view decrypted GPG or OpenSSL files, as well as a good place to create files that will be encrypted. After your host is powered down, all traces of files created on the ramdisk are gone.
To unmount the ramdisk, simply enter the following:
[root@test-db]# umount -v /ramdisk
If you remount the ramdisk, your data will still be there. Once memory has been allocated to the ramdisk, it is flagged so that the kernel will not try to reuse the memory later. Therefore, you cannot “reclaim” the RAM after you are done with using the ramdisk. For this reason, you will want to be careful not to allocate more memory to the ramdisk than is absolutely necessary. In my case, I am allocating < 10% of the physical RAM. You will have to tailor the ramdisk size to your needs. Of course, you can always free up the space with a reboot!
Automating ramdisk creation :
If you need to create and mount a ramdisk every time your system boots, you can automate the process by adding some commands to your /etc/rc.local init script.
Here are the lines that can be added:
# Formats, mounts, and sets permissions for the 4 GB ramdisk
/sbin/mke2fs -q -m 0 /dev/ram0
/bin/mount /dev/ram0 /ramdisk
/bin/chown apache:apache /ramdisk
/bin/chmod 0750 /ramdisk
Cheers !
Harish.
Showing posts with label dd. Show all posts
Showing posts with label dd. Show all posts
Thursday, January 12, 2012
Wednesday, July 28, 2010
Zabbix 1.8.2 on CenOS 5.5 (x86_64)
Installing Zabbix 1.8.2 on CenOS 5.5 and generating fake load to check the installation
==================================================================================
Install the basic CentOS 5.5 on a machine.
==================================================================================
Update CentOS using the following command:
yum -y update
Note : Disable firewall and SELinux only for testing
==================================================================================
Install EPEL using the following command:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
==================================================================================
Install mysql and php using yum:
yum install mysql mysql-server php php-gd php-bcmath php-xml php-mbstring php-mysql
==================================================================================
Download Zabbix rpm file from http://fedora.danny.cz/danny-el/5Server/
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-web-mysql-1.8.2-2.el5.x86_64.rpm
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-server-1.8.2-2.el5.x86_64.rpm
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-1.8.2-2.el5.x86_64.rpm
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-docs-1.8.2-2.el5.x86_64.rpm
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-agent-1.8.2-2.el5.x86_64.rpm
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-web-1.8.2-2.el5.x86_64.rpm
wget http://fedora.danny.cz/danny-el/5Server/x86_64/zabbix-server-mysql-1.8.2-2.el5.x86_64.rpm
==================================================================================
Install the downloaded Zabbix rpm's using the following command :
yum --nogpgcheck localinstall zabbix-1.8.2-2.el5.x86_64.rpm zabbix-server-1.8.2-2.el5.x86_64.rpm zabbix-server-mysql-1.8.2-2.el5.x86_64.rpm zabbix-agent-1.8.2-2.el5.x86_64.rpm zabbix-docs-1.8.2-2.el5.x86_64.rpm zabbix-web-1.8.2-2.el5.x86_64.rpm zabbix-web-mysql-1.8.2-2.el5.x86_64.rpm
==================================================================================
service httpd restart
chkconfig httpd on
==================================================================================
Configuring the Database part (MySQL)
service mysqld restart
chkconfig mysqld on
mysqladmin -u root password passw0rd!
mysql --user=root --password=passw0rd!
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> create database zabbix character set utf8;
mysql> create user 'zabbix'@'localhost' identified by 'password';
mysql> grant all on zabbix.* to zabbix;
mysql> flush privileges;
mysql> quit
Bye
Insert schema, data and images
cd /usr/share/doc/zabbix-server-mysql-1.8.2/create/schema
mysql --user=zabbix --password=password zabbix <>
cd ../data/
mysql --user=zabbix --password=password zabbix <>
mysql --user=zabbix --password=password zabbix <>
==================================================================================
Configuing PHP
edit /etc/php.ini
;...
;max_execution_time = 600
;max_input_time = 600
;memory_limit = 256M
...
;upload_max_filesize = 16M
...
;post_max_size = 32M
...
;date.timezone = Europe/Brussels
...
;mbstring.func_overload = 2
...
==================================================================================
Config Zabbix-server
edit /etc/zabbix/zabbix_server.conf
...
# Database user
DBUser=zabbix
....
#DBPassword=
DBPassword=
...
==================================================================================
Config Zabbix-webinterface
create /usr/share/zabbix/conf/zabbix.conf.php (remove the ;)
;
;global $DB_TYPE,
;$DB_SERVER,
;$DB_PORT,
;$DB_DATABASE,
;$DB_USER,
;$DB_PASSWORD,
;$IMAGE_FORMAT_DEFAULT;
;$DB_TYPE = "MYSQL";
;$DB_SERVER = "localhost";
;$DB_PORT = "0";
;$DB_DATABASE = "zabbix";
;$DB_USER = "zabbix";
;$DB_PASSWORD = "";
;$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
;?>
==================================================================================
service zabbix-server start
chkconfig zabbix-server on
service zabbix-agent start
chkconfig zabbix-agent on
lsof -i:10050
more /var/log/zabbix/zabbix_agentd.log
==================================================================================
http://server/zabbix
Login using the following credentials :
login: admin / password: zabbix
==================================================================================
Generate Fake CPU load :
perl -e 'while (--$ARGV[0] and fork) {}; while () {}' 4
top
==================================================================================
Generate Fake Disk-IO load and Free unused memory currently unavailable :
dd if=/dev/zero of=junk bs=1M count=1K (This will vreate a 1 GB file)
dd if=/dev/zero of=junk bs=1M count=10K (This will vreate a 10 GB file)
This is an useful command for when your OS is reporting less free RAM than it actually has. In case terminated processes did not free their variables correctly, the previously allocated RAM might make a bit sluggis over time.
This command then creates a huge file made out of zeroes and then removes it, thus freeing the amount of memory occupied by the file in the RAM.
In this example, the sequence will free up to 1GB(1M * 1K) of unused RAM. This will not free memory which is genuinely being used by active processes.
rm -rf junk
==================================================================================
Monitor Disk IO performance using iostat:
yum -y install sysstat
iostat -x 10 > /tmp/iostat.txt
tail -f /tmp/iostat.txt
==================================================================================
Test network speed without wasting disk
dd if=/dev/zero bs=1M count=1M | ssh root@192.168.160.161 'cat > /dev/null'
The above command will send 1GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space.
ENJOY !
Labels:
alerts,
centos,
dd,
dixit,
epel,
graphs,
harish,
harishdixit,
monitoring,
mysql,
php,
smartstream,
system performance,
yum,
zabbix
Subscribe to:
Posts (Atom)