Monday, September 30, 2013

DRBD Configuration

In order to configure DRBD we need to follow these simple steps.

1. Have a root access on each servers
2. Using GPARTED create partition on both servers with a capacity of at least 2.0GB. Remember to take note of the name of the partitions since were gonna use them both in the configuration.

Creating partition using GPARTED
3. After creating partitions you can now configure the drbd.conf  file. This is located in /etc/drbd.conf. You can use Vi, Gedit or anything that is comfortable to you.

NOTE : Before configuration you need to do these steps first.
3.1 Rename each servers accordingly by doing this commands on the terminal.
    a. hostname [your_hostname] (eg. hostname drbd01).
    b. edit /etc/hostname then change the value with the respective hostname you used.
3.2 Acquire each of the computer's IP address by typing IFCONFIG.

After doing this two steps we can now configure drbd.conf. Just input the values similar to the image below on both computers or on the server1 alone then using scp just copy it to the second server (tests connectivity too!). 
DRBD Configuration
As you can notice we will use the hostname, partition name and the ip address of both servers in the configuration so make you sure you have taken note of this properly.

4. After configuring drbd.conf we can now start the drbd by typing /etc/drbd.init start (you can also replace start with restart if the service is already running for the configuration to take effect). The following responses should appear as shown in the image below. Do this on both servers.

Initializing DRBD
5. After starting DRBD you need to initialize the metadata by typing sudo drbdadm create mdr0. Afterwards on server1 type sudo drbdadm -- --overwrite-data-of-peer primary all. This line of code will allow replication of data on all servers whenever the data in the PRIMARY server is modified. Type can check the connectivity of server 2 to server 1 by typing watch n1 cat /proc/drbd. This monitors the process of server1 from server2.

Monitoring server1
6. Finally we can now mount the partition we created on both servers by doing these commands.
    a. sudo mkfs.ext3 /dev/drbd0
    b. sudo mount /dev/drbd0  /srv

Mounting the partition created
7. Now that we have successfully configured DRBD we can now check if the configuration works properly. Copy any file into the partition from the Primary server and these changes should also be reflected on server2.

Monday, September 2, 2013

DRDB


PART I. MySQL and WebPage

The exercise is divided into two parts

A. Install PHP and MySQL
B. Create a simple webpage with 3 functionalities
    1. Sign In
    2. Sign Out
    3. Register

Task A.

Installing apache2: to install type sudo apt-get install apache2

Apache1

Apache2

Installing MySQL: to install type sudo apt-get install mysql-server. After installing test the mysql if it is working properly (see 4th picture)
MySQL 1

MySQL 2

MySQL 3

Creating table
Installing Php5: to install type sudo apt-get install php5 libapache2-mod-php5. After installing verify it through localhost. It can now successfully read .php files
Php 1


Php 2

Php 3

Task B.


In this task we are to create a simple web page. With the functionality given above. Here are the screenshots of the webpage. This was created using HTML 5, CSS and PHP.



Register Page
Sign In Page


Search Page
Search Result

Part 2. GParted and DRBD configuration.

A. GParted

GParted is a partitioning tool used to separate the hard disk into multiple spaces. I have used a different partition tool long time ago, but in essence what it does is it provides a separate storage.

For example:

We have hard drive capacity of 180GB, we can divide it into 3 parts, 80 GB for OS1 80 GB for OS2 and 20GB for the bootloading and other hardware files/configurations that are needed.

To configure

1. Open GParted. A prompt should appear asking for a password. (Type "user" in our case).


2. After opening we should see something like this.


3. To Configure
  3.1 Select an unallocated parition.
  3.2 Click New

  3.3 Set the New Size to 2056 MB ~ 2GB


  3.4 Click Add : after clicking add the partition should appear.


3.5 Apply : the changes you made would be useless unless you apply them. To apply go to
Edit->Apply All Operations.


Now you have successfuly created your own partition.

B. DRBD Configuration

1. Installation : DRBD is already installed
2. Configuration : 

2.1 Set up the two machines

