Author Topic: drbd in debian option HA+NFS server work more !!!  (Read 13114 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
drbd in debian option HA+NFS server work more !!!
« on: มกราคม 23, 2011, 10:04:28 PM »
Lab by golfreeze

#Install DRBD+NFS+HA in debian4.0 R1(AMD64bit)

#ลง drbd ทั้งสองเครื่อง
# apt-get install drbd0.7-module-source
# apt-get install drbd0.7-utils
# apt-get install dpatch
# cd /usr/src
# tar -zxf drbd0.7.tar.gz
# cd /usr/src/modules/drbd
# module-assistant prepare
==press to intall module
# module-assistant automatic-install drbd0.7-module-source
ลง drbd0.7 module
# cd /usr/src
# dpkg -i drbd0.7-module-2.6.18-5-amd64_0.7.21-4+2.6.18.dfsg.1-13etch6_amd64.deb

##Config /etc/drbd.conf ทั้ง 2 เครื่อง
resource r0 {
protocol C;
incon-degr-cmd \"halt -f\";
startup {
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
}
net {
}
syncer {
rate 20M;
group 1;
al-extents 257;
}
on host-a {
device /dev/drbd0;
disk /dev/hda8;
address 10.0.0.10:7789;
meta-disk internal;
}
on host-b {
device /dev/drbd0; แทนdevice ที่จะทำการ mount เข้าเป็น device drbd
disk /dev/sda8; แทน disk ที่จะทำการ Mount เพื่อเก็บเป็น data file server
address 10.0.0.20:7789;
meta-disk /dev/sda7[0]; แทนdisk ที่เก็บ meta-disk ควรสร้างให้ 512M เพราะปกติมันเก็บ
256M
}
}

จัดการลบ fstab ของ /dev/sda8 และ /dev/sda7 ออกจาก /etc/fstab ด้วย ลบทั้ง 2 host เลย
#cp /etc/fstab /etc/fstab.ori
แล้ว umount ออกด้วยเพราะว่าเมื่อ start drbd แล้วมันจะ mount ให้เองอัตโนมัติ
#umount /dev/sda8
#umount /dev/sda7


สั่งให้ drbd ทำงานทั้ง 2 ตัว
# /etc/init.d/drbd start




สั่งให้ เครื่อง DRBD0 ทำงานเป็น \\\"Primary\\\" node ได้
# drbdadm primary all
# drbdsetup /dev/drbd0 primary --do-what-I-say
#modprobe drbd (ทั้งสองเครื่อง)

ทำการสร้าง partition ที่ primary node ที่เดียว
# mke2fs /dev/drbd0
# mkdir -p /mbox/export
# mount /dev/drbd0 /mbox/export
#df -h
แล้วลอง copy ข้อมูลใส่ดู
/dev/drbd0 44G 52M 41G 1% /mbox
#ทำการลง Heartbeat ทั้ง สองเครื่องดังนี้
#apt-get install heartbeat
เพิ่ม config เข้าไปให้ทั้ง สองเครื่อง

#vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug #เอาไว้ debug ดู error
logfile /var/log/ha-log
logfacility local0
keepalive 2
#deadtime 30 # USE THIS!!!
deadtime 10
#auto_failback on
bcast eth1 #card interface ไหนที่จะให้ใช้งาน
node DRBD0 DRBD1 #มี host อะไรบ้าง


#vi /etc/ha.d/haresources ทั้งสองเครื่องเหมือนกันเพราะ จะให้เครื่อง DRBD0 เป็น primary
DRBD0 IPaddr::10.0.1.169/23/eth1 drbddisk::r0 Filesystem::/dev/drbd0::/mbox::ext2
nfs-kernel-server


#vi /etc/ha.d/authkeys
auth 3
3 md5 kammatanmeditation
#chmod 600 authkeys



#/etc/init.d/heartbeat start
แล้วสั่ง #cat /proc/drbd ก็จะขึ้นแบบนี้ แปลว่าทำงานแล้วครับ
DRBD0:/home/golf# cat /proc/drbd
version: 0.7.21 (api:79/proto:74)
SVN Revision: 2326 build by root@DRBD0, 2008-01-16 01:50:05
0: cs:StandAlone strimary/Secondary ld:Consistent
ns:17 nr:0 dw:33 dr:807319 al:0 bm:492 lo:0 pe:0 ua:0 ap:0
ดู virtual-ip ที่ heartbeat สร้างขึ้นมาก็
#ip addr sh
3: eth1: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:14:5e:fb:fa:26 brd ff:ff:ff:ff:ff:ff
inet 10.0.1.154/23 brd 10.0.1.255 scope global eth1
inet 10.0.1.169/23 brd 10.0.1.255 scope global secondary eth1:0

----------------------------------------------------------------------------------------------------



----------------------------
ส่วนในการทำ test สำหรับ check ว่าข้อมูล sync กับเครื่อง slave หรือไม่โดยการถอดสายแลน เครื่อง master
ออกก่อน
แล้วก็ไปดูที่เครื่อง slave มันก็จะ take virtual ip ไปครับ

Check state ได้คือ
#drbdadm state all
ถ้าออกมาเป็น
Primary /secondary
ก็แสดงว่าเครื่องนั้นรันเป็น primary node อยู่

หรือจะดูเป็น real time คือ
#watch \"cat /proc/drbd\"
ก็ได้ครับ

เสร็จทำการลงเป็น nfs-kernel-server ทั้งสองเครื่อง
#apt-get install nfs-kernel-server

ทำการ ลบ init ของ nfs-kernel-server(ทั้งสองเครื่อง) ป้องกันการมีปัญหาในการ
รีสตาร์ตเครื่องแล้ว เกิด error
โดย
#update-rc.d -f nfs-kernel-server remove

เข้าไปแก้ config ของ nfs-kernel-server ที่
#vi /etc/exports
ครับ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #1 on: มกราคม 23, 2011, 10:04:39 PM »
ถ้า จะปรับ filesystem ให้เป็น ext3 ก็
#mke2fs -j /dev/xxx
แต่ถ้า ไม่ใส่ -j ก็จะเป็น ext2 ครับ

ลองดู น่ะครับ

มี tip ถ้าสมมติใครเป็น server ที่เก็บไฟล์มีไฟล์ จำนวนมากๆ และ disk ขนาดใหญ่มาก ใช้การเขียนไฟล์
อ่านไฟล์ เยอะ ควรเปลี่ยน file system มาเป็น แบบ reiserfs โดย ที่ debian จะมี program ที่ชื่อว่า
#apt-get install reiserfsprog ครับ
แล้วเวลา make reiser ก็
#mkreiserfs /dev/drbd0
ได้ครับ ซึ่งมีการทดสอบแล้ว ว่าความเร็วในการเข้าถึงไฟล์ แบบนี้จะไวกว่าพวก ext3 ext2 อย่างมาก


golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #3 on: มกราคม 23, 2011, 10:05:37 PM »
ถ้าเครื่อง slave reboot ไปแล้ว state มันไม่ขึ้น sync ก็สั่งโดย
#drbdadm disconnect all
แล้ว
#drbdadm connect all

น่ะครับ

#mysql ha drbd on centos
http://linuxsutra.chakravaka.com/index.php?op=ViewArticle&articleId=5

##drbd module for debian 5 (lenny)
http://packages.debian.org/lenny/drbd8-source

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #4 on: มกราคม 23, 2011, 10:05:47 PM »
เพิ่มเติม config drbd.conf ของผมทั้งสองเครื่อง

โดยที่ xx00 , xx01 คือชื่อ host ของ server ครับ

==========================================
global { minor-count 1; }

resource r1 {
protocol C;
net {
shared-secret "xxxmail";
}
syncer {
rate 12M;
}

on xx00 {
device /dev/drbd0;
disk /dev/sdb1;
address 111.111.12.1:7788;
meta-disk /dev/sdb2[0];
}

on xx01 {
device /dev/drbd0;
disk /dev/sdb1;
address 111.111.12.3:7788;
meta-disk /dev/sdb2[0];
}
}
=============================================

ส่วนการลง app ดูได้จาก link ข้างล่างครับ

apt-get install make gcc libc6 flex linux-headers-`uname -r` libc6-dev linux-kernel-headers

cd /usr/src/
wgethttp://oss.linbit.com/drbd/8.3/drbd-8.3.0.tar.gz

tar -xzvf drbd-8.3.0.tar.gz
cd /usr/src/drbd-8.3.0/
make clean all
make install

modprobe drbd
cat /proc/drbd

ขั้นต่อไปทำการเตรียม drbd config (ทำเหมือนกันทั้งสองเครื่อง xx00,xx01)

xx00# drbdadm create-md r1
ถ้ามี error เกิดขึ้น
================================================
md_offset 597994237952
al_offset 597994205184
bm_offset 597975953408

Found ext3 filesystem which uses 583978752 kB
current configuration leaves usable 583960892 kB

Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
* use external meta data (recommended)
* shrink that filesystem first
* zero out the device (destroy the filesystem)
Operation refused.

Command 'drbdmeta /dev/drbd0 v08 /dev/sdb5 internal create-md' terminated with exit code 40
drbdadm create-md r1: exited with code 40
ให้ไปดู comment ที่ 8 ครับ
================================================

xx00# /etc/init.d/drbd start

xx01# drbdadm create-md r1
xx01# /etc/init.d/drbd start

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #5 on: มกราคม 23, 2011, 10:06:00 PM »
ช่วงนี้ได้ลองใช้ DRBD 8.3 ครับ กับตัว Debian 5.03 มา

ตั้งแต่ตอนลงก็ไม่ติดปัญหาอะไรจน มาเจอเกือบจะท้ายสุด create meta disk ไม่ได้ครับ ก็แก้ไขโดย


##Run fdisk to use /mbox and /meta on sdb HDD

#fdisk /dev/sdb

> d (delete all path)
>n (create new partition)
>p (primary)
>1
input (1-71500 cys) for sdb1 (mbox)
input (71501-end cys) for sdb2 (meta)

##Format to ext3 file system
#mkfs.ext3 /dev/sdb2

##create label
#e2label /dev/sdb2 /meta


####Then use this command to zero out path sdb2 (meta)
#dd if=/dev/zero of=/dev/sdb2 bs=1M count=128

###format device drbd0
#mkfs.ext3 /dev/drbd0

#modprobe drbd
#/etc/init.d/drbd restart


####Then create-md in drbdadm
#drbdadm create-md all
set priviledges to primary node only
#drbdadm -- --overwrite-data-of-peer primary all
#drbdadm attach r1
#drbdadm syncer r1
#drbdadm connect all
#mount /dev/drbd0 /mbox

#cat /proc/drbd

####Do same as server02
#drbdadm create-md all

####Then use this command to zero out path sdb2 (meta)
#dd if=/dev/zero of=/dev/sdb2 bs=1M count=128

###check status by
#cat /proc/drbd

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #6 on: มกราคม 23, 2011, 10:06:11 PM »
ขั้นตอนต่อไปมาทำ การ sync data กันก่อนระหว่าง xx00 กับ xx01

สั่งให้ xx00 ทำงานเป็น primary , xx01 ทำงานเป็น secondary ครับ

xx00#drbdadm -- --overwrite-data-of-peer primary r1

แนะนำให้ ใช้ ตัว screen ช่วยกันหลุดจาก session ครับ
xx00#screen

ทำการ ดูว่ามัน sync กันถึงไหนแล้ว
xx00#watch -n 1 'cat /proc/drbd'

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #7 on: มกราคม 23, 2011, 10:06:21 PM »
ในกรณีถ้า ลองเช๊ค

#cat /proc/drbd

แล้วเครื่อง master ขึ้นเป็นแบบนี้

xx00:/etc/postfix# cat /proc/drbd
version: 8.0.14 (api:86/proto:86)
GIT-hash: bb447522fc9a87d0069b7e14f0234911ebdab0f7 build by phil@fat-tyre, 2008-11-12 16:40:33
0: cs:WFConnection strimary/Unknown ds:UpToDate/DUnknown C r---
ns:78396 nr:24 dw:78472 dr:1556 al:38 bm:23 lo:0 pe:0 ua:0 ap:0
resync: used:0/61 hits:0 misses:0 starving:0 dirty:0 changed:0
act_log: used:0/127 hits:19574 misses:38 starving:0 dirty:0 changed:38

============================================
ดูตรง cs:WFConnection ใน pop00 ถ้าขึ้นอย่างนี้ ให้สั่ง sync ที่เครื่อง pop01 โดย
pop01#modprobe drbd
pop01#drbdadm connect all

ก็จะขึ้นเป็น cs:Connected แล้ว status จะเป็น Primary / Secondary ครับ

==============================================

ถ้าขึ้น cs:Standalone ที่เครื่อง pop00
ไม่ว่าจะ สั่ง command
pop00#drbdadm connect all
แล้วก็ยังไม่ connect กัน
ให้ทำการ check authkeys ว่าตรงกันหรือไม่
เสร็จแล้วสั่ง restart pop00 แล้วอีกแป๊บให้ restart pop01 ไปด้วยเลย
เมื่อ pop00 up ขึ้นมาจะแสดง status เป็น
cs:WFConnection strimary/Unknown
ก็ทำตามข้างล่าง นี่ได้เลย
============================================
แสดงว่า เครื่อง ที่ทำงานเป็น slave server (node = xx01)
ยังไม่ได้สั่งให้ connect กับ ตัว master ซึ่งจะขึ้นเป็น status
\\\"Unknown\\\"
ส่วนตัว (xx01
เป็น primary แล้ว) ให้จัดการ ที่เครื่อง xx01 โดย
xx01#modprobe drbd
xx01#drbdadm connect all

xx01#cat /proc/drbd

xx01:/home/golf# cat /proc/drbd
version: 8.3.0 (api:88/proto:86-89)
GIT-hash: 9ba8b93e24d842f0dd3fb1f9b90e8348ddb95829 build by root@pop01, 2009-10-26 15:47:27
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r---
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

แล้วสั่ง

xx01#/etc/init.d/heartbeat restart

ก็จะสามารถ ทำการ sync ได้ปกติครับ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #8 on: มกราคม 24, 2011, 12:03:05 PM »
apt-get install mysql-server mysql-client build-essential

Make sure that mysql will be started by heartbeat, not at boot-time on either server.

update-rc.d -f mysql remove

Verify the partitions we are using are exactly the same on both servers. We will be using sda6
(256MB) and sda7(94GB): Actual partitions should be something like this:

fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 24 192748+ 83 Linux
/dev/sda2 25 1969 15623212+ 82 Linux swap / Solaris
/dev/sda3 1970 19320 139371907+ 5 Extended
/dev/sda5 1970 6954 40041981 83 Linux
/dev/sda6 6955 6984 240943+ 83 Linux
/dev/sda7 6985 19320 99088888+ 83 Linux

sda6 will be our meta-disk sda7 will be our distributed replication block device Verify that sda6
and sda7 are not mounted:

mount -l

/dev/sda5 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
procbususb on /proc/bus/usb type usbfs (rw)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)

