Linux DRBD Setup

Posted on 9th January 2014 in Computer Tips, Linux OS

This tutorial will explain how to create a 2 node DRBD cluster, additional nodes can be added easily.

For the purpose of this tutorial (and because I believe it to be the easiest distribution) I will be using Ubuntu Server 12.04 LTS. This will work on other Linux distributions but this guide is written specifically for Ubuntu. This tutorial will assume you are using the root user.

For the purposes of this tutorial I will use the below IP config:
Server 1 (drbd01) = 192.168.0.111
Server 2 (drbd02) = 192.168.0.112

1. Install drbd and ocfs2 packages from respository using command ”apt-get install drbd8-utils ocfs2-tools”.

2. Edit “hosts” file (use “vim /etc/hosts” command), add the hostnames & ip addresses of all the drbd nodes

3. Create a resource file “{resource name}.res” file in “/etc/drbd.d/” directory (use “vim /etc/drbd.d/{resource name}.res” command) and populate with the below (feel free to edit as required). Please note anything between a set of *** are comments E.G. ***blah blah***

resource {resource name} { ***name the resource what you want, use the same as the filename***
protocol C;
startup {
wfc-timeout 15;
degr-wfc-timeout 60;
#become-primary-on both; ***allows drbd to go primary/primary on startup, un-comment if you want to use but it is recommended to get drbd setup and working fully first***
}

net {
cram-hmac-alg sha1;
shared-secret “secret”; ***set a password***
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;
allow-two-primaries; ***set this if you want to allow a primary/primary setup***
}

on drbd01 {
device /dev/drbd0; ***if using multiple resources change this as required***
disk /dev/sdb1; ***set the physical disk/partition to use for drbd***
address 192.168.0.111:7788;
meta-disk internal;
}

on drbd02 {
device /dev/drbd0; ***if using multiple resources change this as required***
disk /dev/sdb1; ***set the physical disk/partition to use for drbd***
address 192.168.0.112:7788;
meta-disk internal;
}
}

4. Copy the “{resource name}.res” file to other node(s) (use “scp /etc/drbd.d/{resource name}.res drbd02:/etc/drbd.d/” command)

5. Run the command “drbdadm create-md {resource name}” to initialize the meta data storage. This command should be ran on all nodes

6. Create a cluster.conf file in “/etc/ocfs2/” directory (use “vim /etc/ocfs2/cluster.conf” command) and populate with the below (feel free to edit as required). Please note anything between a set of *** are comments E.G. ***blah blah***

cluster:
node_count = 2 ***set number of nodes***
name = {cluster name} ***set required cluster name***

node:
ip_port = 7777
ip_address = 192.168.0.111
number = 1
name = drbd01
cluster = {cluster name}

node:
ip_port = 7777
ip_address = 192.168.0.112
number = 2
name = drbd02
cluster = {cluster name}

7. Start DRBD (use “service drbd start” command)

8. Copy the “cluster.conf” file to other node(s) (use “scp /etc/ocfs2/cluster.conf drbd02:/etc/ocfs2/” command)

9. Run the command “dpkg-reconfigure ocfs2-tools” and follow the screen prompts to configure OCFS2 & cluster

10. Run the command “drbdadm — –overwrite-data-of-peer primary {resource name}” to start the data sync. This command should be ran from drbd01 only. You can watch progress by running the command “watch drbd-overview”. To stop watching the output press Ctrl+C

11. Run the command “mkfs.ocfs2 /dev/drbd0″ on drbd01 to create the file system on the DRBD device

12. If required you can now un-comment the “become-primary-on both” line in the resource file to allow primary/primary on startup. Restarting DRBD will put both nodes into primary mode (“service drbd restart”)

13. You are now free to mount the DRBD device to wherever you want E.G. “mount /dev/drbd0 /srv”

14. If you want the DRBD device mounted automatically at boot then run “echo ‘/dev/drbd0 /srv ocfs2 _netdev,defaults 0 0′ >> /etc/fstab” to populate fstab (remember to change the mount point from “/srv” to whatever you want)