We can do this by using the previous setup we have learned
* on terminal type hostname drbd-1 on server 1 and drbd-2 on server2
* edit /etc/hostnames, change it to drbd-1 and 2 accordingly
* assign a static ip on both machines. using ifconfig. assign 192.168.0.1 on server 1 and 192.168.0.2 on server 2
* edit /etc/hosts then include both machines with their respective IP's
* reboot
* configure /etc/drbd.conf


* start drbd if it returns an error that says no meta-data found type drbdadm create-md r0


Starting DRBDADM

Starting DRBD
* the partitioning of the other machine is not yet completed


Tuesday, July 30, 2013

Heartbeat Pacemaker

PRE-GUIDED BLOG

(see GUIDED BLOG below for updates)

[This is a theoretical blog on how to setup HA-HB server]

What you need?

  • 2 Connected computers
  • Heartbeat (Daemon)
  • Pacemaker (Cluster Resource Manager / CRM)

In the original discussion the setup is created using a switch ( connected to the internet ) 2 servers (computers) one will be the primary and the other one is the backup. This servers are connected directly via a ethernet crosscable and a serial cable ( in order to pass data ). Since we do not have a ethernet cross cable at our disposal. We will copy the setup that we did in our last exercise (DHCP configuration). Instead of using a ethernet cross cable we will connect them wirelessly.

After creating the topology we will now proceed into configuring the 3 core files in heartbeat these are: 
  1. /etc/ha.d/ha.cf
    http://www.linux-ha.org/doc/users-guide/_creating_an_initial_heartbeat_configuration.html#_the_literal_ha_cf_literal_file

    autojoin none
    mcast bond0 239.0.0.43 694 1 0
    bcast eth2
    warntime 5
    deadtime 15
    initdead 60
    keepalive 2
    node alice
    node bob
    pacemaker respawn
  2. /etc/ha.d/authkeys
    http://www.linux-ha.org/doc/users-guide/_the_literal_authkeys_literal_file.html

    auth <num>
    <num> <algorithm> <secret>
    
    or
    
    
    ( echo -ne "auth 1\n1 sha1 "; \
      dd if=/dev/urandom bs=512 count=1 | openssl md5 ) \
      > /etc/ha.d/authkeys
    chmod 0600 /etc/ha.d/authkeys
  3. /etc/ha.d/haresources

    http://voices.yahoo.com/installing-configuring-heartbeat-ubuntu-server-3778384.html?cat=15
Then we configure the pacemaker:
http://clusterlabs.org/doc/en-US/Pacemaker/1.1/html/Clusters_from_Scratch/
or 
http://www.zivtech.com/blog/setting-ip-failover-heartbeat-and-pacemaker-ubuntu-lucid

After doing the steps in the link above hopefully we are done. 

REFERENCES:

  1. HEARTBEAT - http://www.linux-ha.org/doc/users-guide/users-guide.html
  2. PACEMAKER - http://clusterlabs.org/doc/en-US/Pacemaker/1.1/html/Clusters_from_Scratch/
  3. HEARTBEAT + PACEMAKER - http://www.zivtech.com/blog/setting-ip-failover-heartbeat-and-pacemaker-ubuntu-lucid
  4. http://voices.yahoo.com/installing-configuring-heartbeat-ubuntu-server-3778384.html?cat=15

