Heartbeat + DRBD + mysql + LVS cluster practice _ MySQL

Source: Internet
Author: User
Four host names IP address usage dbm128172160128 four hosts

Host name IP address usage

Dbm128 172.16.0.128 heartbeat + DRBD + MYSQL primary node

Dbm129 172.16.0.129 heartbeat + DRBD + mysql secondary node

Dbs130 172.16.0.130 slave (mater_host = 172.16.0.233)

Dbs131 172.16.0.131 slave (mater_host = 172.16.0.233)

Preparations before configuration

1. set hostname and parse

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

172.16.0.128 dbm128

172.16.0.129 dbm129

2. a new hard disk/dev/sdb5 is added to store 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 coshould in certain setups cause problems:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(E.g., dos fdisk, OS/2 FDISK)

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

Command (m for help): n

Command action

E extended

P primary partition (1-4)

E

Partition number (1-4): 1

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): n

Command action

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!

Calling ioctl () to re-read partition table.

Syncing disks.

3. deploy DRBD (both machines do this)

Yum-y install gcc-c ++ kernel * after installation, restart the system to avoid subsequent errors.

# 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 the DRDB module

# Modprobe drbd

After the machine restarts, the DRBD module disappears and needs to be written to/etc/rc. local for automatic execution upon startup.

Use lsmod to check whether execution is successful

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

Drbd 327968 0

5. edit the configuration file (the two configurations are the same as dbm128 and dbm129)

If there is a problem later, disable the LINUX firewall or increase the port number.

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

Global {usage-count yes ;}

Common {syncer {rate 200 M ;}}

Resource r0 {

Protocol C;

Net {

Cram-hmac-alg sha1;

Shared-secret "FooFunFactory ";

}

Disk {

On-io-error detach;

Fencing resource-only;

}

Startup {

Wfc-timeout 120;

Degr-wfc-timeout 120;

}

Device/dev/drbd1;

On dbm128 {

Disk/dev/sdb5;

Address 172.16.0.128: 7789;

Meta-disk internal;

}

On dbm129 {

Disk/dev/sdb5;

Address 172.16.0.129: 7789;

Meta-disk internal;

}

}

6. start DRBD (two operations)

Run 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 master server)

View the 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, 23:01:15

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

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

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

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

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

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 the DRBD status on the slave machine

[Root @ dbm129 ~] # Cat/proc/drbd

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

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root @ dbm129, 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

If the preceding information is displayed during execution, the operation is successful.

7. format the DRBD file system (only on the host)

[Root @ dbm128 ~] # Mkfs. ext3/dev/drbd1

Do not start the DRBD service on your own because you need to start DRBD through heartbeat.

8. mount the 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 99 M 35 M 59 M 38%/boot

Tmpfs 501 M 0 501 M 0%/dev/shm

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

Put the mysql data directory on/data.

9. install the MYSQL database (four databases must be installed)

Install the required system library files

[Root @ dbm128 ~] # Yum-y install gcc-c ++ gcc-g77 autoconf automake zlib * fiex * libxml * ncurses-devel libmcrypt * libtool-ltdl-devel * cmake

[Root @ dbm128 ~] # Groupadd mysql

[Root @ dbm128 ~] # Useradd-r-g 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-keys = 1-DENABLED_LOCAL_INFILE = 1-keys = 3306-DEXTRA_CHARSETS = all-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-keys =/opt/mysql/data/mysql. sock-DMYSQL_USER = mysql-DWITH_DEBUG = 0

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

Grant related 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

[Root @ dbm128 mysql] # chmod + x/etc/init. d/mysql

You can operate on dbm128 because it will synchronize the past, so dbm129 does not need to be operated.

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

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

[Root @ dbm128 mysql] # vi/etc/init. d/mysql (two sets of dbm128 and dbm129 need to be modified)

Find datadir =/opt/mysql/data and change it to datadir =/data/mysql

[Root @ dbm128 mysql] #/etc/init. d/mysql start (dbm129 does not need to be started when heartbeat is started automatically)

[Root @ dbm128 mysql] #/opt/mysql/bin/mysqladmin-u root password '000000' (all three operations are performed, and dbm129 does not need to be synchronized)

10. install heartbeat (both machines are installed)

Install DRBD before you can install hearbeat

The installation command is as follows:

[Root @ dbm128 ~] # Yum-y install heartbeat-devel heartbeat-stonith heartbeat-pils

Next, configure the 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

Modify 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

Warntime 5

Initdead 30

Ucast eth0 172.16.0.129 (modify the IP address of the peer node)

Ping_group group 172.16.0.128 172.16.0.129

Auto_failback on (change from node to off)

Node dbm128

Node dbm129

Respawn hacluster/usr/lib64/heartbeat/ipfail

Respawn hacluster/usr/lib64/heartbeat/dopd

Apiauth ipfail gid = haclient uid = hacluster

Apiauth dopd gid = haclient uid = hacluster

Add cat/etc/ha. d/authkeys

Auth 1

1 sha1 HA_JACKBILLOW

Add 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 modifies this host name.

Start the heartbeat service:

[Root @ dbm128 ~] /Etc/init. d/heartbeat start

[Root @ dbm129 ~] /Etc/init. d/heartbeat start

Configure heartbeat to automatically start at startup Level 3:

[Root @ dbm128 ~] Chkconfig -- level 35 heartbeat on

[Root @ dbm129 ~] Chkconfig -- level 35 heartbeat on

Check whether heartbeat startup logs are normal.

[Root @ dbm128 ~] # Tail-f/var/log/ha-log

IPaddr [4782]: _ 16:48:15 INFO: Success

Heartbeat [4147]: _ 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]: _ 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]: _ 16:48:58 INFO: Running OK

IPaddr [5158]: _ 16:48:58 INFO: Running OK

Heartbeat [5029]: _ 16:48:58 info: local HA resource acquisition completed (standby ).

Heartbeat [4147]: _ 16:48:58 info: Standby resource acquisition done [foreign].

Heartbeat [4147]: _ 16:48:58 info: remote resource transition completed.

Test it. we can see that 172.16.0.233 is a VIP and is drifting between two hosts.

11. configure master-slave replication

Modify the server-id = 1 of my. cnf in dbs130 and dbs131. each synchronization service must have a unique id.

Add an account for replication on The Master (dbm128:

Mysql> grant replication slave on *. * TO 'repl' @ '2017. 172.% 'identified by '20160301 ';

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)

Set Slave host

Modify the server-id of my. cnf. the content is as follows:

Dbs130 host

Server-id = 3

Dbs130 host

Server-id = 4

Enable Master and Slave synchronization

Run the following command on Slave:

Mysql> change master to MASTER_HOST = '2017. 16.0.233 ',

-> MASTER_USER = 'repl ',

-> MASTER_PASSWORD = '123 ',

-> MASTER_LOG_FILE = 'mysql-bin.000018 ',

-> MASTER_LOG_POS = 107;

Then run

Mysql> slave 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: None

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)

Run the preceding command on several other server load balancer instances.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.