Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve High availability with mycat

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to achieve high availability of mycat. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1 mycat cluster

Mycat can manage configuration files through zookeeper clusters.

1.1 set up zookeeper cluster

There is no explanation of zookeeper cluster building here.

1.2 configure mycat to support zookeeper

Modify myid.properties under mycat conf directory

LoadZk=true

# zk cluster addresses, separated by ","

ZkURL=192.162.3.31:2121192.162.3.32:2121192.162.3.33:2121

# Mycat Cluster ID in zk Cluster

ClusterId=mycat-cluster-1

# ID of this instance in the Mycat cluster. Repetition is prohibited.

Myid=mycat_fz_01

# number of nodes in Mycat cluster

ClusterSize=3

# id of all nodes in the cluster

ClusterNodes=mycat_fz_01,mycat_fz_02,mycat_fz_03

# server booster; booster install on db same server,will reset all minCon to 1

Type=server

BoosterDataHosts=dataHost1

1.3 Custom configuration

Replace the configuration file that needs to be modified to the zkconf directory in the conf directory. You only need to modify it on one machine. You need to note that the user name and password in the server.xml in the conf directory are not consistent with those in zkconf.

1.4 upload configuration

Execute the initzkdata.sh under the bin directory under the mycat where the configuration file is modified, and upload the configuration file (on the machine where the configuration file is modified)

. / initzkdata.sh

1.5 start all mycat

After startup, it is found that other configuration files under mycat conf have been automatically changed to modified contents, which are downloaded in zookeeper.

2 mycat High availability

The lvs+keepalived approach is used here

LVS+Keepalived introduction

LVS

LVS is the abbreviation of Linux Virtual Server, which means Linux virtual server, which is a virtual server cluster system. This project, founded by Dr. Zhang Wensong in May 1992, is one of the earliest free software projects in China. Currently, there are three IP load balancing technologies (VS/NAT, VS/TUN and VS/DR) and ten scheduling algorithms (rrr | wrr | lc | wlc | lblc | lblcr | dh | sh | sed | nq).

Keepalvied

Here, Keepalived is mainly used as the health check of RealServer and the implementation of failover between Master host and BackUP host.

Next, build a MyCAT high-availability load balancing cluster based on LVS+Keepalived, in which LVS implements MyCAT load balancing. however, a simple LVS cannot monitor the health of the back-end node, it only accesses the back-end service node based on the specific scheduling algorithm. At the same time, a single LVS has the risk of a single point of failure. Here, with the introduction of Keepalived, you can implement the following functions:

1. Check whether the back-end node is healthy.

two。 Achieve the high availability of LVS itself.

2.1 configure the environment

Role host IP hostname operating system version software version

VIP 192.162.3.200

LVS-DR-Master 192.162.3.41 keepalived01 CentOS6.9 Keepalived v1.2.13,LVS 1.2.1

LVS-DR-Backup 192.162.3.42 keepalived02 CentOS6.9 Keepalived v1.2.13,LVS 1.2.1

Mycat-Realserver 192.162.3.34 mycat01 CentOS6.9 mycat v1.6.5

Mycat-Realserver 192.162.3.35 mycat02 CentOS6.9 mycat v1.6.5

Mycat-Realserver 192.162.3.36 mycat03 CentOS6.9 mycat v1.6.5

2.2 install keepalived and ipvsadm

Note: ipvsadm is not lvs, it's just a configuration tool for lvs, because lvs is supported by default in 3.10 (the kernel version of CentOS1.1). So there is no need to reinstall it here.

For convenience, we use yum installation here

Install keepalived and ipvsadm on keepalived01 and keepalived02 hosts, respectively

Yum install-y keepalived ipvsadm

In addition to this easy way, you can also compile the official source package directly.

LVS:

Keepalived:

For installation steps, please refer to:

2.3 configure Keepalived

2.3.1 master

