HeartBeat + DRBD + MYSQL + LVS Cluster

Four hosts

Host name IPAddress Purpose

< p align="left">dbm128 172.16.0.128 172.16.0.128″family heartbeat+DRBD+”Family heartbeat+DRBD+”Family heartbeat+DRBD+”Family heartbeat+DRBD+” >primarynode

dbm129 172.16.0.129 heart+ mysql beat+ mysql secondary node

dbs130 172.16.0.130 6.0 slave(mater_host=172.16.0.233)

dbs131 2.1 131 131 slave(mater_host=172.16.0.233)

Pre-configuration preparation

1. Settingshostname and analysis

Edit /etc/hosts file, add the following content:

172.16.0.128 dbm128

172.16.0.129 dbm129 p>

2. Add a new piece /dev/sdb5The hard disk stores DRBD data (both are added)

The command is as follows:

[root@dbm128 ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won’t be recoverable.

The number of cylinders for this disk is set to 6527.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (eg, old versions of LILO)

2) booting and partitioning software from other OSs

(eg, DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n< /span>

Command action

e extended

p primary partition (1-4)

e

Partition number (1-4): 1

First cylinder (1-6527, default 1):

< p align="left">Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-6527, default 6527):

< span style="font-family:Calibri; font-size:14px">Using default value 6527

Command (m for help): n

Command action< /span>

l logical (5 or over)

p primary partition (1-4)

l

First cylinder (1-6527, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-6527, default 6527):

Using default value 6527

Command (m for help): w

The partition table has been altered!

< p align="left">

Calling ioctl() to re-read partition table.

Syncing disks.

< p align="left">3.DRBD deployment (both machines do this )

yum -y install gcc gcc-c++ kernel* < /span>Restart after installation to avoid errors later

#wget http://oss. linbit.com/drbd/8.4/drbd-8.4.3.tar.gz

# tar zxvf drbd-8.4.3.tar.gz

# cd drbd -8.4.3

# ./configure –prefix=/ –with-km

#make

#make install

4. Load and install< span style="font-family:Calibri">DRDBmodule

#modprobe drbd

After the machine restartsDRBD module disappears, you need to write /etc/rc.local to execute automatically after booting

Check whether it has been executed successfully by lsmod

[root@dbm128 drbd-8.4.3]# lsmod | grep drbd

drbd 327968 0

5.Edit the configuration file (the configuration of the two devices is the same dbm128, dbm129)< /span>

If there is a problem later, please changeLINUXTurn off the firewall, or increase the port.

[root@dbm128 drbd-8.4.3]# cat /etc/drbd .conf

global {usage-count yes;} p>

common{syncer{rate 200M;}}

