วันพฤหัสบดีที่ 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

วันพุธที่ 30 พฤศจิกายน พ.ศ. 2554

ubuntu installing mongodb- part I : install server




The newest version of mongodb is not in repository of ubuntu. To install newest 2.0, custom repository 10gen is needed.

Add key :
#sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

Add repository by creating file name '/etc/apt/sources.list.d/10gen.list'
with this line :
(using upstart)
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
You're ready to install :
#apt-get update#apt-get install mongodb-10gen
The mongodb is running in the system. The configuration for mongodb is /etc/mongodb.conf and in /etc/init/mongodb.conf (for startup script)

Reference:
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

วันศุกร์ที่ 14 ตุลาคม พ.ศ. 2554

(link) Nginx "how to" - Fast and Secure webserver

This might be a informative link worth to visit if you are experiencing performance issue with web server. Nginx is an option.
https://calomel.org/nginx.html

วันศุกร์ที่ 30 กันยายน พ.ศ. 2554

mysql commonly use statement

Create table
mysql> CREATE  table if not exists tblname like old_tblname;

INSERT ... SELECT
mysql> INSERT INTO tblname1 SELECT *  from tblname2 where ...;

Empty table
mysql> TRUNCATE table story_longcon_40;

Delete/Drop table
mysql> DROP TABLE tblname

Delete/Drop database
mysql> DROP {DATABASE | SCHEMA} [IF EXISTS] db_name
Optimize Table

mysql> OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE tbl_name [, tbl_nam

Delete binary logs 
This will delete the binary log till master.000080
mysql> purge binary logs to 'master-bin.000081';

Start slave
mysql> START SLAVE [thread_type [, thread_type] ... ]
or
mysql> START SLAVE [SQL_THREAD] UNTIL
MASTER_LOG_FILE = 'log_name', MASTER_LOG_POS = log_pos


วันพฤหัสบดีที่ 29 กันยายน พ.ศ. 2554

[MySQL] Backing up data

There are several ways to backing up data
1) Logical backup

* SQL dumps
#mysqldump dbname tblname
Not suitable for huge backup. Both table structure and the data are stored together.(option available)

* Delimited file backups
backing up :

mysql> SELECT * INTO OUTFILE '/tmp/t1.txt'
    -> FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    -> LINES TERMINATED BY '\n'
    -> FROM test.t1


restore :

mysql> LOAD DATA INFILE '/tmp/t1.txt'
    -> INTO TABLE test1.t1
    -> FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    -> LINES TERMINATED BY '\n';
*parallel dump: maatkit(mk-parallel-dump)

2) File system snapshot (LVM)
not covered here.