Monday, July 26, 2010

[Level 3] My Boy Friend (Bash Framework) Project @ first release

Recently, I collect my bash script,
and design my pattern for it.

Now, I decided to release it with
Creative Commons Attribution-Share Alike 3.0 Taiwan License.

With it can help you for your daily jobs.

Download link:
My Boy Friend (Bash Framework) Project.

Wish this helps.
regards,
Stanley Huang

Thursday, July 22, 2010

[Level 1] Install CouchDB in Ubuntu

How to install CouchDB in Ubuntu,
just use apt-get
# apt-get install couchdb

After start couchdb, then if you want to test manage couchdb.
You can use your brower to mange it.
# firefox http://localhost:5984 (default port)

If you want to test it by command,
you have two ways to do that.

1. Use telnet command:
# telnet locahost 5984
GET /test/test1234 HTTP/1.1
HTTP/1.0 200 OK
Server: CouchDB/0.10.0 (Erlang OTP/R13B)
Etag: "2-51d7e462ab7a57a53c0bd5a2b3becd52"
Date: Thu, 22 Jul 2010 03:04:54 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 80
Cache-Control: must-revalidate

{"_id":"test1234","_rev":"2-51d7e462ab7a57a53c0bd5a2b3becd52","name":"Stanley"}
Connection closed by foreign host.
#

2. Use curl:
a. First, download curl.
# apt-get install curl
b. Use curl to get data
# curl -X GET http://localhost:5984
/test/test1234{"_id":"test1234","_rev":"2-51d7e462ab7a57a53c0bd5a2b3becd52",
"name":"Stanley"}
#

Wish this helps.
regards,
Stanley Huang

Thursday, July 8, 2010

[Level 3] Maintain MySQL schema.

If you want to maintain MySQL with more flexible,
you need a procedure to do this for you.
(especially you want to manage schema upgrade patch...)
Therefore I write a procedure for this purpose, please refer to following code:

-- Usage: sp_altertable('database','table','column','add/drop/modify', 'type');
-- ex. mysql> call sp_altertable('test','mytab','mycol','add', 'varchar(2)');
-- ex. mysql> call sp_altertable('test','mytab','mycol','drop', '');
delimiter //
DROP PROCEDURE IF EXISTS sp_altertable//
CREATE PROCEDURE sp_altertable(in tableschema varchar(32), in tablename varchar(32), in columnname varchar(32), in action varchar(8), in ddl_statement varchar(128))
BEGIN
    set @sDDL='';
    select concat('ALTER TABLE ', tableschema, '.', tablename, ' ', action, ' ', columnname,' ', ddl_statement) into @sDDL;
    -- select @sDDL;
    prepare stmt_name from @sDDL;
    IF action='add' AND NOT EXISTS(
        SELECT * FROM information_schema.COLUMNS
        WHERE COLUMN_NAME=columnname AND TABLE_NAME=tablename AND TABLE_SCHEMA=tableschema
        ) THEN
            execute stmt_name;
    ELSEIF action='drop' AND EXISTS(
        SELECT * FROM information_schema.COLUMNS
        WHERE COLUMN_NAME=columnname AND TABLE_NAME=tablename AND TABLE_SCHEMA=tableschema
        ) THEN
            execute stmt_name;
    ELSEIF action='modify' THEN
        execute stmt_name;
    END IF;
END;
//
delimiter ;

Wish this helps.
regards,
Stanley Huang

[Level 1] Install Cassandra on OpenSolaris

You can install Cassandra by following steps:
# pfexec mkdir -p /var/lib/cassandra
# pfexec mkdir -p /var/lib/cassandra/data
# pfexec mkdir -p /var/lib/cassandra/commitlog
# pfexec mkdir -p /var/lib/cassandra/logs
# pfexec mkdir -p /var/log/cassandra
# pfexec chown -R root:root /var/lib/cassandra /var/log/cassandra
# pfexec chmod -R 755 /var/lib/cassandra

Set user environment on ~/.bashrc
export CASSANDRA_HOME=$HOME/cassandra/src
export CASSANDRA_CONF=$HOME/cassandra/conf
export CASSANDRA_PATH=$CASSANDRA_HOME/bin
export PATH=$CASSANDRA_PATH:$PATH

Then you have to download git (SUNWgit) from OpenSolaris repository to get Cassandra's source code.
# pkg install SUNWgit

Use git command as following to get the Cassandra's source:
# cd ~/         ## change working directory to user home, because we set 
                           CASSANDRA_HOME directory in $HOME/cassandra
# git clone git://git.apache.org/cassandra.git src

Select the 0.6.3 tag and create a branch.

# cd src
# git co origin/tags/cassandra-0.6.3
# git branch -b 0.6.3-sakai

Building the code, and the Cassandra jar using Ant.

# cd $CASSANDRA_HOME
# ant
# ant jar




Modify the storage-conf.xml in $CASSANDRA_CONF directory to add in the keyspace used.

Wish this helps.
regards,
Stanley Huang

Monday, July 5, 2010

[Level 2] Setup OpenVPN in OpenSolaris

Down pkgutil from Blastwave:
http://sourceforge.net/projects/pkgutil/
Prepare environment:
# unzip ./pkgutil-2.0.zip
# mkdir -p /var/opt/csw/
# ln -s `pwd` /var/opt/csw/
Install OpenVPN: 
# /opt/csw/bin/pkgutil -i tun tap
# /opt/csw/bin/pkgutil -i openvpn

Modify config:
# cd  /etc/csw/openvpn
# cp ./openvpn.conf.CSW ./openvpn.conf
# vi ./openvpn.conf


Setting vpn client: 
client
dev tun
proto tcp
remote vpn.server.hostname 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
comp-lzo
verb 3

Wish this helps. 
regards, 
Stanley Huang