resource r0{

protocol C;

< p align="left"> net{

cram-hmac-alg sha1;

shared-secret “FooFunFactory”;

shared-secret “FooFunFactory”;

p>

disk{

on-io-error detach;

fencing resource-only;

fencing resource-only }< /p>

startup{

wfc-timeout 120;

degr-wfc-timeout 120;

}

device /dev/drbd1;

on dbm128{

disk /dev/sdb5;

< span style="font-family:Calibri; font-size:14px"> address 172.16.0.128:7789;

meta-disk internal;

meta-disk internal; }

span>

on dbm129{

disk /dev/sdb5;

< p align="left"> address 172.16.0.129:7789;

meta-disk internal;

}

}

< p align="left">

6.Start DRBD( Two operation)

You can use the following command to start DRBD

[root@dbm128 drbd-8.4.3]# drbdadm create-md all

[root@dbm128 drbd -8.4.3]# /etc/init.d/drbd start

[ root@dbm128 drbd-8.4.3]# drbdadm – –overwrite-data-of-peer primary all (this step is only done on the primary server)

View DRBD status on the host

[root@dbm128 ~]# cat /proc/drbd

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@dbm128, 2014-07-18 23:01:15

1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r—n-

< p align="left"> ns:45789492 nr:0 dw:0 dr:45794304 al:0 bm:2794 lo:0 pe:3 ua :5 ap:0 ep :1 wo:f oos:6639292

[======= =========>…] sync’ed: 87.4% (6480/51196)M

finish: 0:06:46 speed: 16,336 (18,732) K/sec

The above data is being synchronized. The following synchronization is completed

[root@dbm128 ~]# cat /proc/drbd < /span>

version: 8.4.3 (api:1/proto:86-101)< /span>

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@dbm128, 2014-07-18 23 :01:15

1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r—– p>

ns:52426428 nr:0 dw:0 dr:52426428 al:0 bm:3200 lo:0 pe :0 ua:0 ap:0 ep:1 wo:f oos:0

View on the slave machine< span style="font-family:Calibri">DRBD status

[root@dbm129 ~]# cat /pro c/drbd

version: 8.4.3 (api:1/proto:86 -101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@dbm129, 2014- 07-18 23:14:34

1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r—–

ns:0 nr:52426428 dw:52426428 dr:0 al:0 bm:3200 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

in During the execution, if the above message appears, it means the operation was successful

7. Format the DRBD file system (Only do on the host span>)

[root@dbm128 ~]# mkfs.ext3 /dev/drbd1

Be careful not to start automaticallyDRBD Service, because it needs to passheartbeat to startDRBD

8. Mount DRBD partition

[root@dbm128 ~]# mkdir /data

[root@dbm128 ~]# mount /dev/drbd1 /data

[root@dbm128 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

92G 4.9G 82G 6% /

/dev/sda1 35M 59M 99M 38% /boot

tmpfs 501M 0 501M 0% /dev/shm

/dev/drbd1 50G 180M 47G 1% /data

After that, put the mysql data directory in the /data

span>

9. install MYSQL database (four Must be installed)

Install the required system Library related library files

[root@dbm128 ~]#< /span>yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake p>

[root@dbm128 ~]# groupadd mysql

[root@dbm128 ~]# useradd -r -g mysql mysql

[root@dbm128 ~]# tar zxvf mysql-5.5.25.tar.gz

[root@dbm128 ~]# cd mysql-5.5.25

[root@dbm128 mysql-5.5.25]# cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql/ -DMYSQL_DATADIR=/opt/mysql/data -DMYSQL_UNIX_ADDR=/opt/mysql/data/ mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMY_SQL_UNIX_A mysql USER=/DMYDWIX_A_DMY=0 span>

[root@dbm128 mysql-5.5.25]# make && make install

Grant relevant permissions

[root@dbm128 mysql]# chown -R mysql:mysql /opt/mysql

[root@dbm128 mysql]# /opt/mysql/scripts/mysql_install_db –user=mysql –basedir=/opt/mysql –datadir=/opt/mysql /data

mysql configuration file

[root@dbm128 mysql]# cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql

[root@dbm128 mysql]# cp /opt/mysql/support-files/my-large.cnf /etc/my.cnf

< span style="font-family:Calibri; font-size:14px">[root@dbm128 mysql]# chmod +x /etc/init.d/mysql

dbm128On the operation, because it will be synchronized over.dbm129< span style="color:red">No operation

[ root@dbm128 mysql]# cp -r /opt/mysql/data /data/mysql

[root@dbm128 mysql]# chown -R mysql:mysql /data/mysql

[root@dbm128 mysql]# vi /etc/init.d/mysql (Two consoles need to modify dbm128,dbm129)

Find datadir=/opt/mysql/data amended to datadir=/data/mysql

[root@dbm128 mysql]#/etc/init.d/mysql start start (dbm129 don’t start Then do heartbeat using automatic start)

[root@dbm128 mysql]# /opt/mysql/bin/mysqladmin -u root password ‘123456’ (operate on all three, dbm129< /span>No operation has been synchronized )

10.Install heartbeat(two )

You must first install DRBD, and then install hearbeat p>

The installation command is as follows:

[root@dbm128 ~]# yum -y install heartbeat heartbeat-devel heartbeat-stonith heartbeat-pils

Next configuration file

[root@ dbm128 ~]# cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/ha.cf

[root@dbm128 ~]# cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/haresources

[root@dbm128 ~]# cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/authkeys

[root@dbm128 ~]# chmod 600 /etc/ha.d/authkeys

Edit ha.cf

[root@dbm128 ~]# cat /etc/ha.d/ha.cf

debugfile /var/log/ha-debug

logfile /var/log/ha-log

logfacility local0

keepalive 1

deadtime 15< /span>

warntime 5

initdead 30

ucast eth0 172.16.0.129 (< span style="color:red">Modify each other’s nodeIP)< /p>

ping_group group 172.16.0.128 172.16.0.129

auto_failback on (modified from node tooff)

node dbm128

node dbm129

respawn hacluster /usr/lib64/heartbeat/ipfail

respawn hacluster /usr/lib64/heartbeat/dopd

span>

apiauth ipfail gid=haclient uid=hacluster

apiauth dopd gid=haclient uid=hacluster

Add to the backcat /etc/ha.d/authkeys

auth 1

1 sha1 HA_JACKBILLOW

Add to the back cat /etc/ha.d/haresources

dbm128 drbddisk::r0 Filesystem::/dev/drbd1::/data mysql IPaddr::172.16.0.233/24/eth0

The above dbm128 host, if dbm129 is modified CPU name.

Start the heartbeat service: span>

[root@dbm128 ~]/etc/init.d/heartbeat start

[root@dbm129 ~]/etc/init.d/heartbeat start

Configure the heartbeat at the startup level 3 is automatically activated in :

[root@dbm128 ~]chkconfig –level 35 heartbeat on

[root@dbm129 ~]chkconfig –level 35 heartbeat on

Observe whether the heartbeat startup log is normal

[root@dbm128 ~]# tail -f /var/log/ha-log

IPaddr[4782]: 2014/07/21_16:48:15 INFO: Success

heartbeat[4147]: 2014/07/21_16:48:57 info: dbm129 wants to go standby [foreign]

heartbeat[4147]: 2014/07/21_16:48:57 info: standby: acquire [foreign] resources from dbm129

heartbeat[5029]: 2014/07/21_16:48:57 info: acquire local HA resources (standby).

ResourceManager[5042]: 2014/07/21_16:48:57 info: Acquiring resource group : dbm128 drbddisk::r0 Filesystem::/dev/drbd1::/data mysql IPaddr::172.16.0.233/24/eth0

Filesystem[5083]: 2 014/07/21_16:48:58 INFO: Running OK

IPaddr[5158 ]: 2014/07/21_16:48:58 INFO: Running OK

heartbeat [5029]: 2014/07/21_16:48:58 info: local HA resource acquisition completed (standby).

heartbeat[4147]: 2014/07/21_16:48:58 info: Standby resource acquisition done [foreign].

heartbeat[4147]: 2014/07/21_16:48:58 info: remote resource transition completed.

Test it and see that 172.16.0.233 is VIP, drifting between two hosts.

11.Master-slave replication configuration

< p align="left">Modify the dbs130,dbs131 main my.cnf’s server-id=1, each synchronization service must be set with a unique number.

Master(这里为dbm128机器)上增加一个用于复制的账号:

mysql>GRANT REPLICATION SLAVE ON *.*  TO ‘repl’@’172.16.0.%’  IDENTIFIED BY ‘123456’;

mysql>FLUSH REPLICATION;

mysql> show master status;

+——————+———-+————–+——————+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+——————+———-+————–+——————+

| mysql-bin.000018 |      107 |              |                  |

+——————+———-+————–+——————+

1 row in set (0.00 sec)

设置Slave 主机

修改my.cnfserver-id,内容如下:

dbs130主机

server-id=3

dbs130主机

server-id=4

开启MasterSlave的同步

Slave上执行如下命令

mysql>CHANGE MASTER TO MASTER_HOST=’172.16.0.233′,

         ->MASTER_USER=’repl’,

         ->MASTER_PASSWORD=’123456′,

         ->MASTER_LOG_FILE=’ mysql-bin.000018′,

         ->MASTER_LOG_POS=107;

 之后执行

 mysql>slav e start;

mysql> show slave status\G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 172.16.0.233

                  Master_User: repl

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000018

          Read_Master_Log_Pos: 107

               Relay_Log_File: dbs130-relay-bin.000007

                Relay_Log_Pos: 253

        Relay_Master_Log_File: mysql-bin.000018

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB:

          Replicate_Ignore_DB:

           Replicate_Do _Table:

       Replicate_Ignore_Table:

      Replicate_Wild_Do_Table:

  Replicate_Wild_Ignore_Table:

                   Last_Errno: 0

                   Last_Error:

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 107

              Relay_Log_Space: 556

              Until_Condition: Non e

               Until_Log_File:

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File:

           Master_SSL_CA_Path:

              Master_SSL_Cert:

            Master_SSL_Cipher:

               Master_SSL_Key:

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

  Replicate_Ignore_Server_Ids:

             Master_Server_Id: 1

1 row in set (0.00 sec)

在其他几台slave机器上也执行上面的命令

Leave a Comment

Your email address will not be published.