In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Experimental reference http://blog.csdn.net/qq_19175749/article/details/51607210
1. Introduction of related software 1. Introduction to Heartbeat
Official site: http://linux-ha.org/wiki/Main_Page
Heartbeat can quickly transfer resources (VIP address and program service) from one malfunctioning server to another normal server to provide services. Heartbeat is similar to keepalived. Heartbeat can achieve failover function, but can not achieve health check on the back end.
Application scenarios and differences between heartbeat and keepalived
Many netizens say why not use keepalived but use heartbeat which has not been updated for a long time. Here are the application scenarios and differences between them.
1. For web,db, load balancing (lvs,haproxy,nginx), etc., both heartbeat and keepalived can be implemented
2. It is best to combine lvs with keepalived, because keepalived was originally generated for lvs. (heartbeat does not have the health check function for RS, and heartbeat can carry out health check through ldircetord).
3. Mysql dual-master and multi-slave, NFS/MFS storage, they are characterized by the need for data synchronization, such business is best to use heartbeat, because heartbeat has its own drbd script
Summary: applications without data synchronization have high availability and optional keepalived, and applications with data synchronization have high availability and optional heartbeat
2. DRBD introduction
Official site: http://www.drbd.org/users-guide-8.4/
DRBD (DistributedReplicatedBlockDevice) is a software that directly synchronizes and mirrors data at the remote server based on the block device level. It is a storage replication solution realized by software without sharing and mirroring the contents of block devices between servers. It can achieve real-time mirroring or synchronous replication based on block device level between two servers in the network (both servers write successfully) / asynchronous replication (local server writes successfully), which is equivalent to the RAID1 of the network. Because it is based on block devices (disk, LVM logical volume), at the bottom of the file system, data replication is faster than the cp command. DRBD has been officially written into the documentation manual by MySQL as one of the recommended high-availability solutions
3. MySQL introduction
Official site: http://www.mysql.com/
MySQL is an open source small relational database management system. At present, MySQL is widely used in small and medium-sized websites on Internet. Because of its small size, high speed and low total cost of ownership, especially open source, many small and medium-sized websites choose MySQL as the website database in order to reduce the total cost of ownership.
Second, pre-environmental preparation 1. Architecture Topology
Architecture description:
One master and multiple slaves are the most commonly used architectures, and multiple slave libraries can use lvs to provide load balancing for reading.
To solve the problem of a master single point, when the master library is down, the backup node of the master library can take over automatically, and all the slave libraries will automatically synchronize with the new master library, thus realizing the hot backup scheme of the mysql master library.
two。 System environment
System environment
System
Red Hat Enterprise Linux Server release 6.5
Number of system bits
X86_64
Kernel version
2.6.32-431.el6.x86_64
Software environment
Heartbeat
Heartbeat-3.0.4
Drbd
Drbd-8.4.4
Mysql
Mysql-5.5.32
3. Deployment environment
Role
IP
VIP
Eth0: 192.168.12.1 Compact 24 (address for external service)
Master1
Eth0: 192.168.12.55 Universe 24 (private network)
Eth2: 10.1.12.55 shock 24 (heartbeat line)
Eth3: 10.2.12.55 Compact 24 (DRBD Gigabit data transfer)
Master2
Eth0: 192.168.12.56 Universe 24 (intranet)
Eth2: 10.1.12.56 stroke 24 (heartbeat line)
Eth3: 10.2.12.56 Compact 24 (DRBD Gigabit data transfer)
Slave1
Eth0: 192.168.12.55 Universe 24 (temporarily on master1)
Description: slave library carries out master-slave synchronous replication through the VIP of master library.
Demand:
1. When the master library master1 goes down, master2 automatically takes over VIP and all slave libraries
2. When master2 takes over, the master-slave synchronization replication of the slave library will not be affected.
4. Main database server data partition information
Magnetic disk
Capacity
Zoning
Mounting point
Description
/ dev/sdb
18G
/ dev/sdb2
/ data/
Store data
2G
/ dev/sdb1
Metadata partition
Store the status information of drbd synchronization
Be careful
1. The metadata partition must not be formatted to establish the file system (sdb2 stores the status information of drbd synchronization)
2. Do not mount the divided partition.
3. The DRBDmetadata partition of the production environment can generally be set to 1-2G, and the data partition depends on the maximum demand.
4. In a production environment, two hard drives are the same size
5. Environmental preparation
# # modify the hostname and ip, disable the firewall, and restart the system:
# hostname master1
# vi / etc/sysconfig/network
NETWORKING=yes
HOSTNAME=master1
# as follows:
[root@master1 ~] # hostname
Master1
[root@master1 ~] # ip add | egrep "eth0 | eth2 | eth3" | grep inet
Inet 192.168.12.55/24 brd 192.168.12.255 scope global eth0
Inet 10.1.12.55/24 brd 10.1.12.255 scope global eth2
Inet 10.2.12.55/24 brd 10.2.12.255 scope global eth3
[root@master1 ~] # fdisk-l | grep sdb
Disk / dev/sdb: 21.5 GB, 21474836480 bytes
[root@master1 ~] # chkconfig iptables off
[root@master1 ~] # reboot
[root@master2 ~] # hostname
Master2
[root@master2 ~] # ip add | egrep "eth0 | eth2 | eth3" | grep inet
Inet 192.168.12.56/24 brd 192.168.12.255 scope global eth0
Inet 10.1.12.56/24 brd 10.1.12.255 scope global eth2
Inet 10.2.12.56/24 brd 10.2.12.255 scope global eth3
[root@master2 ~] # fdisk-l | grep sdb
Disk / dev/sdb: 21.5 GB, 21474836480 bytes
[root@master2 ~] # chkconfig iptables off
[root@master2 ~] # reboot
Third, heartbeat installation and deployment 1. Configure heartbeat connection routing and hosts between servers
= master1
[root@master1 ~] # route add-host 10.1.12.56 dev eth2 "to Peer heartbeat routing"
[root@master1 ~] # route add-host 10.2.12.56 dev eth3 "data routing to peer DRBD"
[root@master1 ~] # route-n | grep "10\." | sort
10.1.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.1.12.56 0.0.0.0 255.255.255.255 UH 0 0 0 eth2
10.2.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
10.2.12.56 0.0.0.0 255.255.255.255 UH 0 0 0 eth3
# # selecting heartbeat ip and drbd-ip in hosts configuration
[root@master1 ~] # echo "10.1.12.55 master1
10.2.12.55 master1
10.1.12.56 master2
10.2.12.56 master2 "> > / etc/hosts
[root@master1] # tail-4 / etc/hosts
10.1.12.55 master1
10.2.12.55 master1
10.1.12.56 master2
10.2.12.56 master2
= master2
[root@master2 ~] # route add-host 10.1.12.55 dev eth2
[root@master2 ~] # route add-host 10.2.12.55 dev eth3
[root@master2 ~] # route-n | grep "10\." | sort
10.1.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.1.12.55 0.0.0.0 255.255.255.255 UH 0 0 0 eth2
10.2.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
10.2.12.55 0.0.0.0 255.255.255.255 UH 0 0 0 eth3
# # selecting heartbeat ip for hosts configuration
[root@master2 ~] # echo "10.1.12.55 master1
10.2.12.55 master1
10.1.12.56 master2
10.2.12.56 master2 "> > / etc/hosts
[root@master2] # tail-2 / etc/hosts
10.1.12.55 master1
10.2.12.55 master1
10.1.12.56 master2
10.2.12.56 master2
two。 Install heartbeat
# # if the firewall is enabled, you need to release udp port 694master / slave consistency
[root@master2 heartbeat-3.0.4-RPM] # cat setup.sh
#! / bin/bash
Cd `dirname $0`
Echo `pwd`
Echo install lib64ltdl7
Rpm-ivf lib64ltdl7-2.2.6-6.1mdv2009.1.x86_64.rpm
Echo install perl-TimeDate
Rpm-ivf perl-TimeDate-1.16-13.el6.noarch.rpm
Echo install PyXML
Rpm-ivf PyXML-0.8.4-19.el6.x86_64.rpm
Echo install cluster-glue-libs
Rpm-ivf cluster-glue-libs-1.0.5-6.el6.x86_64.rpm
Echo install cluster-glue
Rpm-ivf cluster-glue-1.0.5-6.el6.x86_64.rpm
Echo install resource-agents
Rpm-ivf resource-agents-3.9.5-24.el6_7.1.x86_64.rpm
Echo install heartbeat
Rpm-ivf heartbeat-3.0.4-2.el6.x86_64.rpm heartbeat-libs-3.0.4-2.el6.x86_64.rpm
Echo Done
Exit 0
[root@master2 heartbeat-3.0.4-RPM] # sh setup.sh
[root@master2 heartbeat-3.0.4-RPM] # rpm-qa | grep heartbeat
Heartbeat-libs-3.0.4-2.el6.x86_64
Heartbeat-3.0.4-2.el6.x86_64
3. Configure heartbeat
# # configuration files of master and slave are exactly the same ha.cf/authkeys/sharesources
3.1 configure the ha.cf file
[root@master1 ~] # vim / etc/ha.d/ha.cf
# log configure
Debugfile / var/log/ha-debug
Logfile / var/log/ha-log
Logfacility local1
# options configure
Keepalive 2
Deadtime 30
Warntime 10
Initdead 120
# bcast eth2
Mcast eth2 225.0.0.55 694 1 0
# node configure
Auto_failback on
Node master1
Node master2
Crm no
3.2 configure the authkeys file
[root@master1 ~] # vi / etc/ha.d/authkeys
Auth 1
1 sha1 47e9336850f1db6fa58bc470bc9b7810eb397f06
[root@master1 ~] # chmod 600 / etc/ha.d/authkeys
3.3.Configuring haresource files
Master1 IPaddr::192.168.12.1/24/eth0
# master1 IPaddr::192.168.12.1/24/eth0 drbddisk::data Filesystem::/dev/drbd1::/data::ext4 mysqld
Description:
Drbddisk::data / dev/null 2 > & 1
4.4 configure DRBD
# # configuration files on both sides of the master and slave nodes are identical
[root@master1 ~] # vi / usr/local/drbd/etc/drbd.conf
Global {
# minor-count 64
# dialog-refresh 5; # 5 seconds
# disable-ip-verification
Usage-count no
}
Common {
Protocol C
Disk {
On-io-error detach
# size 454G
No-disk-flushes
No-md-flushes
}
Net {
Sndbuf-size 512k
# timeout 60; # 6 seconds (unit = 0.1seconds)
# connect-int 10; # 10 seconds (unit = 1 second)
# ping-int 10; # 10 seconds (unit = 1 second)
# ping-timeout 5; # 500 ms (unit = 0.1 seconds)
Max-buffers 8000
Unplug-watermark 1024
Max-epoch-size 8000
# ko-count 4
# allow-two-primaries
Cram-hmac-alg "sha1"
Shared-secret "hdhwXes23sYEhart8t"
After-sb-0pri disconnect
After-sb-1pri disconnect
After-sb-2pri disconnect
Rr-conflict disconnect
# data-integrity-alg "md5"
# no-tcp-cork
}
Syncer {
Rate 120M
Al-extents 517
}
}
Resource data {
On master1 {
Device / dev/drbd1
Disk / dev/sdb2
Address 10.2.12.55:7788
Meta-disk / dev/sdb1 [0]
}
On master2 {
Device / dev/drbd1
Disk / dev/sdb2
Address 10.2.12.56:7788
Meta-disk / dev/sdb1 [0]
}
}
4.5 initialize the meta partition
# # configuration files on both sides of the master and slave nodes are identical
[root@master1 ~] # drbdadm create-md data
Writing meta data...
Initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.
4.6 start drbd
# # both master and slave are required
[root@master1 ~] # drbdadm up all
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown CRUTHUTHUTHUMUR
Ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:18860312
4.7 initialize device synchronization (set master node, overwrite standby node, keep data consistent)
# # Operation of Master Node
[root@master1] # drbdadm-overwrite-data-of-peer primary data
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-
Ns:10354688 nr:0 dw:0 dr:10358428 al:0 bm:632 lo:1 pe:0 ua:4 ap:0 ep:1 wo:d oos:8505624
[= >.] Sync'ed: 55.0% (8304ax 18416) M
Finish: 0:01:25 speed: 99360 (96772) K/sec
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-
Ns:0 nr:15407104 dw:15406080 dr:0 al:0 bm:940 lo:2 pe:7 ua:1 ap:0 ep:1 wo:d oos:3454232
[= >.] Sync'ed: 81.7% (3372max 18416) M
Finish: 0:00:35 speed: 98360 (96288) want: 102400 K/sec
[root@master1] # chkconfig-- list drbd
Drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4.8 Mount the drbd partition to the data data directory
[root@master1 ~] # drbdadm primary all
[root@master1 ~] # mkdir / data
[root@master1 ~] # mount / dev/drbd1 / data/
[root@master1 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 172m 17G 1% / data
4.9 Test drbd
# # normal status
[root@master1 ~] # cp drbd-8.4.4.tar.gz / data/
[root@master1 ~] # echo "test drbd switch." > / data/test.txt
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:18861122 nr:0 dw:812 dr:18861341 al:4 bm:1152 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-
Ns:0 nr:18861146 dw:18861146 dr:0 al:0 bm:1152 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
Description: master1 is the primary node and master2 is the standby node
# # simulating master1 downtime
[root@master1 ~] # umount / dev/drbd1
[root@master1 ~] # drbdadm down all
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:WFConnection ro:Secondary/Unknown ds:UpToDate/DUnknown C r-
Ns:0 nr:18861178 dw:18861178 dr:0 al:0 bm:1152 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # drbdadm primary all
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:WFConnection ro:Primary/Unknown ds:UpToDate/DUnknown C r-
Ns:0 nr:18861178 dw:18861178 dr:668 al:0 bm:1152 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # mkdir / data
[root@master2 ~] # mount / dev/drbd1 / data/
[root@master2 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 173M 17G 2% / data
[root@master2 ~] # ll-lrht / data/
Total 716K
Drwx- 2 root root 16K Mar 16 2018 lost+found
-rw-r--r-- 1 root root 693K Mar 16 2018 drbd-8.4.4.tar.gz
-rw-r--r-- 1 root root 23 Mar 16 2018 test.txt
Note: after master1 downtime, master2 can be upgraded to the primary node, and the drbd partition can be mounted to continue to use.
# restore drbd to master1
[root@master1 ~] # / etc/init.d/drbd start
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-
Ns:0 nr:4 dw:4 dr:0 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:4 nr:18861178 dw:18861182 dr:1027 al:1 bm:1153 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # / etc/init.d/drbd stop
Stopping all DRBD resources:
.
[root@master2 ~] # cat / proc/drbd
Cat: / proc/drbd: No such file or directory
[root@master2 ~] # df-hT | grep drbd
[root@master2 ~] # / etc/init.d/drbd start
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:Connected ro:Secondary/Secondary 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:d oos:0
[root@master1 ~] # drbdadm primary all
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:0 nr:8 dw:8 dr:668 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master1 ~] # mount / dev/drbd1 / data/
[root@master1 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 173M 17G 2% / data
4.10 configure haresource to launch drbd
[root@master1] # chkconfig-- list drbd
Drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@master1 ~] # chkconfig drbd off
[root@master1 ~] # vi / etc/ha.d/haresources
Master1 IPaddr::192.168.12.1/24/eth0 drbddisk::data Filesystem::/dev/drbd1::/data::ext4
[root@master1 ~] # cp / root/drbd-8.4.4/scripts/drbddisk / etc/ha.d/resource.d/
[root@master1 ~] # / etc/init.d/heartbeat stop
[root@master2 ~] # chkconfig drbd off
[root@master2 ~] # vi / etc/ha.d/haresources
Master1 IPaddr::192.168.12.1/24/eth0 drbddisk::data Filesystem::/dev/drbd1::/data::ext4
[root@master2 ~] # cp / root/drbd-8.4.4/scripts/drbddisk / etc/ha.d/resource.d/
[root@master2 ~] # / etc/init.d/heartbeat stop
[root@master1 ~] # / etc/init.d/heartbeat start
[root@master2 ~] # / etc/init.d/heartbeat start
# # Test switching
[root@master1 ~] # ip add | grep 192
Inet 192.168.12.55/24 brd 192.168.12.255 scope global eth0
Inet 192.168.12.1/24 brd 192.168.12.255 scope global secondary eth0
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:4 nr:0 dw:4 dr:693 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master1 ~] # df-hT | grep / drbd
/ dev/drbd1 ext4 18G 173M 17G 2% / data
[root@master1 ~] # / etc/init.d/heartbeat stop
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-
Ns:8 nr:4 dw:12 dr:1027 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master1 ~] # ip add | grep 192
Inet 192.168.12.55/24 brd 192.168.12.255 scope global eth0
[root@master2 ~] # ip add | grep 192
Inet 192.168.12.56/24 brd 192.168.12.255 scope global eth0
Inet 192.168.12.1/24 brd 192.168.12.255 scope global secondary eth0
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:4 nr:8 dw:12 dr:693 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 173M 17G 2% / data
V. MySQL installation and deployment
# # master1 installation mysql,master2 is only installed before initialization, and slave slave library is also configured on master1. Slave slave library is not configured here.
1. Install cmake tools
# ls-lrht cmake-2.8.8.tar.gz
-rw-r--r-- 1 root root 5.5m Oct 20 04:50 cmake-2.8.8.tar.gz
# tar xf cmake-2.8.8.tar.gz
# cd cmake-2.8.8
#. / configure
# gmake
# gmake install
# which cmake
/ usr/local/bin/cmake
two。 Install ncurses-devel dependencies
# yum-y install ncurses-devel
# yum-y install bison
3. Start installing MySQL3.1 to create users
-u specified user uid-s specifies the shell used for user login-M do not create a user login directory-g specifies the group to which the user belongs-G specifies the user additional group
# groupadd-g 1200 mysql
# useradd mysql-s / sbin/nologin-M-g mysql-u 1200
-hosts configuration (there is no need to configure here, because the subsequent mysql provides services through vip)
# tail-4 / etc/hosts
10.1.12.55 master1
10.2.12.55 master1
10.1.12.56 master2
10.2.12.56 master2
3.2 decompression and compilation
# tar zxf mysql-5.5.32.tar.gz
# cd mysql-5.5.32
# cmake. -DCMAKE_INSTALL_PREFIX=/app/mysql-5.5.32\
-DMYSQL_DATADIR=/app/mysql-5.5.32/data\
-DMYSQL_UNIX_ADDR=/app/mysql-5.5.32/tmp/mysql.sock\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii\
-DENABLED_LOCAL_INFILE=ON\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_FEDERATED_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1\
-DWITHOUT_PARTITION_STORAGE_ENGINE=1\
-DWITH_FAST_MUTEXES=1\
-DWITH_ZLIB=bundled\
-DENABLED_LOCAL_INFILE=1\
-DWITH_READLINE=1\
-DWITH_EMBEDDED_SERVER=1\
-DWITH_DEBUG=0
3. 3 install mysql
# make & & make install
3.4.Create a Link file
# ln-s / app/mysql-5.5.32/ / app/mysql
# ll / app/
Total 4
Lrwxrwxrwx 1 root root 18 Oct 30 05:06 mysql- > / app/mysql-5.5.32/
Drwxr-xr-x 13 root root 4096 Oct 30 05:05 mysql-5.5.32
3.5 configure environment variables
# echo 'export PATH=/app/mysql/bin:$PATH' > > / etc/profile
Tail-5 / etc/profile
Source / etc/profile
Echo $PATH
3.6Configuring my.cnf files
# # put it on drbd storage
# vi / data/master/my.cnf
[mysqld]
Socket = / data/master/mysql.sock
Port = 3306
Pid-file = / data/master/mysql.pid
Datadir = / data/master/data
Basedir = / app/mysql
User = mysql
Server-id=1
[client]
Port = 3306
Socket = / data/master/mysql.sock
[mysql]
No-auto-rehash
4. Initialize and start MySQL on master1
# # Note: the directory where the database stores data must be in the drbd partition.
# # Operation on master1
[root@master1 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 173M 17G 2% / data
[root@master1 ~] # cd / app/mysql/scripts/
#. / mysql_install_db-basedir=/app/mysql-datadir=/data/master/data-user=mysql
# chown-R mysql. / data/master/
# # starting mysql
# mysqld_safe-- defaults-file=/data/master/my.cnf &
# netstat-nltpd | grep mysql
# # modifying mysql login password
# / app/mysql/bin/mysqladmin-u root password '111111'-S / data/master/mysql.sock
# # Login Test
# mysql-uroot-p111111-S / data/master/mysql.sock
5. Configure mysql startup and shutdown script
# # Note that both master1 and master2 need to be added and added to the ha startup directory
# vi / etc/ha.d/resource.d/mysqld
#! / bin/bash
Port=3306
Mysql_user= "root"
Mysql_pwd= "111111"
Cmdpath= "/ app/mysql/bin/"
Mysql_sock= "/ data/master/mysql.sock"
# startup function
Function_start_mysql ()
{
If [!-e ${mysql_sock}]; then
Printf "Starting MySQL...\ n"
/ bin/sh ${cmdpath} / mysqld_safe-- defaults-file=/data/master/my.cnf 2 > & 1 > / dev/null &
Else
Printf "MySQL is running...\ n"
Exit
Fi
}
# stop function
Function_stop_mysql ()
{
If [!-e "$mysql_sock"]; then
Printf "MySQL is stopped...\ n"
Exit
Else
Printf "Stoping MySQL...\ n"
# echo "${cmdpath} mysqladmin-u ${mysql_user}-p$ {mysql_pwd}-S / mysqldata/$ {port} / mysql$ {port} .sock shutd
Own "
${cmdpath} mysqladmin-u ${mysql_user}-p$ {mysql_pwd}-S / data/master/mysql.sock shutdown
Fi
}
# restart function
Function_restart_mysql ()
{
Printf "Restarting MySQL...\ n"
Function_stop_mysql
Sleep 2
Function_start_mysql
}
Case $1 in
Start)
Function_start_mysql
Stop)
Function_stop_mysql
Restart)
Function_restart_mysql
*)
Printf "Usage:/mysqldata/$ {port} / mysql {start | stop | restart}\ n"
Esac
# # Test start and stop
# chmod axix / etc/ha.d/resource.d/mysqld
# / etc/ha.d/resource.d/mysqld start
# netstat-nltpd | grep mysql
5. Start MySQL on master2
# # stop the mysql service on master1 first
# / etc/ha.d/resource.d/mysqld stop
# # disable the high availability on master1 and mount the drbd disk to master2
[root@master1 ~] # / etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
[root@master1 ~] # / etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
# # check on master2
[root@master2 ~] # ip add | grep 192
Inet 192.168.12.56/24 brd 192.168.12.255 scope global eth0
Inet 192.168.12.1/24 brd 192.168.12.255 scope global secondary eth0
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:20 nr:41760 dw:41780 dr:2096 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 202m 17G 2% / data
# # master2 copy mysql start / stop service and modify
# scp / etc/ha.d/resource.d/mysqld master2:/etc/ha.d/resource.d/mysqld
# # start and stop testing
[root@master2 ~] # / etc/ha.d/resource.d/mysqld start
Starting MySQL.. [OK]
[root@master2 ~] # netstat-nltpd | grep mysql
Tcp 0 0 0.0.0.0 3306 0.0.0.015 * LISTEN 41571/mysqld
[root@master2 ~] # / etc/ha.d/resource.d/mysqld stop
Shutting down MySQL. [OK]
6. Configure haresource to start MySQL
Operation is required for both master1 and master2
# # stop the height available first
# / etc/init.d/heartbeat stop
# # move mysqld service to ha service
# chkconfig-list mysqld
Service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig-- add mysqld')
# ll / etc/ha.d/resource.d/ | grep mysql
-rwxr-xr-x 1 root root 1152 Oct 30 11:35 mysqld
# # modifying Startup parameters
# vi / etc/ha.d/haresources
Master1 IPaddr::192.168.12.1/24/eth0 drbddisk::data Filesystem::/dev/drbd1::/data::ext4 mysqld
# # enabling High availability
# / etc/init.d/heartbeat start
# tail-200f / var/log/ha-log
# tail-200f / var/log/ha-debug
# # check
[root@master1 ~] # ip add | grep 192
Inet 192.168.12.55/24 brd 192.168.12.255 scope global eth0
Inet 192.168.12.1/24 brd 192.168.12.255 scope global secondary eth0
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:41952 nr:884 dw:42836 dr:9467 al:16 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master1 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 202m 17G 2% / data
[root@master1 ~] # netstat-nltpd | grep mysqld
Tcp 0 0 0.0.0.0 3306 0.0.0.015 * LISTEN 54535/mysqld
# # Test switching
[root@master1 ~] # / etc/init.d/heartbeat stop
[root@master1 ~] # ip add | grep 192
Inet 192.168.12.55/24 brd 192.168.12.255 scope global eth0
[root@master1 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master1, 2018-03-16 11:44:26
1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-
Ns:42100 nr:996 dw:43096 dr:9801 al:16 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master1 ~] # df-hT | grep drbd
[root@master1 ~] # netstat-nltpd | grep mysql
[root@master2 ~] # ip add | grep 192
Inet 192.168.12.56/24 brd 192.168.12.255 scope global eth0
Inet 192.168.12.1/24 brd 192.168.12.255 scope global secondary eth0
[root@master2 ~] # cat / proc/drbd
Version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@master2, 2016-10-29 23:25:51
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:1044 nr:42100 dw:43144 dr:13859 al:6 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
[root@master2 ~] # df-hT | grep drbd
/ dev/drbd1 ext4 18G 202m 17G 2% / data
[root@master2 ~] # netstat-nltpd | grep mysqld
Tcp 0 0 0.0.0.0 3306 0.0.0.015 * LISTEN 43020/mysqld
6. MySQL slave deployment 1. Main library preparation
# # now the HA of mysql has been configured, and the current node is on master1
# # simple configuration Optimization
[root@master1] # mysql-uroot-p111111-S / data/master/mysql.sock
Mysql > drop database test
Mysql > select user,host from mysql.user
Mysql > delete from mysql.user where user=''
Mysql > delete from mysql.user where host='master1'
Mysql > delete from mysql.user where host='::1'
Mysql > select user,host from mysql.user
+-+ +
| | user | host |
+-+ +
| | root | 127.0.0.1 | |
| | root | localhost |
+-+ +
2 rows in set (0.00 sec)
Mysql > flush privileges
# # modifying main Library parameters
[root@master1 ~] # vi / data/master/my.cnf
[mysqld]
Server-id = 1
Log-bin=/data/master/mysql-bin
# # restart mysql
[root@master1 ~] # / etc/ha.d/resource.d/mysqld restart
[root@master1 ~] # netstat-nltpd | grep mysql
Tcp 0 0 0.0.0.0 3306 0.0.0.015 * LISTEN 43242/mysqld
[root@master1 ~] # ll / data/master/ | grep mysql-bin
-rw-rw---- 1 mysql mysql 126 Mar 19 16:03 mysql-bin.000001
-rw-rw---- 1 mysql mysql 107 Mar 19 16:03 mysql-bin.000002
-rw-rw---- 1 mysql mysql 60 Mar 19 16:03 mysql-bin.index
# # create a synchronization account rep in the main database
# mysql-uroot-p111111-S / data/master/mysql.sock
Mysql > grant replication slave on *. * to 'rep'@'192.168.12.%' identified by' 123456'
Mysql > flush privileges
Mysql > select user,host from mysql.user
# # Test connection and synchronize from the library through vip
# mysql-urep-p123456-h292.168.12.1-P3306
two。 Initialize from the library
# # install from the library to the local disk of master1
[root@master1] # mkdir-p / mysql/slave
[root@master1 ~] # cd / app/mysql/scripts/
#. / mysql_install_db-basedir=/app/mysql-datadir=/mysql/slave/data-user=mysql
3. Configure slave library my.cnf
# vi / mysql/slave/my.cnf
[mysqld]
Socket = / mysql/slave/mysql.sock
Port = 3307
Pid-file = / mysql/slave/mysql.pid
Datadir = / mysql/slave/data
Basedir = / app/mysql
User = mysql
Server-id=2
[client]
Port = 3307
Socket = / mysql/slave/mysql.sock
[mysql]
No-auto-rehash
# chown-R mysql. / mysql/slave
# # starting mysql
# mysqld_safe-- defaults-file=/mysql/slave/my.cnf &
# netstat-nltpd | grep mysql
Tcp 0 0 0.0.0.0 3307 0.0.0.015 * LISTEN 62750/mysqld
Tcp 0 0 0.0.0.0 3306 0.0.0.015 * LISTEN 62462/mysqld
4. From library change master
# # connecting the slave library to the master library through vip
[root@master1] # mysql-uroot-p-S / mysql/slave/mysql.sock
Mysql > change master to
Master_host='192.168.12.1'
Master_port=3306
Master_user='rep'
Master_password='123456'
Mysql > start slave
Mysql > show slave status\ G
# # testing Master-Slave synchronization
[root@master1] # mysql-uroot-p111111-S / data/master/mysql.sock
Mysql > create database shaw_db
Mysql > create table shaw_db.t_user as select * from mysql.user
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0
# # viewing data from the database
Mysql > show databases like 'shaw%'
+-+
| | Database (shaw%) |
+-+
| | shaw_db |
+-+
Mysql > select count (*) from shaw_db.t_user
+-+
| | count (*) |
+-+
| | 7 |
+-+
# # Note here why 3 pieces of data are inserted in the main library and 7 pieces of data are inserted from the library, because the master database data is directly synchronized by change master after initialization from the slave library, and the data in the user table in the mysql library is not cleaned up, so the query data will be more than the main database.
Mysql > select user,host from shaw_db.t_user
+-+ +
| | user | host |
+-+ +
| | root | localhost |
| | root | master1 |
| | root | 127.0.0.1 | |
| | root |:: 1 |
| | localhost |
| | master1 |
| | rep | 192.168.12.% | |
+-+ +
7 rows in set (0.00 sec)
5. Switch the high availability of the master library to view the status of the slave library
# # currently, the main library is on master1. Switch ha to master2.
[root@master1 ~] # / etc/init.d/heartbeat stop
# # at this point, the master database has been switched to master2 to view the current slave library status
Mysql > show slave status\ G
* * 1. Row *
Slave_IO_State: Reconnecting after a failed master event read
Master_Host: 192.168.12.1
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 537
Relay_Log_File: mysql-relay-bin.000003
Relay_Log_Pos: 683
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Connecting
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: 537
Relay_Log_Space: 985
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2003
Last_IO_Error: error reconnecting to master 'rep@192.168.12.1:3306'-retry-time: 60 retries: 86400
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
# # after waiting for 60s, the slave library is automatically synchronized with master2
Mysql > show slave status\ G
* * 1. Row *
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.12.1
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 107
Relay_Log_File: mysql-relay-bin.000005
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000003
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: 555
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)
# # create some tables on master2 to see if they can be synchronized to the slave library
[root@master2] # mysql-uroot-p111111-S / data/master/mysql.sock
Mysql > use shaw_db
Mysql > create table t_zhong (id int,name varchar (20))
Mysql > insert into t_zhong values (1), (2)), (3))
# # viewing data from the database
Mysql > select * from shaw_db.t_zhong
+-+ +
| | id | name |
+-+ +
| | 1 | test |
| | 2 | test2 |
| | 3 | test3 |
+-+ +
7. The problem of highly available brain fissure and its solution 7.1 causes of brain fissure
1. Heartbeat links between highly available servers fail, making it impossible to check each other's heartbeats
2. The firewall is turned on on the highly available server, which blocks heartbeat detection.
3. The information such as the address of the network card on the highly available server is not configured properly, which leads to the failure of sending heartbeat.
4. Improper configuration of other services, such as different heartbeat mode, heartbeat broadcast conflict, software BUG, etc.
7.2 some programs to prevent brain fissure
1. Add redundant lines
2. Forcibly turn off heartbeat detection when brain cleft is detected (turn off the master node remotely and control the power circuit fence)
3. Do a good job of monitoring and alarm of brain fissure.
4. After the alarm, the backup node sets a long time to take over when it takes over, giving the operation and maintenance personnel enough time to deal with it (artificial processing)
5. Start the disk lock, and the service party is locking the disk. When a brain crack occurs, the other party can not snatch the "shared disk resources" at all.
Problems with disk locks:
There will be a deadlock problem when using locked disks. If the one who occupies the shared disk does not take the initiative to "unlock" the other, the other will never get the shared disk. If the server node suddenly crashes or crashes, it will be impossible to execute the unlock command, and the standby node will not be able to take over the resources and services. Someone has designed the intelligent lock in HA, and the service provider will enable the disk lock only when the heartbeat is completely disconnected. It's usually unlocked.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.