Vi / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Notification_email {

Acassen@firewall.loc # sets the alarm email address, which can be set up more than one per line.

Failover@firewall.loc # needs to enable the local sendmail service

Sysadmin@firewall.loc

}

Notification_email_from Alexandre.Cassen@firewall.loc # sets the sending address of the mail

Smtp_server 121.0.0.1 # set smtp server address

Smtp_connect_timeout 30 # sets the timeout for connecting to smtp server

Router_id LVS_DEVEL # represents an identity of the running keepalived server. The information displayed in the subject of the message when sending an email

}

Vrrp_instance VI_1 {

State MASTER # specifies the role of keepalived. MASTER indicates that this host is the primary server, and BACKUP indicates that this host is the standby server.

Interface eth5 # specifies the interface of the HA monitoring network, and the name of the network interface that can be seen through ifconfig or ip add

Virtual_router_id 51 # virtual routing identity, which is a number, and the same vrrp instance uses a unique identity. That is, under the same vrrp_instance, MASTER and BACKUP must be consistent.

Priority 100# defines priority. The larger the number, the higher the priority. Under the same vrrp_instance, the priority of MASTER must be greater than that of BACKUP.

Advert_int 1 # sets the time interval (in seconds) for synchronization checks between MASTER and BACKUP load balancers

Authentication {# set authentication type and password

Auth_type PASS # sets the verification type, mainly including PASS and AH

Auth_pass 1111 # sets the authentication password. Under the same vrrp_instance, MASTER and BACKUP must use the same password in order to communicate normally.

}

Virtual_ipaddress {# set virtual IP addresses. You can set multiple virtual IP addresses, one per line

192.162.3.200

}

}

Virtual_server 192.162.3.200 2066 {# to set up a virtual server, you need to specify a virtual IP address and a service port. The IP and the port are separated by a space.

Delay_loop 6 # sets the running check time (in seconds)

Lb_algo rr # sets the load scheduling algorithm. Here it is set to rr, that is, polling algorithm.

Lb_kind DR # sets the mechanism of LVS to achieve load balancing. There are three modes: NAT, TUN and DR.

Nat_mask 255.255.255.0

Persistence_timeout 50 # session duration in seconds. This option is very useful for dynamic web pages and provides a good solution for session sharing in cluster systems. If set to 0, polling is performed to achieve load balancing. Setting a number means that iphash is used within the specified implementation.

With this session persistence feature, the user's request will be distributed to a service node until the duration of the session is exceeded.

# it should be noted that the session persistence time is the maximum unresponsive timeout, that is, if the user does not perform any action within 50 seconds when operating the dynamic page

# then the next operation will be distributed to another node, but if the user has been operating the dynamic page, it will not be subject to a time limit of 50 seconds

Protocol TCP # specifies the type of forwarding protocol, including TCP and UDP

Real_server 192.162.3.34 2066 {# configure service node 1, you need to specify the real IP address and port of the real server, and the IP and the port are separated by a space

Weight 1 # configures the weights of the service node. The weights are represented by numbers. The larger the number, the higher the weights. The weights can be set for servers with different performance.

# by allocating different loads, you can set higher weights for servers with high performance and relatively low weights for servers with lower performance, so that system resources can be used and allocated reasonably

Status detection setting section of TCP_CHECK {# realserver (in seconds)

Connect_timeout 3 # indicates a 3-second no response timeout

Nb_get_retry 3 # indicates the number of retries

Delay_before_retry 3 # indicates the retry interval

Connect_port 2066

}

}

Real_server 192.162.3.35 2066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 2066

}

}

Real_server 192.162.3.36 2066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 2066

}

}

}

2.3.2 backup

Modify the same file on the backup machine, except for priority and status modification, other than the same as the host

! Configuration File for keepalived

Global_defs {

Notification_email {

Acassen@firewall.loc

Failover@firewall.loc

Sysadmin@firewall.loc

}

Notification_email_from Alexandre.Cassen@firewall.loc

Smtp_server 121.0.0.1

Smtp_connect_timeout 30

Router_id LVS_DEVEL

}

