วันพฤหัสบดีที่ 19 เมษายน พ.ศ. 2555

file system performance : drop caches

#hdparm -tT /dev/sda
#hdparm -I /dev/sda

create test file on the disk
#dd if=/dev/zero of=/home/file.img bs=8k count=256

measuring performance
#iotop -b -n 1 -o
#cat /proc/slabinfo

Before start new test, restart system or clear disk caches
#sync; echo 3 > /proc/sys/vm/drop_caches
#sync; echo 0 > /proc/sys/vm/drop_caches


http://www.linuxinsight.com/proc_sys_vm_drop_caches.html

วันอังคารที่ 3 เมษายน พ.ศ. 2555

LiveCD software raid starting at md125


If you boot existing with live cd it may change the device name (/dev/mdx) starting from 125. This can prevent system from starting up normally.(/etc/fstab still use the old /dev/mdx name starting from md1). To rename software raid, stop and assemble it. :

This will rename md125 ... 127 to md1 ... md3 respectively

#mdadm --stop /dev/md125
#mdadm --assemble /dev/md1 /dev/sda1 /dev/sdb1
#mdadm --stop /dev/md126
#mdadm --assemble /dev/md2 /dev/sda2 /dev/sdb2
#mdadm --stop /dev/md127
#mdadm --assemble /dev/md3 /dev/sda3 /dev/sdb3

วันพุธที่ 14 มีนาคม พ.ศ. 2555

mysql user copy/migration



gensqluser.sh  : this script will gen sql statement for creating new user
---
mygrants()
{
  mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
    'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
    ) AS query FROM mysql.user" | \
  mysql $@ | \
  sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
}

mygrants --host=localhost --user=username--password=password
---

host1# ./gensqluser.sh >> user.sql

host2# mysql -u -p < user.sql


bash script read file line by line

#/bin/bash

while read myline
do
  echo $myline
done < inputfile

วันพฤหัสบดีที่ 12 มกราคม พ.ศ. 2555

awk basic

awk is very useful tool for linux user.
For example, you have output from ps aux like this :

#ps aux 

root      2213  0.0  0.4   6596  2428 pts/2    S    12:08   0:00 bash
root      2235  0.0  0.1   4848   952 pts/2    S+   12:08   0:00 /bin/bash xxx
root      2236  0.0  0.6   7132  3236 pts/2    S+   12:08   0:04 ssh xxx

The second column is PID, and 8th is process state.
To find the zombie process you just execute the following command  :

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z


See just use $th of the column, you will get the value of that column. Also, you can apply even you have comma separated field with -F option.

For more usage of this command please consult
#man awk

:)


วันอังคารที่ 13 ธันวาคม พ.ศ. 2554

Ubuntu ramdisk


Mounting ram as a working space which help I/O faster.

#mkdir -p /tmp/ram#sudo mount -t tmpfs -o size=512M tmpfs /tmp/ram/

However, be careful to not exceed the memory you have in the system.


http://www.ubuntuka.com/ubuntu-ramdisk-ramdrive-easy-way/

วันพฤหัสบดีที่ 8 ธันวาคม พ.ศ. 2554

ubuntu installing mongodb- part II : install php driver

After finishing this part, your php will be able to use mongodb function. 

To install mongodb php driver, first of all we need pecl to install from PHP repository. 
#sudo apt-get install php5-dev php5-cli php-pear
Running pecl to get and install php driver. 
#sudo pecl install mongo
Turn your back to the screen and have a coffee while system compiling the mongo extension. After finishing installation, you will see this : 
Build process completed successfully
Installing '/usr/lib/php5/20090626+lfs/mongo.so'
install ok: channel://pecl.php.net/mongo-1.2.6
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
Then, edit php.ini  (/etc/php5/cli/php.ini, ubuntu)  and add this line extension=mongo.so.


Reference : http://www.mongodb.org/display/DOCS/PHP+Language+Center