Sunday, April 4, 2010

DRBD Server with OpenVZ

Installing DRBD with OpenVZ (CentOS 5.3) by 林观生

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

20GB for /

40GB for /vz

260GB for drbd device -> don’t do anything just put as a software raid.



Install CentOS 5.3 as an usual

turn off the iptables and selinux

#turn off firewall

chkconfig iptables off



#update the OS

yum -y update



#restart first so will bootup wih the kernel if they have kernel update

shutdown -r now



#crontab

yum -y install vixie-cron ntp

/usr/sbin/ntpdate sg.pool.ntp.org

crontab -e

30 03 * * * /usr/sbin/ntpdate sg.pool.ntp.org



#OpenVZ

cd /etc/yum.repos.d

wget http://download.openvz.org/openvz.repo

rpm —import http://download.openvz.org/RPM-GPG-Key-OpenVZ

yum search ovzkernel

yum install ovzkernel.i686

yum install ovzkernel-devel.i686





vi /boot/grub/grub.conf (Edit File)

—-



default 0



title OpenVZ (See Kernel which countain stab)




—-



vi /etc/sysctl.conf (Edit File)

—-

# packet forwarding enabled and proxy arp disabled

net.ipv4.ipforward = 1

net.ipv4.conf.default.proxyarp = 0





# Controls source route verification

net.ipv4.conf.default.rpfilter = 1




# Do not accept source routing

net.ipv4.conf.default.acceptsourceroute = 0




# Controls the System Request debugging functionality of the kernel

kernel.sysrq = 1




# we do not want all our interfaces to send redirects

net.ipv4.conf.default.sendredirects = 1


net.ipv4.conf.all.sendredirects = 0




# Controls whether core dumps will append the PID to the core filename.

# Useful for debugging multi-threaded applications.

kernel.coreusespid = 1

—-



yum -y install vzctl vzquota



Reboot the machine, use the new kernel (Contain OpenVZ)

shutdown -r now





vi /etc/fstab






/dev/md1 /vz.orig ext3 defaults 1 2







Install HeartBeat

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

yum search heartbeat

yum -y install heartbeat.i386 heartbeat-devel.i386

yum -y install heartbeat



Create 3 files on both side

—————————————————————————————-



1)vi ha.cf (Create File)

—————-

logfile /var/log/ha-log

logfacility local0

uselogd yes


node server1

node server2

keepalive 2

deadtime 10

initdead 120

udpport 694

bcast eth1

autofailback yes

respawn hacluster /usr/lib/heartbeat/ipfail

—————-



2)vi haresources (Create File

————————-

server1 192.168.1.155 \

drbddisk::r0 Filesystem::/dev/drbd0::/vz::ext3 \

openvz

————————-



3) vi authkeys (Create File)

—————-

auth 1

1 crc

—————-



chmod 600 /etc/ha.d/authkeys



/etc/init.d/heartbeat start



#put as the startup

chkconfig —add heartbeat

chkconfig heartbeat on

chkconfig —list | grep ‘heartbeat’



++++++++++++++++++++++++++++++++

heartbeat 0:off 1:off 2:on 3:on 4:on 5:on 6:off

++++++++++++++++++++++++++++++++



#Do ifconfig command should be show like this

….

eth0:0 Link encap:Ethernet HWaddr 00:1A:92:1C:C4:E8

inet addr:192.168.1.199 Bcast:192.168.1.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Interrupt:169

…..



#Turn down one machine make it sure the floating IP is moved.





Install DRBD

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

search DRBD Pakcage

yum search drbd



#If you want configure the kernel header manual don’t install the kmod

yum -y install drbd82.i686 kmod-drbd82.i686



#restart the machine

shutdown -r now



mdadm —create -l 1 -n 2 /dev/md2 /dev/sda3 /dev/sdb3



vi /etc/drbd.conf (Edit File)



—————————————————————————————————————

global {

usage-count yes;

}

common {

protocol C;

syncer { rate 100M; } --> Put in this rate or it will take quite long time.

}

resource r0 {

device /dev/drbd0;

disk /dev/md2;

meta-disk internal;

on server1 {

address 15.5.19.87:7789;

}

on server2 {

address 15.5.19.88:7789;

}

}

——————————————————————————————————————



#add DRBD to metadata

drbdadm create-md r0

drbdadm attach r0

drbdadm syncer r0

drbdadm connect r0

cat /proc/drbd



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

+version: 8.2.6 (api:88/proto:86-88) ++GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by pavel@xemulnb.sw.ru, 2008-09-30 17:46:13 ++ 0: cs:Connected st:Primary/Secondary ds:Inconsistent/Inconsistent C r—- ++ ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 oos:0 +

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

