วันอังคารที่ 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.

mysql backup/dump/export table schema, definition


1) use mysqldump
server# mysqldump -uroot -p dbname tblname -d 
with this method you will get sql statement. You can use this for backing up table definition as well.

2) create table from another table
mysql> create table if not exists tblname like old_tblname;
with this method you get a copy of table. It is useful if you want to have a another table with the same structure for backing up, testing.



วันศุกร์ที่ 5 สิงหาคม พ.ศ. 2554

Postfix วิธีการ pipe mail ที่ได้รับ ไปยัง command ต่างๆ

Environment ที่ใช้ทดสอบนะครับ ใช้ Ubuntu 10.04.3, Postfix, Dovecot เป็นหลัก สิ่งที่ต้องการคือ เมื่อมีคนส่ง e-mail มาที่ test@example.com แล้ว ให้ postfix ทำการ pipe email นั้นเข้าสู่โปรแกรม /home/myuser/testperl ซึ่งเป็น perl script ที่ผมเขียนรอไว้ก่อนหน้านี้แล้ว

ทั้งนี้ ตัว postfix ผม config ตัว virtual domains, virtual mailbox ที่ติดต่อกับ mysql server เอาไว้ด้วยนะครับ

เริ่มจาก

  • เข้าไปแก้ไข /etc/postfix/main.cf

ที่บรรทัด smtpd_recipient_restrictions เพิ่มคำสั่ง check_recipient_access เข้าไป

smtpd_recipient_restrictions =  
# bypass checks on outgoing mail  
permit_mynetworks  
# reject if not full email address  
reject_non_fqdn_recipient 
# next line rejects if the account/domain does not exist  
# ALSO prevents OPEN RELAY - if missing RELAY is OPEN!!  
# MUST appear before the check_recipient_access  
reject_unauth_destination  
# perform filter access by recipient name  
check_recipient_access hash:/usr/local/etc/postfix/script_filter
  • เพิ่ม /etc/postfixscript_filter
test@example.com FILTER support:dummy
  • # postmap script_filter จะมีไฟล์ script_filter.db เพิ่มขึ้นมา
  • เข้าไปแก้ master.cf
support  unix - n n - - pipe  flags=Rq user=www    argv=/home/myuser/testperl $(sender)$(recipient)

โดยใน perl script จะได้ argument 1 = sender และ argument 2 = receiver

แค่นี้ ระบบก็เรียบร้อยพร้อมใช้งานแล้ว ยิ้ม

วันพฤหัสบดีที่ 16 มิถุนายน พ.ศ. 2554

How to Setup Canon MX350 Series on Ubuntu 11.04 Natty

sudo add-apt-repository ppa:michael-gruz/canon
sudo apt-get update

apt-get install cnijfilter-mx350series

and now you can add printer by
1. Go to search -> printing
2. Add -> Network Printer
3. Canon MX350 Series will appear in left panel
4. Follow the instruction
5. Finish installation

วันพฤหัสบดีที่ 9 มิถุนายน พ.ศ. 2554

Ubuntu apt-get history

for Ubuntu admin you can track apt-get history at

/var/log/apt/history.log
for a brief

and

for more detail at
/var/log/apt/term.log

mdadm cheat sheet

Mdadm Cheat Sheet

1. Create a new RAID array

Create (mdadm –create) is used to create a new array:
mdadm --create --verbose /dev/md0 --level=1 /dev/sda1 /dev/sdb2
or using the compact notation:
mdadm -Cv /dev/md0 -l1 -n2 /dev/sd[ab]1

2. /etc/mdadm.conf

/etc/mdadm.conf or /etc/mdadm/mdadm.conf (on debian) is the main configuration file for mdadm. After we create our RAID arrays we add them to this file using:
mdadm --detail --scan >> /etc/mdadm.conf
or on debian
mdadm --detail --scan >> /etc/mdadm/mdadm.conf

3. Remove a disk from an array

We can’t remove a disk directly from the array, unless it is failed, so we first have to fail it (if the drive it is failed this is normally already in failed state and this step is not needed):
mdadm --fail /dev/md0 /dev/sda1
and now we can remove it:
mdadm --remove /dev/md0 /dev/sda1

This can be done in a single step using:
mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

