Tuesday, December 21, 2010

Doing some works on Load Balancer with Crossroads.

Well, it's finally about time to begins my senior project stuffs.
Let's say I've been doing busy with some jobs earlier, So I didn't have a chance to look at it much.
But It is nearly new year, everybody's going back their home after midterm examinations.
For me, It's time to move on and working on stuffs.
The less people, The more I can concentrate on this work. (I don't like to be surrounded by people much.)

Talk to much, let's see how I install crossroads on ubuntu. It's easy and work fine.

First download the crossroads package from their website.
$cd /
$wget http://crossroads.e-tunity.com/downloads/crossroads-stable.tar.gz
Untar it.
$tar -xzvf crossroads-stable.tar.gz
Then before starting our installation. Make sure that you've already installed the build-essential package.
$sudo apt-get install build-essential
 Let's begin!
$cd crossroads-2.68
$sudo make install
Wait for a moment. Then we done!
Now it's time for configuration.
Crossroads provides two ways of configuration. Using command-line, or using xml.
Let's see the first one. If we need to use command-line, then we use "xr" command for all configuration.
$xr --verbose --server tcp0:80 / #this will tell xr that we use this server as load balancer
-W 10.10.10.1:8001 / #and this will create our web interface on port 8001
-backend 10.10.10.2:80 / #this will create backend according to the ip address and port
-backend 10.10.10.3:80
This will make your server to listen to port 80 and to dispatch traffic to servers 10.10.10.2 and 10.10.10.3
A web interface for the balancer is started on port 8001

Instead of starting XR by hand, we may use xrcrl as preferable. But first, you've to create a configuration.
To do so, put the following in the file /etc/xrctl.xml
<?xml version="1.0" encoding="UTF-8"?>
     <configuration>
        <system>
          <uselogger>true</uselogger>
          <logdir>/tmp</logdir>
        </system>
        <service>
          <name>web</name>
        <server>
          <address>0:80</address>
          <type>tcp</type>
          <webinterface>10.10.10.1:8001</webinterface>
          <verbose>yes</verbose>
        </server>
        <backend>
          <address>10.10.10.2:80</address>
        </backend>
        <backend>
          <address>10.10.10.3:80</address>
        </backend>
        </service>
     </configuration>
Then type these following commands to start the xr
$xrctl start
Or to stop.
$xrctl stop 
That's all for today. Late night again. OMG!!

Credits : Crossroads

Saturday, December 18, 2010

How to install FTP with vsftpd.

Very easy to configure. recommended!!


First install via apt-get
$sudo apt-get install vsftpd
Let's have it back up before doing anything is recommend!
$sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
Now begin to configure!
Disable anonymous login and enable local users login, give them write permission.
anonymous_enable=NO
# Let local users login
# If you connect from the internet with local users, you should enable TLS/SSL/FTPS
local_enable=YES

# Write permissions
write_enable=YES
To Deny some users to login
userlist_deny=YES
userlist_file=/etc/vsftpd.denied_users
In the file /etc/vsftpd.denied_users add the username of the users that can't login. One username per line.

To Allow some users to login
userlist_deny=NO
userlist_enable=YES
userlist_file=/etc/vsftpd.allowed_users
In the file /etc/vsftpd.allowed_users add the username of the users that can login. One username per line.

TLS/SSL/FTPS
Add these code at the end of file.
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES
Additional Options
# Show hidden files and the "." and ".." folders.
# Useful to not write over hidden files:
force_dot_files=YES

# Hide the info about the owner (user and group) of the files.
hide_ids=YES

# Connection limit for each IP:
max_per_ip=3

# Maximum number of clients:
max_clients=5
Then, have it applied new configuration.
$sudo /etc/init.d/vsftpd restart 
That's all the configurations I've applied to my ftp server.
If you need more option, please kindly visit this site which can provides you for further information.
Ubuntu Forum 


Credits : epimeteo from Ubuntu Forum. Thx :)

Thursday, December 16, 2010

Great book on Servlets & JSP

It's really good to think of reading a textbook instead of a bunch of papers of your class.
In Thailand, Educational system in higher level such Bachelor's Degree in many high-rank University
still using a bunch of papers, which we called "sheet", for teaching during class.
It's just a slide-printed on paper. So, seems like I can't find much of details in there.
For me, to know and understand what I learned from class is to read the whole details of the topics,
not only the topics and some of information that lied around the paper.

On my last exam I took, which is today, about noon. It's the Internet Programming class.
It's about Servlets and JSP. Unfortunately, I've skipped 2 classes, my head's gone empty
until I've found a book which tutor's using as reference. Head First Servlets and JSP
It's really great book! I recommended for this book if you're totally new to Servlets and JSP.
But, it required some of Java Skills. So, you might need to know Java before start reading this one.
Oh, I didn't buy the book actually, I borrowed it from the library at my Institute.
Don't look in the bad way. I don't have that much of money to spend, even I did spend a lot
on many books from Amazon.com

Anyway, I'm totally like this book. It have great content. Also,the way they represent details on each topic is
like..you know, It's comic, full of pictures and images. It's good for your brain when you've to
remember something so complicated.

That's all for today :)

Tuesday, December 7, 2010

Insertion Sort and Merge Sort in Java

Well it's my homework in DAA (Design and Analysis of Algorithms)
Talking about the algorithms, itself is brought from the book that we've used
which is "Introduction to Algorithms 3rd edition"
It's a good book, but I do weak in maths somehow.
So, probably there is some of them I couldn't understand right away.
It's bad to have a worst logic and maths skill, you know?
whatever, let's see the code that I have written using Java.
(Somebody said that they doesn't like Java because of its performance,
But I don't. I prefer it than C/C++ in some way.)

Insertion Sort
public static void insertionSort_2(int x[]) {
        int i, j, key;
        for (j = 1; j < x.length; j++) {
            key = x[j];  
            i = j - 1; 
            while (i >= 0 && x[i] > key) { 
                x[i + 1] = x[i]; 
                i = i - 1; .
            }
            x[i + 1] = key; 
        }
    }
This one works based on the algorithms of insertion sort. First we find the key.
then we lock the key so we won't get confuse between
the length of array we are caring and the one that is still out of our sight.
after that we just sorting it, by compare the value of an array, one by one.
when it have sorted, we just change the key. moving to the next one until the whole array is sorted.

Merge Sort
public static void merge_sort(int y[], int p, int r) {
        if (r > p) {
            int q = (p + r) / 2;
            merge_sort(y, p, q);
            merge_sort(y, q + 1, r);
            merge(y, p, q, r);
        }
    }
 Merge method
public static void merge(int y[], int p, int q, int r) {
        int n1 = q - p + 2;
        int n2 = r - q + 1;
        int i, j, k;
        int []left = new int[n1];
        int []right = new int[n2];
        //Cp y to left array
        for (i = 0; i < n1 - 1; i++) {
            left[i] = y[p + i];
        }
        left[n1 - 1] = INF;
        //Cp y to right array
        for (i = 0; i < n2 - 1; i++) {
            right[i] = y[q + 1 + i];
        }
        right[n2 - 1] = INF;
        i = 0;
        j = 0;
        for (k = p; k <= r; k++) {
            if (left[i] <= right[j]) {
                y[k] = left[i];
                i++;
            } else {
                y[k] = right[j];
                j++;
            }
        }
    }
For merge sort, there are two method you need.
The first one is for divide an array into separate two of them.
Another one is for merging them together.
I won't explain it clearly because it will take me a while to try to explain it.
As you can see that I'm not English native, so It's quite hard to write.

And It's all for tonight. I'm late for my bed again.

Thanks for reading
:)