[This part is what I did step by step in configuring the heartbeat only using : http://voices.yahoo.com/installing-configuring-heartbeat-ubuntu-server-3778384.html?cat=15]

Configuring /etc/ha.d/ha.cf


Configuring /etc/ha.d/authkeys


Configuring /etc/ha.d/haresources


Starting Heartbeat
In this part I have failed to start the heartbeat because node2 is non existent that's why on the upper portion of the blog I have stated that we need 2 Computers because I have overlooked the fact that each node corresponds to a computer. This steps also failed to accomplish the pacemaker part thus I think this setup is incomplete.

GUIDED BLOG

After failing to configure heartbeat  successfully during the first two sessions, we have now a guide on how to accomplish the task. Here is the list of tasks that are needed to be done in order to accomplish heartbeat.

Step 0: Remove/Purge Heartbeat and Apache2

Since other students have used the computer, their previous configurations are present so we need to do a sudo apt-get purge apache2 heartbeat or sudo apt-get remove --purge apache2 heartbeat in order to remove their configurations. (Note: we can eliminate redundant typing of sudo by typing first sudo -s).


Removing Previous Installations.

Step 1: Changing host names

We need to change hostnames in order to identify computer1 from computer2 since all computer in the pclab are named user. To change the hostnames we need to do to steps.
  1. Type sudo hostname <your_hostname> // in our case it is server1
  2. Edit /etc/hostname and change the content of it to <your_hostname>

Step 2: Installing Heart Beat and Apache2

After removing we need to install both heartbeat and apache again to both computers. We can do this by typing sudo (or w/o it) apt-get install apache2 heartbeat on the terminal.


Installing Heartbeat and Apache on Server1



Installing on Server2
     After installing. We configure the index.html in both servers to identify which server is which.  We can do this by editing index.html in the www where index.html is the default file opened when we access the servers. Afterwards we restart apache.

     It seemed awkward to me because if the goal of the exercise is to fetch the data if server1 died out. Then why is it that the returned html file if server1 died out is not the html file of server1 instead it is the html file of server2. I think this can be answered by a principle in DBMS, maybe server1 and server2 are connected to a remote server thus serving same file. We only show different kind of html to demonstrate that server2 catches the requests if server1 dies out.

Modifying index.html

Step 3: Configuring

  1. ha.cf
  2. haresources
  3. authkeys
After installing the needed tools, we will now proceed in configuring the setup of heartbeat.

1. ha.cf configuration

     We configure ha.cf in vi. We can do this by typing vi /etc/ha.d/ha.cf, type the necessary lines of codes shown in the picture below on both server 1 and 2. The lines here configures the needed configurations in order for the heartbeat to run.

Configuring ha.cf

2. haresources

    After configuring ha.cf we now configure haresources. This file tells us what the Virtual IP of the main server is and what server application it is using. In our case it is apache2. Do this for both server1 and 2
Configuring haresources

3. authkeys

   We now edit authkeys (or authentication keys in longer terms). This file is needed in order to ensure that the one accessing the server1 w/c is the backup server is the legit backup server. This file contains an encrypted password(in our case it is sha1, another example is md5). After that we need to set the permissions to 600 by typing chmod 600. This will ensure us that it can only be edited by our server.

Configuring authkeys

Step 4: Edit /etc/hosts

   In our previous exercises we already have configured this file. This file contains table with  a combination of IP and sitename of hosts. So we can route to them. We need to configure this in order for our server to establish connections.
Editing /etc/hosts

Step 5: crm configure edit

  After editing /etc/hosts we now proceed to editing our cluster resource manager. This crm is pre installed in heartbeat (I think?). The problem is whenever I tried to do this by typing crm configure edit it will return an error that it cannot be configured because line one of the XML file is not found. Me and my partner anaylzed the problem and have found out that even though the XML file is there in /etc/var/lib? (i forgot the whole path, but it is where the xml file is located) the XML file is there. This may have been caused that we need permissions( but remember I already typed sudo -s at the start, I even tried sudo crm configure edit but did it did not work). This is the part where I have reached in configuring the heartbeat setup. This is also the second last part of the exercise.

Step 6:   Restarting apache2 and heartbeat

   We need to restart heartbeat and apache2 in order to apply the changes we have made in the configuration. After this we should test if our setup works.


Questions:

1. What are the problems encountered?

One of the major problem encountered is that even if you purge the current configurations of heartbeat and apache. The configuration file is still present. So after you installed them again, the previous configurations still persists.

Another problem is that students forgot to clean up what they have done. It gives us a hard time to configure since initial or some configurations have been altered already and some can't be altered for some unknown reason and most of us in the lab cannot even successfully run the program even though we followed the step by step procedure.

2. What are your insights about HA-HB?

I think ha-hb concept is great, because a website needs to be up at all times. Like in the movie "The Social Network" Mark Zuckerberg states that facebook must not shutdown ever.That is how crucial website up time is and I think HA-HB is perfect for this task.

3. State your ideas about the possible application of HA-HB?

 Aside from facebook that I have mentioned earlier I think a potential application of HA-HB is in online banking, computer registration systems ( ie. Systemone, CRS of UPD)  or any site that performs transactions.

 4. What can you say about the mode of discussion?

I think it is good for the students to let them fend for themselves. With the theory given, they will learn more efficient because they are learning at their own pace. Although it is good I think they still need the supervision from their respective lab instructors just in case they suffer some problems that is not fully related or is out of scope of the exercise.



  

Tuesday, July 23, 2013

Linux Router and Protocol Analysis

This exercises focuses on establishing a connection on a remote computer using another computer to act as a router. To be able to perform this we need to follow the steps below.

A. Linux Router Configuration


Topology

We need to accomplish this topology but with minor variations. We will not use Cross cable in connecting Computer A and Computer B. Instead we will be using Wifi Connection to establish a network connection between A and B then use a cable directly connected to the internet.

In this exercise we used Ubuntu 12.04 to act as a server and a client. Then follow the steps below.

Step 1: We need to have a root access in order to modify the settings. Type sudo -s then enter your password.
Root Access

Step 2: Get the information on which devices your computer use that will be configured. In our case it is wlan0 and eth0. We will not be using eth1 since eth1 is used on a wired connection. On computer B eth0 is used in the wire directly connected to the internet while wlan0 is the connection between computer A and B.

Acquiring Device Information

Step 3 (Configuring the Router):

In this step we configured Computer B to act as a router for Computer A. We changed the IP address of wlan0 (the interface connected to Computer A) to 192.168.1.254 with a netmask of 255.255.255.0 . Then we checked if is Disabled. If disabled we set it to 1 to enable it. After checking the IP forwarding setting we now configure the Firewall settings using IPTABLES. The parameters used will be discussed later.

Configuring Computer B

Step 4 (Configuring the Client):

After configuring the router we now configure the client. First we assign the IP 192.168.1.1 to wlan0 (this is the interface of computer A connected to computer B). Afterwards we set the IP Address of Computer B as a default gateway using route.


Configuring the Client ( Computer A )
Now that we have configured computer A. We will try to ping the address 10.0.4.254 and 10.0.4.0.
Notice that this will result to a unreachable state because we have now changed the IP of Computer B to 192.168.1.254. Also the /etc/resolv.conf of computer A is empty. We need to copy the resolv.conf of computer B to A in order to have internet access. Resolv.conf contains a setting with nameserver and search. I think this is the default setup used by the network to connect to the internet.

Copying result.conf


Pinging Computer B
Since we have succesfully pinged our router Computer B. We are now sure that we can connect to the internet since computer B that is acting as a router has an internet access (As of this moment I'm currently using the connection from A to B to write this blog).


B. DHCP Server Configuration

In the previous activity we have successfully established a connection in Computer A manually. Now we will try the same but only using DHCP. This means that we will make a that will enable our router Computer B to assign IP addresses automatically to other computers that is connected to its network. We need to edit /etc/dhcp/dhcpd.conf in oreder to achieve this.

dhcpd.conf
The parameters used in dhcpd.conf will be discussed later. 

After we have configured dhcpd.conf we will now try to acquire IP of Computer A automatically by using dhclient wlan0 (since wlan0 is the one used by comptuer A to connect to computer B). Next we will check the information that Computer B gave to Computer A using cat /var/lib/dhcp/dhcpd.leases.

dhclient wlan0
Lease information
We have successfully assigned an automatic IP on computer A using dhclient 

QUESTIONS:


1. Using the man pages for iptables, briefly explain what was done in step 5 in configuring
Computer B. Describe the parameters used in the iptables command. (5 points)

Iptables -F = flush all the chains in the table if none is given, equivalent to deleting all the rules one by one

iptables -P  = set the policy for the chain to the given target.

Iptables -t = specifies the packet matching table which the command should operate on.

nat = table consulted when a packet that creates a new connection is encountered. 

2. What are the options you used in /etc/dhcpd.conf? (5 points)

We used router, broadcast-address, subnet-mask, domain-name-servers as options. We also added range (this is used if there are many computers connecting to the router), max-lease time and default lease time. Lease time is used in defining how long the computer can keep the connection established.

3. How do you assign a fixed IP address to a computer?What information do you need? (3 points)

ifconfig - we need the device to be used, the netmask and an optional broadcast.