Thanks goes out to the below websites that I used to collect information:
Ubuntu Documentation for DRBD
Linbit DRBD User’s Guide

comments: 0 »

Linux LVS Load Balancer Setup

Posted on 21st February 2013 in Computer Tips, Linux OS

This tutorial will explain how to create a software load balancer using the Linux kernel, LVS load balancing.

For the purpose of this tutorial (and because I believe it to be the easiest distribution) I will be using Ubuntu Server 12.04 LTS. This will work on other Linux distributions but this guide is written specifically for Ubuntu. This tutorial will assume you are using the root user.

For the purposes of this tutorial I will use the below IP config:
VIP (Virtual IP, load balanced IP) = 192.168.0.110
RIP1 (Real IP 2, real server 1 IP) = 192.168.0.111
RIP2 (Real IP 2, real server 2 IP) = 192.168.0.112

1. Install keepalived package from respository using command ”apt-get install keepalived”.

3. Edit “sysctl.conf” file (use “vim  /etc/sysctl.conf” command), find “#net.ipv4.ip_forward = 1″ and remove the # (uncomment)

4. Run “sysctl -p” command to update sysctl

5. Edit “hosts” file (use “vim  /etc/hosts” command), add the hostnames & ip addresses of all load balancers and real servers

6. Set the loopback on all real servers to the VIP (see below for Windows loopback info)

7. Create a “keepalived.conf” file in “/etc/keepalived/” directory (use “vim /etc/keepalived/keepalived.conf” command) and populate with the below (feel free to edit as required). Please note anything between a set of *** are comments and must be removed before saving the file. E.G. ***blah blah***

vrrp_sync_group VG1 {
group {
VI_1
}
}

vrrp_instance VI_1 {
state MASTER ***Must be “BACKUP” on failover load balancer***
interface eth0
virtual_router_id 1
priority 100 ***Must be less than 100 on failover load balancer, 50 is best***
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.110
}
}
#Load Balance Port 80 – Standard Web Port
virtual_server 192.168.0.110 80 {
delay_loop 15
lb_algo wlc
lb_kind DR
persistence_timeout 50
protocol TCP

real_server 192.168.0.111 80 {
weight 100
TCP_CHECK {
connect_timeout 3
}
}

real_server 192.168.0.112 80 {
weight 100
TCP_CHECK {
connect_timeout 3
}
}
}

#Load Balance Port 443 – Standard SSL Web Port
virtual_server 192.168.0.110 443 {
delay_loop 15
lb_algo wlc
lb_kind DR
persistence_timeout 50
protocol TCP

real_server 192.168.0.111 443 {
weight 100
TCP_CHECK {
connect_timeout 3
}
}

real_server 192.168.0.112 443 {
weight 100
TCP_CHECK {
connect_timeout 3
}
}
}

8. Start keepalived on all load balancers using command “/etc/init.d/keepalived start”

 

You can then check the ipvsadm configuration and which load balancer has the VIP by using the below commands:
“ipvsadm”
“ipvsadm -lc”
“ip addr list” or “ip a s”

 

If you are load balancing a Windows server then you will need to do the following on the Windows real server:
1. Install the Windows Loopback and set IP to the VIP with a 255.255.255.255 subnet mask
2. Rename adapters to “lan” and “loopback” respectively
3. Run below commands in a command prompt:
netsh interface ipv4 set interface “lan” weakhostreceive=enabled
netsh interface ipv4 set interface “loopback” weakhostreceive=enabled
netsh interface ipv4 set interface “loopback” weakhostsend=enabled

 

Thanks goes out to the below websites that I used to collect information:
Ubuntu Manual for ipvsadm
gcharriere.com
www.linuxvirtualserver.org

comments: 0 »

Change User Password via Command Line

Posted on 26th December 2012 in Computer Tips, Windows OS

Open up a command line prompt (Run -> Cmd) and type the command “net user {username} {new password}”

You have to run the Command Line as Administrator (right click and “Run as Administrator”). Substitute {username} with the required username you wish to change and substitute {new password} with the password you want the user to be set to.

comments: 0 »