Determine the kernel in use to install headers:

uname -r
apt-get install linux-headers-<<what was returned above>>

ETH0 will be the public interface on 10.10.10.XXX, while ETH1 will be on 192.168.1.xxx, a separate
network or crossover cable connected between the two machines. DRBD will run using eth1 of both
machines. On both servers, perform the following:

apt-get install drbd0.7-module-source drbd0.7-utils ipvsadm heartbeat
cd /usr/src/
tar xvfz drbd0.7.tar.gz
cd modules/drbd/drbd
make
make install
mv /etc/drbd.conf /etc/drbd.conf.sample

Edit /etc/drbd.conf and create the following contents:

resource r0 {
protocol C;
incon-degr-cmd "halt -f";
startup {
degr-wfc-timeout 120; # 2 minutes.
}
disk {
on-io-error detach;
}
net {
}
syncer {
rate 10M;
group 1;
al-extents 257;
}
on mysqldb01 { # the hostname of server 1 (uname -n)
device /dev/drbd0; #
disk /dev/sda7; # data partition on server 1
address 192.168.1.10:7788; # ETH1 IP Address
meta-disk /dev/sda6[0]; # 256MB partition for DRBD on server 1
}
on mysqldb02 { # ** EDIT ** the hostname of server 2 (uname -n)
device /dev/drbd0; #
disk /dev/sda7; # ** EDIT ** data partition on server 2
address 192.168.1.11:7788; # ETH1 IP Address
meta-disk /dev/sda6[0]; # 256MB partition for DRBD on server 2
}
}