4. Add a disk to an existing array

We can add a new disk to an array (replacing a failed one probably):
mdadm --add /dev/md0 /dev/sdb1


5. Verifying the status of the RAID arrays

We can check the status of the arrays on the system with:
cat /proc/mdstat
or
mdadm --detail /dev/md0

The output of this command will look like:

cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
104320 blocks [2/2] [UU]

md1 : active raid1 sdb3[1] sda3[0]
19542976 blocks [2/2] [UU]

md2 : active raid1 sdb4[1] sda4[0]
223504192 blocks [2/2] [UU]

here we can see both drives are used and working fine – U. A failed drive will show as F, while a degraded array will miss the second disk -

Note: while monitoring the status of a RAID rebuild operation using watch can be useful:
watch cat /proc/mdstat

6. Stop and delete a RAID array

If we want to completely remove a raid array we have to stop if first and then remove it:
mdadm --stop /dev/md0
mdadm --remove /dev/md0

and finally we can even delete the superblock from the individual drives:
mdadm --zero-superblock /dev/sda

#Clone partition table
sfdisk -d /dev/sda | sfdisk /dev/sdb

(this will dump the partition table of sda, removing completely the existing partitions on sdb, so be sure you want this before running this command, as it will not warn you at all).

There are many other usages of mdadm particular for each type of RAID level, and I would recommend to use the manual page (man mdadm) or the help (mdadm –help) if you need more details on its usage. Hopefully these quick examples will put you on the fast track with how mdadm works.

Reference :
http://www.ducea.com/2009/03/08/mdadm-cheat-sheet/

วันศุกร์ที่ 3 มิถุนายน พ.ศ. 2554

ubuntu snmp

I've install cacti to a server which will poll the data from linux box, installed snmp.

To test polling data from cacti to linux box,
#snmpwalk -c public -v 2c [ip-address]

In ubuntu if you want to allow other host to view this data you need to modified
"/etc/default/snmp "

SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid [ip-address]'





วันอังคารที่ 31 พฤษภาคม พ.ศ. 2554

apache http auth with cgi

If you are using apache http auth with cgi, you have a few more things to do.
You need to enable .htaccess

RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]

วันอาทิตย์ที่ 15 พฤษภาคม พ.ศ. 2554

mysql open query log without changing my.cnf and restart

Use mysql client connect to server

#show variables like 'general%';

+------------------+----------------------------+
| Variable_name | Value |
+------------------+----------------------------+
| general_log | OFF |
| general_log_file | /var/run/mysqld/mysqld.log |
+------------------+----------------------------+

This 2 vaiables control mysql query logging.

To turn query log on :
SET GLOBAL general_log_file = '/var/log/mysql/sql-log.log' ;
SET GLOBAL general_log = 1


To turn query log off :
SET GLOBAL general_log = 0 ;
SET GLOBAL general_log_file = '/var/run/mysqld/mysqld.log';

Notice: This is for mysql 5.1 only. For mysql 5.0, those variable is not available. you need editing my.cnf and restart.

วันพฤหัสบดีที่ 24 กุมภาพันธ์ พ.ศ. 2554

วันอังคารที่ 22 กุมภาพันธ์ พ.ศ. 2554

perc H200 hardware raid utility in linux

I just bought server coming with hardware raid PERC H200 (Dell).
By the time of this blog, I understand that it use chipset from LSI here are out put from

#lspci --n
LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon] [1000:0072] (rev 03)

Unfortunately, the monitoring software for this h/w raid is not open. You have to download sas2ircu bin code. The program will display raid status.
I've downloaded from this link :

Please visit for usage:
http://hwraid.le-vert.net/wiki/LSIFusionMPTSAS2#a2.Linuxkerneldrivers

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

protecting web access with mod_auth

You can limit web access by password. Apache has module mod_auth* for you. It's easy.



1. create password file
# htpasswd -c /usr/local/apache/passwd/passwords rbowen
New password: mypassword
Re-type new password: mypassword
Adding password for user rbowen

for additional user just remove "-c"

2. add directive to apache (.httaccess or )
AuthType Basic
AuthName "Restricted Files"
# (Following line optional)
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen

3. Restart apache and have fun!
If you have a problem, please investigate the error_log first.


More information :