Preface * DRBD (distributedreplicatedblockdevice) is an open source software that synchronizes and mirrors data directly on a remote server based on the block device level. Similar to RAID1 data mirroring, typically with HA software such as keepalived, heartbeat, for high availability. The simple records here are for reference only.
First, the implementation of the environment
System version: CentOS 5.8DRBD version: drbd-8.3.15keepalived:keepalived-1.1.15master:192.168.149.128backup:192.168.149.129
Second, the initialization of the configuration
1) in 128, 1292 server/etc/hosts inside Add the following configuration:
192.168.149.128 node1192.168.149.129 node2
2) Optimize the system kernel parameters, directly on the sysctl.conf configuration as follows:
Net.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0KERNEL.SYSRQ = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1KERNEL.MSGMNB = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296net.ipv4.tcp_max_tw_buckets = 10000net.ipv4.tcp_sack = 1net.ipv4.tcp_window_ Scaling = 1net.ipv4.tcp_rmem = 4096 87380 4194304net.ipv4.tcp_wmem = 4096 16384 4194304net.core.wmem_def Ault = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.netdev_ Max_backlog = 262144net.core.somaxconn = 262144net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_fin_timeout = 1net.ipv4.tcp_ Keepalive_time = 30net.ipv4.ip_local_port_range = 1024x768 65530net.ipv4.icmp_echo_ignore_all = 1
3) Two servers add a piece of equipment, for the DRBD master device storage, I here for/dev/sdb 30G HDD;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/28/wKioL1Np_7aTusfaAAKJoxAzkU4740.jpg "title=" 1.png " alt= "Wkiol1np_7atusfaaakjoxazku4740.jpg" width= "680" height= "266" border= "0" hspace= "0" vspace= "0" style= "width : 680px;height:266px; "/>
Execute the following command:
Mkfs.ext3/dev/sdb;dd If=/dev/zero of=/dev/sdb bs=1m Count=1;sync
Third, DRBD installation configuration
Yum-y install drbd83* kmod-drbd83; Modprobe DRBD
After the installation is complete and the DRBD module is loaded, vi modifies the/etc/drbd.conf configuration file, as follows:
Global { usage-count yes;} Common {syncer {rate 100M;}} Resource R0 {protocol C; startup { } disk {On-io-error detach; #size 1G;} net {} on node1 {device/dev/drbd0; dis K/dev/sdb; Address 192.168.149.128:7898; Meta-disk internal; } on Node2 {device/dev/drbd0; disk/dev/sdb; address 192.168.149.129:7898; Meta-disk internal;}}
After the configuration has been modified, execute the following command initialization:
Drbdadm create-md r0 ;/etc/init.d/drbd restart;/etc/init.d/status
Such as:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/2B/wKiom1NqA0_gZAfCAATMZZdgNLI315.jpg "title=" 5.png " Width= "680" height= "266" border= "0" hspace= "0" vspace= "0" style= "width:680px;height:266px;" alt= "wkiom1nqa0_ Gzafcaatmzzdgnli315.jpg "/>
The above steps, need to be performed on both servers, both are configured after the Node2 from the above to execute the following command:/ETC/INIT.D/DRBD status See the following information, indicating that the current two are from, we need to set Node1 as master, the command is as follows:
DRBDADM----Overwrite-data-of-peer primary allmkfs.ext3/dev/drbd0mkdir /app ; mount/dev/drbd0 /app
Since then, the DRBD configuration, we can write to the/app directory of anything, when Master has a downtime or other failures, manually switch to backup, the data is not lost, equivalent to two servers to do network RAID1.
Iv. Configuration of Keepalived
Wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz; TAR-XZVF keepalived-1.1.15.tar.gz; CD keepalived-1.1.15;./configure; Make, make installdir=/usr/local/, CP $DIR/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/, CP $DIR/etc/sysconfig/ keepalived/etc/sysconfig/; mkdir-p/etc/keepalived; CP $DIR/sbin/keepalived/usr/sbin/
Both servers are installed keepalived and configured, first configured on Node1 (master), and the keepalived.conf content is as follows:
! Configuration File for keepalivedglobal_defs { router_id lvs_devel}vrrp_script check_mysql { script '/data/sh/ check_mysql.sh " interval 5 }vrrp_instance vi_1 {State MASTER interface eth0 virtual_router_id advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.149.100 } track_script { check_mysql }}
Then create a check_mysql.sh detection script that reads as follows:
#!/bin/sha= ' ps-c mysqld--no-header |wc-l ' if[$A-eq 0];then/bin/umount/app/drbdadm secondary R0killall KEEPALIVEDFI
On the Add Node2 (Backup) configuration, the keepalived.conf content is as follows:
! Configuration File for keepalivedglobal_defs { router_id lvs_devel}vrrp_sync_group vi{group { vi_1}notify_ Master/data/sh/master.shnotify_backup/data/sh/backup.sh}vrrp_instance vi_1 {State backup interface eth0 virtual_router_id advert_int 1 authentication { Auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.149.100 }}
Create a master.sh detection script that reads as follows:
#!/bin/bashdrbdadm Primary R0/bin/mount/dev/drbd0/app//etc/init.d/mysqld Start
Create a backup.sh detection script that reads as follows:
#!/bin/bash/etc/init.d/mysqld Stop/bin/umount/dev/drbd0drbdadm Secondary R0
The following steps occur for the recovery of cerebral bifida:
Master execution Command: Drbdadm secondary R0drbdadm -- --discard-my-data Connect r0backup Execute command: Drbdadm Connect R0
The article is for reference only, this article references, especially thanks to share the dedicated it person.
http://oldboy.blog.51cto.com/2561410/1240412
http://docs.linuxtone.org/ebooks/MySQL/Heartbeat+MySQL+DRBD%E6%9E%84%E5%BB%BA%E9%AB%98%E5%8F%AF%E7%94%A8MySQL% E6%96%b9%e6%a1%88.pdf
This article is from the "Wu Guangko-focus on automated Operations" blog, please be sure to keep this source http://wgkgood.blog.51cto.com/1192594/1408056