Mysql DBA Advanced Operations Learning Note-heartbeat installation and configuration of highly available software

Source: Internet
Author: User
Tags dba md5 sha1 iptables

2. Deploy heartbeat high-availability requirements 2.1 operating systems

Centos-6.8-x86_64

2.2 Heartbeat Service Host resource preparation

Primary Server A:

Host Name: heartbeat-1-130

Eth0 Network card Address: 192.168.1.130 (Management IP)

ETH1 Network card address: 10.0.10.4 (Heartbeat IP)

From Server B:

Host Name: heartbeat-1-129

Eth0 Network card Address: 192.168.1.129 (Management IP)

ETH1 Network card address: 10.0.10.5 (Heartbeat IP)

Virtual VIP:

Virtual VIP on the master server heartbeat-1-130

vip:192.168.1.131

3.Heartbeat High Availability Implementation 3.1 build virtual reality environment

Cloning two virtual machines

3.2 Configuring IP and host names for virtual machines

Configuring the IP and hostname is omitted
The host names of the hosts that set up two machines are heartbeat-1-130 and heartbeat-1-129, respectively.
Compile the/etc/sysconfig/network configuration file for two machines separately, setting up hostname=heartbeat-1-130 and hostname=heartbeat-1-129.
The hostname heartbeat-1-130 and hostname heartbeat-1-129 are then executed at the command line to make the settings take effect immediately.
Tip: You can execute the Setup command and then select the network configuration-->edit configuration to configure the machine name, and then logout exit to log back in to take effect.

3.3 Configuring the Hosts file (two nodes to do)

Configuring the Hosts file on the heartbeat-1-130 host

[[email protected] ~]# cat >>/etc/hosts<<eof> 192.168.1.129 heartbeat-1-129> 192.168.1.130 heartbeat-1-130> eof

Configuring the Hosts file on the heartbeat-1-129 host

[[email protected] ~]# cat >>/etc/hosts<<eof> 192.168.1.129 heartbeat-1-129> 192.168.1.130 heartbeat-1-130> eof

Check the test by pinging the IP address to see if the IP returned is consistent with the content configured in/etc/hosts.

Special emphasis: Machine name must be the result of Uname–n return

[[email protected] ~]# uname -nheartbeat-1-130

Hint: The configuration of the hosts will be used in the heartbeat service, then the DRBD and storage high availability will also be used, in the production environment will be all machine name corresponding to all the machine IP address, and then through Cfengine or puppet or sshkey+ The Rsync tool is distributed to all machines. When a machine is added to the network, it is distributed uniformly to all machines/etc/hosts through the distribution tool.

3.4 Configuring a heartbeat connection between services

Eth1 10.0.10.5 and eth1 10.0.10.4 two network card between the connection through the ordinary network cable, that is, not through the switch, directly with a network cable will be connected with two network cards, for heartbeat detection or data transmission.

Tip: The heartbeat software on the high-availability server pair will use this Heart jumper to check if the machine on the end is alive, and then decide whether to do failover or resource switching to ensure business continuity.
If the conditions allow, the above connection can be used at the same time to increase the safety factor to prevent the occurrence of split brain problems.

This case: the use of Ethernet cable two network cards directly connected.

Selection reason: Simple, easy to deploy, the effect is good.

Add a host route on both machines to enable two machines to check the peer through the heartbeat line.

(1) Add the following host routes on HEARTBEAT-1-130 server:

/sbin/route route add -host 10.0.10.4 dev eth1

Again, this command makes 10.0.10.4 accessed from the heartbeat-1-130 Server, and goes out with the eth1 card, that is, using the heartbeat line.

echo ‘/sbin/route route add -host 10.0.10.4 dev eth1‘>>/etc/rc.local

Join the boot-up configuration so that the configuration of this route is automatically loaded when it is started.

(2) Add the following host routes on heartbeat-1-129 server:

/sbin/route route add -host 10.0.10.5 dev eth1

Again, this command makes 10.0.10.5 Accessed from the heartbeat-1-129 Server, and goes out with the eth1 card, that is, using the heartbeat line.

echo ‘/sbin/route route add -host 10.0.10.5 dev eth1‘>>/etc/rc.local

Join the boot-up configuration so that the configuration of this route is automatically loaded when it is started.
You can view the configured route status with Route–n

3.5 Configuring the Virtual VIP

Configure the virtual VIP on heartbeat-1-130 on the primary server

[[email protected] ~]# echo ‘ifconfig eth0:1 192.168.1.131 netmask 255.255.255.0 up‘ >>/etc/rc.local[[email protected] ~]# echo ‘route add -host 192.168.1.131 dev eth0:1‘ >>/etc/rc.local
3.6 Shutting down the firewall and SELinux (two nodes to operate)