Start drbd on both servers

/etc/init.d/drbd start

Verify they are running. Both should be in a secondary state.

cat /proc/drbd
version: 0.7.24 (api:79/proto:74)
SVN Revision: 2875 build by root@mysqldb01, 2007-12-14 02:55:51
0: cs:Connected st:Secondary/Secondary ld:Inconsistent
ns:0 nr:0 dw:0 dr:0 al:0 bm:12096 lo:0 pe:0 ua:0 ap:0
1: cs:Unconfigured

Make server1 the primary and format the the device. You want to format the drbd device, not the sda
device. The server you are formatting must be the primary. You cannot format the drbd device if it
is in secondary mode. There is no need to perform the format operation on the secondary as it will
be sync'd as well.

drbdsetup /dev/drbd0 primary --do-what-I-say
mkfs.ext3 /dev/drbd0
drbdadm connect all

Verify that they are now sync'ing

watch cat /proc/drbd

version: 0.7.24 (api:79/proto:74)
SVN Revision: 2875 build by root@mysqldb01, 2007-12-14 02:55:51
0: cs:SyncTarget st:Secondary/Primary ld:Inconsistent
ns:0 nr:9660908 dw:9660908 dr:0 al:0 bm:12685 lo:0 pe:0 ua:0 ap:0
[=>..................] sync'ed: 9.5% (87332/96415)M
finish: 1:54:03 speed: 12,968 (10,140) K/sec
1: cs:Unconfigured