Vrrp_instance VI_1 {

State BACKUP # change state from MASTER to BACKUP

Interface eth5

Virtual_router_id 51

Priority 99 # modify priority

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

192.162.3.200

}

}

Virtual_server 192.162.3.200 2066 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.162.3.34 2066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 2066

}

}

Real_server 192.162.3.35 2066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 2066

}

}

Real_server 192.162.3.36 2066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 2066

}

}

}

In the above two configuration files, there is one place to pay particular attention to, that is, interface, the relevant deployment documents on the Internet are eth0, before CentOS1, the network interface is indeed eth0, but in CentOS1, the interface is eno16111136. Therefore, it is necessary to make corresponding modifications according to the actual production situation.

2.4 install and configure mycat

Please refer to the above for installation

2.4.1 bind virtual vip

Bind VIP addresses for lo:0 and suppress ARP broadcasts on MyCAT servers

Execute the following script on the three hosts of mycat01 and mycat02,mycat03, named realserver.sh here, and create and copy the following

If an error occurs that the file or directory cannot be found, execute yum-y install net-tools first

#! / bin/bash

# description: Config realserver

# here the ip is the same as the previously configured virtual ip

VIP=192.162.3.200

/ etc/rc.d/init.d/functions

Case "$1" in

Start)

/ sbin/ifconfig lo:0$ VIP netmask 255.255.255.255 broadcast $VIP

/ sbin/route add-host $VIP dev lo:0

Echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce

Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce

Sysctl-p > / dev/null 2 > & 1

Echo "RealServer Start OK"

Stop)

/ sbin/ifconfig lo:0 down

/ sbin/route del $VIP > / dev/null 2 > & 1

Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_ignore

Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_announce

Echo "0" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "0" > / proc/sys/net/ipv4/conf/all/arp_announce

Echo "RealServer Stoped"

*)

Echo "Usage: $0 {start | stop}"

Exit 1

Esac

Exit 0

Execute. / realserver.sh start on the machine respectively.

2.4.2 View

Run ifconfig to view

2.5 start keeplive

Start the Keepalived service on keepalived01 and keepalived02, respectively

Service keepalived start

2.5.1 View

Looking at the mapping through ipvsadm-L, there is a similar result, which is successful in theory.

[root@192] # ipvsadm-L

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

TCP 192.162.3.200:2066 rr persistent 50

-> 192.162.3.34 Route 2066 0 0

-> 192.162.3.35 Route 2066 0 0

-> 192.162.3.36 Route 2066 0 0

2.5.2 Test

Connect to our virtual ip through a machine with mysql and find that you can log in to the database

[root@192 network-scripts] # mysql-uroot-pdigdeep-P2066-h292.162.3.200

Mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 301

Server version: 5.6.29-mycat-1.6.5-release-20120122220033 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

Mysql >

2.5.3 View forwarding

Execute ipvsadm-L on keepalived's machine again and find that it was transferred to 35 once.

[root@192] # ipvsadm-L

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

TCP 192.162.3.200:2066 rr persistent 50

-> 192.162.3.34 Route 2066 0 0

-> 192.162.3.35 Route 2066 1 0 1

-> 192.162.3.36 Route 2066 0 0

[root@192 ~] #

2.5.4 load balancing mode

Related to configuration, it is found here that multiple times point to a machine, because the persistence_timeout attribute specified as 50 in the configuration file of keepalived means that requests from the same machine within 50 seconds will be allocated consistently by hash. If you want to achieve polling in the strict sense, you can change it to 0.

[root@192] # ipvsadm-L

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

TCP 192.162.3.200:2066 rr persistent 50

-> 192.162.3.34 Route 2066 0 0

-> 192.162.3.35 Route 2066 1 1 3

-> 192.162.3.36 Route 2066 0 0

[root@192 ~] #

This is the end of the article on "how to achieve high availability of mycat". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report