Close Iptables

iptables -Fservice iptables saveservice iptables stop

Turn off SELinux

setenforce 0sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
3.7 Installing centos-6.8-x86_64 heartbeat3.0 Software

centos-6.8-x86_64 RPM package does not have heartbeat software, so to download the Epel package

[[email protected] ~]# yum search heartbeat已加载插件:product-id, subscription-managerThis system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.rhel-local   | 4.1 kB 00:00 ... 警告:没有匹配 heartbeat 的软件包没有找到匹配的软件包
3.8 Download and install the Epel extension Source (two units to operate)
mkdir -p /home/linzhongniao/toolscd /home/linzhongniao/toolswget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -ivh  epel-release-6-8.noarch.rpmrpm -qa|grep epel
3.9 Installing the heartbeat (two units to operate)
yum install heartbeat* -y
3.10 Primary node Configuration heartbeat service

Centos5.8 machine, after performing the Yum install heartbeat*–y two times, no accident can install the heartbeat software.
As mentioned earlier, the default profile directory for heartbeat is/ETC/HA.D. Heartbeat commonly used configuration file has three, ha.cf, Authkey, Haresource, the respective functions see the table below.

Tip: If Yum wants to keep the RPM package after installation, use the following method.

[[email protected] ~]# sed -i ‘s#keepcache=0#keepcache=1#g‘ /etc/yum.conf [[email protected] ~]# grep keepcache /etc/yum.conf keepcache=1
3.10.1 configuration ha.cf file and file description

(1) ha.cf haresources Authkeys The first of these three files copied to the/etc/ha.d/directory

[[email protected] ~]# ll /usr/share/doc/heartbeat-3.0.4/总用量 144 -rw-r--r-- 1 root root  1873 12月  3 2013 apphbd.cf -rw-r--r-- 1 root root   645 12月  3 2013 authkeys -rw-r--r-- 1 root root  3701 12月  3 2013 AUTHORS -rw-r--r-- 1 root root 58752 12月  3 2013 ChangeLog -rw-r--r-- 1 root root 17989 12月  3 2013 COPYING -rw-r--r-- 1 root root 26532 12月  3 2013 COPYING.LGPL -rw-r--r-- 1 root root 10502 12月  3 2013 ha.cf -rw-r--r-- 1 root root  5905 12月  3 2013 haresources -rw-r--r-- 1 root root  2935 12月  3 2013 README[[email protected] ~]# cd /usr/share/doc/heartbeat-3.0.4/[[email protected] heartbeat-3.0.4]# lsapphbd.cf  authkeys  AUTHORS  ChangeLog  COPYING  COPYING.LGPL  ha.cf  haresources  README[[email protected] heartbeat-3.0.4]# cp ha.cf haresources authkeys /etc/ha.d/

(2) Configuring the HA.CF configuration file

[[email protected] ~]# cat /etc/ha.d/ha.cf debugfile /var/log/ha-debuglogfile/var/log/ha-loglogfacility local0keepalive 2deadtime 30warntime 10initdead 60#bcast  eth1mcast eth1 225.0.0.130 694 1 0#udpport 694#ucast eth1 10.0.10.5 auto_failback onnode  heartbeat-1-130node  heartbeat-1-129ping 10.0.10.8respawn hacluster /usr/lib64/heartbeat/ipfail#crm on

(3) Detailed description of the ha.cf file

Debugfile/var/log/ha-debug: This file holds debug information for heartbeat.

The Logfile/var/log/ha-log:heartbeat log file.

KeepAlive 2: The time interval of the heartbeat, the default time in seconds S.

Deadtime 30: The heartbeat of the other node is not received at this time interval, the other party is considered dead.

Warntime 10: A warning is issued and recorded in the log when the heartbeat of the other node is not received at that interval.

Initdead 60: On a system, the system starts or restarts after a period of time network to work properly, this option is used to resolve the time interval generated, at least twice times the value of Deadtime.

Mcast eth1 225.0.0.130 694 1 0: Set the port used for broadcast communication, 225.0.0.130 for multicast IP address in a LAN this IP address cannot be the same, 694 is the port number used by default.

Note: A LAN has multiple sets of heartbeat services at the same time normal use of the premise is the multicast address is different (optional multicast address segment is 224.0.0.0-239.255.255.255), general routers, switches, etc. should be multicast way, The last eight bits of the IP are recommended as the last 8 bits of the multicast address. Of course, no multicast can solve the heartbeat problem.

Udpport 694: Set the port used for broadcast communication and 694 is the default port number.