Next, setup the mysql datafiles on the drbd device. Stop mysql on both servers

/etc/init.d/mysql stop


Move the mysql data files and test mounting on mysqldb01

mkdir /mnt/move
mount -t ext3 /dev/drbd0 /mnt/move
mv /var/lib/mysql/* /mnt/move/.
umount /mnt/move
mount -t ext3 /dev/drbd0 /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql


Clear databases from mysqldb02 so we can be sure we're starting from the proper set.

rm -R /var/lib/myssql/*


Start Mysql on mysqldb01 and verify that you can connect

/etc/init.d/mysql start
mysql -u root -p

Test drive MySQL on mysqldb01 a little bit, create a new database and a table in the database. The
following is the basic process to manually switch from the primary server to the secondary. We will
use it to verify everything is working as expected before proceeding to the heartbeat. Stop MySQL on
mysqldb01 and unmount drbd0

/etc/init.d/mysql stop
umount /var/lib/mysql
drbdadm secondary r0

On mysqldb02, make it the primary, mount the drbd and then start mysql

drbdadm primary r0
mount -t ext3 /dev/drbd0 /var/lib/mysql
ls /var/lib/mysql
/etc/init.d/mysql start

On mysqldb02, login to mysql and verify that the database and table we created exists. Create some
new records in our test table.

mysql -u root -p

If everything is working as planned, stop mysql on mysqldb02, unmount the drbd and switch the
services back to mysqldb01 to verify that works. On mysqldb02:

/etc/init.d/mysql stop
umound /var/lib/mysql
drbdadm secondary r0

On mysqldb01

drbdadm primary r0
mount -t ext3 /dev/drbd0 /var/lib/mysql
/etc/init.d/mysql start

Test connecting to Mysql as we did before. Verify any changes you made on mysqldb02 exist on
mysqldb01. This will be a good time to set a root password since the server won't be listening on
localhost any longer:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'some_pass' WITH GRANT
OPTION;
FLUSH PRIVILEGES;

Edit the /etc/mysql/my.cnf file and change the IP address of the "bind-address"
setting to be that which we will use for the heartbeat. Now, since the heartbeat will control both
drbd and MySQL, stop MySQL and unmount the drbd

/etc/init.d/mysql stop
umount /var/lib/mysql

Create entries in /etc/hosts for the two servers which will be in the cluster. Use the ip address
which is bound to the public interface (eth0) which the heartbeat will use.

Create the /etc/ha.d/ha.cf file on both servers as follows:

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth0
auto_failback on
node mysqldb01 ## make sure both names are accessible - check /etc/hosts
node mysqldb02
ping 10.10.10.1 ## ETH0, public network
apiauth ipfail gid=haclient uid=hacluster

Create the /etc/ha.d/haresources. This file is the same on both servers. It lists the primary
servername, tells it to use LVS, sets the IP address of the heartbeat, the drbddisk name from
/etc/drbd.conf, the drbd device name and mount point and finally the server to start.

mysqldb01 LVSSyncDaemonSwap::master IPaddr::10.10.10.12/24/eth0 drbddisk::r0
Filesystem::/dev/drbd0::/var/lib/mysql::ext3 mysql

Create authkeys on both servers in /etc/ha.d/authkeys. Heartbeat will complain if you don't
secure the file.

auth 3
3 md5 plaintextpassword

chmod 600 /etc/ha.d/authkeys

Start heartbeat on both servers, starting with mysqldb01:

/etc/init.d/heartbeat start

Errors will be in /var/log/ha-debug and /var/log/ha-log if you have problems. You should now be able
to connect to mysql on the heartbeat's ip address. Shutdown heartbeat on mysqldb01, and you
should notice that /var/lib/mysql is now mounted on mysqldb02 and you can still connect to the
database.

Upgrading Mysql with DRBD and Heartbeat

After recently running into the dilemma of how to upgrade something that doesn't like you to shut
it down, I've resolved it thus: First, upgrade the secondary database server. The MySQL upgrade
will actually fail since Debian cannot start and stop a database that isn't running and whose
file storage isn't mounted. After the secondary is mounted, commence to upgrading the primary.
The data files will now be upgraded, and the database shouldn't be down long enough to create a
fail over on the heartbeat while the containers are upgraded.


References:

http://www.howtoforge.com/high_availability_nfs_drbd_heartbeat_p2
http://linuxsutra.blogspot.com/2007/02/howto-mysql-drbd-ha.html
http://marksitblog.blogspot.com/2007/07/mysql-5-high-availability-with-drbd-8.html
http://blog.irwan.name/?p=118

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: drbd in debian option HA+NFS server work more !!!
« Reply #9 on: มกราคม 24, 2011, 01:34:07 PM »
Lab by golfreeze

#Install DRBD+NFS+HA in debian4.0 R1(AMD64bit)

#ลง drbd ทั้งสองเครื่อง
# apt-get install drbd0.7-module-source
# apt-get install drbd0.7-utils
# apt-get install dpatch
# cd /usr/src
# tar -zxf drbd0.7.tar.gz
# cd /usr/src/modules/drbd
# module-assistant prepare
==press to intall module
# module-assistant automatic-install drbd0.7-module-source
ลง drbd0.7 module
# cd /usr/src
# dpkg -i drbd0.7-module-2.6.18-5-amd64_0.7.21-4+2.6.18.dfsg.1-13etch6_amd64.deb

##Config /etc/drbd.conf ทั้ง 2 เครื่อง
resource drbd-resource-0 {
protocol C;
incon-degr-cmd "halt -f"; # killall heartbeat would be a good alternative :->
disk {
on-io-error panic;
}
syncer {
rate 10M; # Note: 'M' is MegaBytes, not MegaBits
}
on host-a {
device /dev/drbd0;
disk /dev/hda8;
address 10.0.0.10:7789;
meta-disk internal;
}
on host-b {
device /dev/drbd0;   แทนdevice ที่จะทำการ mount เข้าเป็น device drbd
disk /dev/sda8; แทน disk ที่จะทำการ Mount เพื่อเก็บเป็น data file server
address 10.0.0.20:7789;
meta-disk /dev/sda7[0]; แทนdisk ที่เก็บ meta-disk ควรสร้างให้ 512M เพราะปกติมันเก็บ
256M
}
}

จัดการลบ fstab ของ /dev/sda8 และ /dev/sda7 ออกจาก /etc/fstab ด้วย ลบทั้ง 2 host เลย
#cp /etc/fstab /etc/fstab.ori
แล้ว umount ออกด้วยเพราะว่าเมื่อ start drbd แล้วมันจะ mount ให้เองอัตโนมัติ
#umount /dev/sda8
#umount /dev/sda7


สั่งให้ drbd ทำงานทั้ง 2 ตัว
# /etc/init.d/drbd start




สั่งให้ เครื่อง DRBD0 ทำงานเป็น "Primary" node ได้
# drbdadm primary all
# drbdsetup /dev/drbd0 primary --do-what-I-say


ทำการสร้าง partition ที่ primary node ที่เดียว
# mke2fs /dev/drbd0
# mkdir -p /mbox/export
# mount /dev/drbd0 /mbox/export
#df -h
แล้วลอง copy ข้อมูลใส่ดู
/dev/drbd0             44G   52M   41G   1% /mbox
#ทำการลง Heartbeat ทั้ง สองเครื่องดังนี้
#apt-get install heartbeat
เพิ่ม config เข้าไปให้ทั้ง สองเครื่อง

#vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug     #เอาไว้ debug ดู error
logfile /var/log/ha-log
logfacility     local0
keepalive       2
#deadtime       30      # USE THIS!!!
deadtime        10
#auto_failback on
bcast           eth1         #card interface ไหนที่จะให้ใช้งาน
node            DRBD0 DRBD1   #มี host อะไรบ้าง


#vi /etc/ha.d/haresources     ทั้งสองเครื่องเหมือนกันเพราะ จะให้เครื่อง DRBD0 เป็น primary
DRBD0  IPaddr::10.0.1.169/23/eth1 drbddisk::r0 Filesystem::/dev/drbd0::/mbox::ext2 nfs-kernel-server


#vi /etc/ha.d/authkeys
auth 3
3 md5 kammatanmeditation
#chmod 600 authkeys


#/etc/init.d/heartbeat start
แล้วสั่ง #cat /proc/drbd ก็จะขึ้นแบบนี้ แปลว่าทำงานแล้วครับ
DRBD0:/home/golf# cat /proc/drbd
version: 0.7.21 (api:79/proto:74)
SVN Revision: 2326 build by root@DRBD0, 2008-01-16 01:50:05
 0: cs:StandAlone st:Primary/Secondary ld:Consistent
    ns:17 nr:0 dw:33 dr:807319 al:0 bm:492 lo:0 pe:0 ua:0 ap:0
ดู virtual-ip ที่ heartbeat สร้างขึ้นมาก็
#ip addr sh
3: eth1: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:14:5e:fb:fa:26 brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.154/23 brd 10.0.1.255 scope global eth1
    inet 10.0.1.169/23 brd 10.0.1.255 scope global secondary eth1:0

--------------------------------------------------------------------------------------------------------------------------------
ส่วนในการทำ test สำหรับ check ว่าข้อมูล sync กับเครื่อง slave หรือไม่โดยการถอดสายแลน เครื่อง master ออกก่อน
แล้วก็ไปดูที่เครื่อง slave มันก็จะ take virtual ip ไปครับ

Check state ได้คือ
#drbdadm state all
ถ้าออกมาเป็น
Primary /secondary
ก็แสดงว่าเครื่องนั้นรันเป็น primary node อยู่


Lab by golfreeze

#Install DRBD+NFS+HA in debian4.0 R1(AMD64bit)

#ลง drbd ทั้งสองเครื่อง
# apt-get install drbd0.7-module-source
# apt-get install drbd0.7-utils
# apt-get install dpatch
# cd /usr/src
# tar -zxf drbd0.7.tar.gz
# cd /usr/src/modules/drbd
# module-assistant prepare
==press to intall module
# module-assistant automatic-install drbd0.7-module-source
ลง drbd0.7 module
# cd /usr/src
# dpkg -i drbd0.7-module-2.6.18-5-amd64_0.7.21-4+2.6.18.dfsg.1-13etch6_amd64.deb

##Config /etc/drbd.conf ทั้ง 2 เครื่อง
resource drbd-resource-0 {
protocol C;
incon-degr-cmd "halt -f"; # killall heartbeat would be a good alternative :->
disk {
on-io-error panic;
}
syncer {
rate 10M; # Note: 'M' is MegaBytes, not MegaBits
}
on host-a {
device /dev/drbd0;
disk /dev/hda8;
address 10.0.0.10:7789;
meta-disk internal;
}
on host-b {
device /dev/drbd0; แทนdevice ที่จะทำการ mount เข้าเป็น device drbd
disk /dev/sda8; แทน disk ที่จะทำการ Mount เพื่อเก็บเป็น data file server
address 10.0.0.20:7789;
meta-disk /dev/sda7[0]; แทนdisk ที่เก็บ meta-disk ควรสร้างให้ 512M เพราะปกติมันเก็บ
256M
}
}

จัดการลบ fstab ของ /dev/sda8 และ /dev/sda7 ออกจาก /etc/fstab ด้วย ลบทั้ง 2 host เลย
#cp /etc/fstab /etc/fstab.ori
แล้ว umount ออกด้วยเพราะว่าเมื่อ start drbd แล้วมันจะ mount ให้เองอัตโนมัติ
#umount /dev/sda8
#umount /dev/sda7


สั่งให้ drbd ทำงานทั้ง 2 ตัว
# /etc/init.d/drbd start




สั่งให้ เครื่อง DRBD0 ทำงานเป็น "Primary" node ได้
# drbdadm primary all
# drbdsetup /dev/drbd0 primary --do-what-I-say


ทำการสร้าง partition ที่ primary node ที่เดียว
# mke2fs /dev/drbd0
# mkdir -p /mbox/export
# mount /dev/drbd0 /mbox/export
#df -h
แล้วลอง copy ข้อมูลใส่ดู
/dev/drbd0 44G 52M 41G 1% /mbox
#ทำการลง Heartbeat ทั้ง สองเครื่องดังนี้
#apt-get install heartbeat
เพิ่ม config เข้าไปให้ทั้ง สองเครื่อง

#vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug #เอาไว้ debug ดู error
logfile /var/log/ha-log
logfacility local0
keepalive 2
#deadtime 30 # USE THIS!!!
deadtime 10
#auto_failback on
bcast eth1 #card interface ไหนที่จะให้ใช้งาน
node DRBD0 DRBD1 #มี host อะไรบ้าง


#vi /etc/ha.d/haresources ทั้งสองเครื่องเหมือนกันเพราะ จะให้เครื่อง DRBD0 เป็น primary
DRBD0 IPaddr::10.0.1.169/23/eth1 drbddisk::r0 Filesystem::/dev/drbd0::/mbox::ext2
nfs-kernel-server


#vi /etc/ha.d/authkeys
auth 3
3 md5 kammatanmeditation
#chmod 600 authkeys


#/etc/init.d/heartbeat start
แล้วสั่ง #cat /proc/drbd ก็จะขึ้นแบบนี้ แปลว่าทำงานแล้วครับ
DRBD0:/home/golf# cat /proc/drbd
version: 0.7.21 (api:79/proto:74)
SVN Revision: 2326 build by root@DRBD0, 2008-01-16 01:50:05
0: cs:StandAlone st rimary/Secondary ld:Consistent
ns:17 nr:0 dw:33 dr:807319 al:0 bm:492 lo:0 pe:0 ua:0 ap:0
ดู virtual-ip ที่ heartbeat สร้างขึ้นมาก็
#ip addr sh
3: eth1: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:14:5e:fb:fa:26 brd ff:ff:ff:ff:ff:ff
inet 10.0.1.154/23 brd 10.0.1.255 scope global eth1
inet 10.0.1.169/23 brd 10.0.1.255 scope global secondary eth1:0

----------------------------------------------------------------------------------------------------
----------------------------
ส่วนในการทำ test สำหรับ check ว่าข้อมูล sync กับเครื่อง slave หรือไม่โดยการถอดสายแลน เครื่อง master
ออกก่อน
แล้วก็ไปดูที่เครื่อง slave มันก็จะ take virtual ip ไปครับ

Check state ได้คือ
#drbdadm state all
ถ้าออกมาเป็น
Primary /secondary
ก็แสดงว่าเครื่องนั้นรันเป็น primary node อยู่
Post by : golfreeze [2008-01-18 12:23:37] mail not show


Comment : 1
ถ้า จะปรับ filesystem ให้เป็น ext3 ก็
#mke2fs -j /dev/xxx
แต่ถ้า ไม่ใส่ -j ก็จะเป็น ext2 ครับ

ลองดู น่ะครับ