#do this on your primary machine (Master)

drbdadm — —overwrite-data-of-peer primary r0



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

|version: 8.2.6 (api:88/proto:86-88) ||GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by pavel@xemulnb.sw.ru, 2008-09-30 17:46:13 || 0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r—- || ns:0 nr:75266976 dw:75259232 dr:0 al:0 bm:4592 lo:243 pe:472 ua:242 ap:0 oos:170495532 || [=====>…………..] sync’ed: 30.7% (166499/239994)M || finish: 0:35:38 speed: 79,604 (58,520) K/sec |

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++





Configure DRBD that it can works with OpenVZ

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

#turn off the VZ service —> will be turn it on bt the script

chkconfig vz off



/etc/init.d/drbd status



#make sure the drbd drive mounted to vz directory.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

|version: 8.2.6 (api:88/proto:86-88) || GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by pavel@xemulnb.sw.ru, 2008-09-30 17:46:13 ||m:res cs st ds p mounted fstype ||0:r0 Connected Primary/Secondary UpToDate/UpToDate C /vz ext3 |

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



mv /etc/vz /etc/vz.orig

mv /etc/sysconfig/vz-scripts /etc/sysconfig/vz-scripts.orig

mv /var/vzquota /var/vzquota.orig

ln -s /vz/cluster/etc/vz /etc/vz

ln -s /vz/cluster/etc/sysconfig/vz-scripts /etc/sysconfig/vz-scripts

ln -s /vz/cluster/var/vzquota /var/vzquota



#do this only in primary

cp -a /vz.orig/* /vz/

mkdir -p /vz/cluster/etc

mkdir -p /vz/cluster/etc/sysconfig

mkdir -p /vz/cluster/var

cp -a /etc/vz.orig /vz/cluster/etc/vz/

cp -a /etc/sysconfig/vz-scripts.orig /vz/cluster/etc/sysconfig/vz-scripts

cp -a /var/vzquota.orig /vz/cluster/var/vzquota



#do this on both side



mkdir /root/live-switchover

ln -s /root/live-switchover/openvz /etc/init.d/



#Copy the 4 script to /root/live-switchover & put chmod 755 to all files.



restart the machine



^
^ DRBD works…



Install OpenVZ

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

vzsplit -n 1 -f vps.1

cd /vz/template/cache/

wget http://download.openvz.org/contrib/template/precreated/centos-5-i386-default.tar.gz



vzctl create 1001 —ostemplate centos-5-i386-default —config vps.1

vzctl set 1001 —onboot yes —save

vzctl set 1001 —hostname server11.netdns.net —save

vzctl set 1001 —ipadd 20x.xxx.xxx.xxx —save

vzctl set 1001 —nameserver 208.67.220.220 —save



#manual config use this file

vi /etc/vz/conf/1001.conf



# highest upper limit

vzctl set 1001 —kmemsize 2147483647:2147483647 —save

vzctl set 1001 —lockedpages 2147483647:2147483647 —save

vzctl set 1001 —privvmpages 2147483647:2147483647 —save

vzctl set 1001 —shmpages 2147483647:2147483647 —save

vzctl set 1001 —numproc 2147483647:2147483647 —save

vzctl set 1001 —numtcpsock 2147483647:2147483647 —save

vzctl set 1001 —numflock 2147483647:2147483647 —save

vzctl set 1001 —numpty 2147483647:2147483647 —save

vzctl set 1001 —numsiginfo 2147483647:2147483647 —save

vzctl set 1001 —tcpsndbuf 2147483647:2147483647 —save

vzctl set 1001 —tcprcvbuf 2147483647:2147483647 —save

vzctl set 1001 —othersockbuf 2147483647:2147483647 —save

vzctl set 1001 —dgramrcvbuf 2147483647:2147483647 —save

vzctl set 1001 —numothersock 2147483647:2147483647 —save

vzctl set 1001 —dcachesize 2147483647:2147483647 —save

vzctl set 1001 —numfile 2147483647:2147483647 —save

vzctl set 1001 —numiptent 2147483647:2147483647 —save

vzctl set 1001 —diskspace 1423360000:1433600000 —save

vzctl set 1001 —diskinodes 1390000000:1400000000 —save





# start VPS

vzctl start 1001



# chk status

vzctl status 1001



# vzctl exec allows executing any commands in the Virtual Private Server context.

vzctl exec 1001 ping localhost



Regards,

феникс



No comments:

Post a Comment