Ucast eth1 10.0.10.4: Sets the network card and IP for the heartbeat detection of the other machine.

The two hosts of the Auto_failback On:heartbeat are primary nodes and slave nodes respectively. The primary node consumes resources and runs all services under normal circumstances, and when it encounters a failure, it transfers the resources to the slave node to run the service. When the option is set to ON, once the master node resumes running, the resource is automatically fetched and replaced from the node, otherwise it is not replaced by the slave node.

Respawn Heartbeat/usr/lib/heartbeat/ipfail: Specifies the process that is started and closed with heartbeat, which is automatically monitored and restarted if a failure occurs. The most commonly used process is ipfail, which is used to detect and handle network failures and to detect network connections with ping node specified by the ping statement. If your system is 64bit, be aware of the path to the file.

CRM on whether to turn on Cluster Resource Manager (cluster resource management feature)

Tip: We can look at ha.cf under/usr/share/doc/heartbeat-3.0.4/to learn more about parameter information.

3.10.2 configuration Authkey file and file description

(1) Configuring the Authkey file

[[email protected] ~]# cat /etc/ha.d/authkeys auth 33 md5 Hello!

Modify Authkey permissions to 600

[[email protected] ~]# chmod 600 /etc/ha.d/authkeys[[email protected] ~]# ll /etc/ha.d/authkeys -rw------- 1 root root 20 3月   3 07:39 /etc/ha.d/authkeys

(2) Parameter description

此处提到authkey权限必须为600#   Authentication file.  Must be mode 600#   Must have exactly one auth directive at the front.#   authsend authentication using this method-id##   Then, list the method and key that go with that method-id此处提到可以设置认证方法#   Available methods: crc sha1, md5.  Crc doesn‘t need/want a key.#   You normally only have one authentication method-id listed in this file#   Put more than one to make a smooth transition when changing auth#   methods and/or keys.这里说明sha1是最好的认证方法,其次md5是最好的#   sha1 is believed to be the "best", md5 next best.#   crc adds no security, except from packet corruption.#   Use only on physically secure networks.#auth 1#1 crc#2 sha1 HI!#3 md5 Hello!默认的配置使用crc方法这是不加密的最不安全的,下面为authkey生产配置##########

Note that the permissions required by the Authkeys default to 600 otherwise the heartbeat service will be error-open, both machines need to operate

3.10.3 Configuring Haresource Files
[[email protected] ~]# cat /etc/ha.d/haresources heartbeat-1-130 IPaddr::192.168.1.131/24/eth0:1

Configuration parameter Description: heartbeat-1-130 the primary node hostname,192.168.0.131 to vip,24 as the Mask 24 network segment, eth0:1 the device name for the VIP. IPAddr the default script for configuring IP for Heartbeat, followed by IP, etc. are script parameters.

[[email protected] ~]# ll /etc/ha.d/resource.d/IPaddr -rwxr-xr-x 1 root root 2273 12月  3 2013 /etc/ha.d/resource.d/IPaddr

This is actually equivalent to a script pass, equivalent to executing:

/etc/ha.d/resource.d/IPaddr 192.168.1.131/24/eth0:1 stop/start
3.11 Configuring the Heartbeat service from the node 3.11.1 copy the three configuration files on the master node to the slave node
cd /etc/ha.dscp authkeys ha.cf haresources heartbeat-1-129:/etc/ha.d

All of the configuration files in production are SVN change-over and then released to both machines, and can be synchronized with SCP.

3.11.2 Configuring HA.CF Files

From the node only need to modify the place below the ha.cf file

Mcast eth1 225.0.0.129 694 1 0

Change 255.0.0.130 to 255.0.0.129

Above is the way of multicasting, if you need to modify the following in the broadcast way.

Ucast eth1 10.0.10.5

Change Ucast eth1 10.0.10.5 to Ucast eth1 10.0.10.4

4. Start the Heartbeat service

Start the primary node after starting the slave node

[[email protected] ~]# /etc/init.d/heartbeat startStarting High-Availability services: INFO:  Resource is stoppedDone.
5. Test Heartbeat Service

The primary node stops the heartbeat service or the eth1 NIC is down

/etc/init.d/heartbeat stop

We will find that the virtual VIP switch to the slave node, to achieve heartbeat high-availability features continue to provide services to users.

6. Test the column Brain

Both nodes are down eth1 NIC

Ifdown eth1

7. View the process of heartbeat startup and takeover of resources

You can view heartbeat logs and system logs to see the process of heartbeat starting and taking over resources

Tail-f/var/log/ha-log

Tail-f/var/log/messages

Mysql DBA Advanced Operations Learning Note-heartbeat installation and configuration of highly available software

Related Article

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.