LVS - Load Balancing Detaied Tutorial - Step 3: MySql Cluster - DRBD - Web Installation
Next, we start last config: Mysql Clutering with DRBD
####################################################################################################
Step 3: MySQL cluster with Drbd and Heartbeat
Now, we have 4GB disks on both servers (db1 adn db2)
a.Partition Setup for Cluster Servers on both server:
Patition disks
# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
# fdisk /dev/sdb
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +2000M
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (245-522, default 245):
Using default value 245
Last cylinder or +size or +sizeM or +sizeK (245-522, default 522):
Using default value 522
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 8e Linux LVM
/dev/sdb2 245 522 2233035 83 Linux
Command (m for help): t
Selected partition 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 8e Linux LVM
/dev/sdb2 245 522 2233035 8e Linux LVM
Command (m for help): w
# partprobe
Create Physical Volume:
# pvcreat /dev/sdb1
Physical volume "/dev/sdb1" successfully created
# pvcreat /dev/sdb2
Physical volume "/dev/sdb2" successfully created
Create Volume Group:
# vgcreate vgdb /dev/sdb1 /dev/sdb2
Volume group "vgdb" successfully created
Create Logical volume partition:
#lvcreate -L +1000M -n /dev/vgdb/lvdb
Logical volume "lvdb" created
#lvcreate -L +256M -n /dev/vgdb/lvmeta
Logical volume "lvmeta" created
#lvdisplay | more
b. Install drbd and configure ( both servers)
Install:
#yum install -y drbd82 kmod-drbd82
Configuration:
#vim /etc/drbd.conf
global {
usage-count yes;
}common {
syncer { rate 10M; }
}resource r0 {
protocol C;
handlers {
pri-on-incon-degr "echo o > /proc/sysrq-trigger ; halt -f";
pri-lost-after-sb "echo o > /proc/sysrq-trigger ; halt -f";
local-io-error "echo o > /proc/sysrq-trigger ; halt -f";
outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater -t 5";
}startup {
}disk {
on-io-error detach;
}net {
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
}syncer {
rate 10M;
al-extents 257;
}on db1.hbn.local {
device /dev/drbd0;
disk /dev/vgdb/lvdb;
address 192.168.44.151:7788;
meta-disk /dev/vgdb/lvmeta[1];
}on db2.hbn.local {
device /dev/drbd0;
disk /dev/vgdb/lvdb;
address 192.168.44.152:7788;
meta-disk /dev/vgdb/lvmeta[1];
}}
save and quit
#scp /etc/drbd.conf db2:/etc/
#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
save & quit
# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
#scp /etc/sysctl.conf db2:/etc/
Load DRBD module both nodes:
# modprobe drbd
# echo "modprobe drbd" >> /etc/rc.local
##### run this on both servers ######
#drbdadm create-md r0
#drbdadm attach r0
#drbdadm syncer r0
#drbdadm connect r0
On Primary Node only
#drbdadm -- --overwrite-data-of-peer primary r0
On both Nodes:
#drbdadm up all
On Primary Node only
#drbdadm -- primary all
#watch cat /proc/drbd
On Primary Node only
#mkfs.ext3 /dev/drbd0
#mkdir /data/
#mount /dev/drbd0 /data/
df -h
# umount /dev/drbd0 /data
####### Secondry Node #######
#mkdir /data
b. Heartbeat:
\================
Install heartbeat package using yum
#yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-devel
#vim /etc/ha.d/ha.cf ## Create this file and copy this text ##
logfacility local0
keepalive 2#deadtime 30 # USE THIS!!!
deadtime 10
# we use two heartbeat links, eth2 and serial 0
bcast eth0#serial /dev/ttyS0
baud 19200
auto_failback off
node db1.hbn.local
node db2.hbn.local
#scp /etc/ha.d/ha.cf db2:/etc/ha.d/
On DB1:
#vim /etc/ha.d/haresources
db1.hbn.local IPaddr::192.168.44.150/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/data::ext3 mysqld
On DB2:
#vim /etc/ha.d/haresources
db2.hbn.local IPaddr::192.168.44.150/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/data::ext3 mysqld
Both Server:
#vim /etc/ha.d/authkeys
auth 3
3 md5 hbn
#scp /etc/ha.d/authkeys db2:/etc/ha.d/
#chmod 600 /etc/ha.d/authkeys
#chkconfig --level 235 heartbeat on
#chkconfig --level 35 mysqld off
c. MySql
Install:
#yum install -y mysql-server
Configurate:
#vim /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
datadir=/data/mysql#socket=/var/lib/mysql/mysql.sock
socket=/data/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid[mysql]
socket=/data/mysql/mysql.sock[client]
socket=/data/mysql/mysql.sock
#cd /data
#mkdir mysql
# mysqladmin -u root password 123456
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database joomla;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| joomla |
| mysql |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.44.131' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.44.132' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
Test on 2 web server:
#mysql -u root -p -h 192.168.44.150
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| joomla |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit;
Bye
####################################################################################################
Step 4: Install Joomla
Copy joomla code, extract it
#unzip Joomla_1.5.22-Stable-Full_Package.zip
#mkdir -p /var/www/html/web
#cp -r * /var/www/html/web/
#cd /var/www/html
#chown -R apache:apache web/
Install web:
Then:
#cd /var/www/html/web
# scp -r * www2:/var/www/html/web
Demo - Videos:
Part1:
Part2:
Part3:
Web Install:
Or:
Part1: http://www.mediafire.com/?bw372bdvcxb0n0d
Part2: http://www.mediafire.com/?6ul5qlw7jbz8yga
Part3: http://www.mediafire.com/?gp6j5junfjsyhv4
Web Install: http://www.mediafire.com/?cc8ahxy9ziih93h
------------------------------------------------------------
Thanks for reading
--------------------------------------------------------------------------
All my Lab:
Linux Lab -- window and Cisco Lab
to be continued - I will update more.
Nam Habach