7, based on the mechanism of HA HA --mycat Mycat

In a real project, Mycat services also need to consider high availability, if Mycat where the server goes down, or Mycat service
Service failure, the need for equipment supplies services, need to be considered Mycat cluster.
 

1, high availability solutions

Use HAProxy + Keepalived with two Mycat put Mycat clusters for high availability.
HAProxy achieve a multi-node cluster MyCat of high availability and load balancing
HAProxy own high availability can be achieved by Keepalived.
 

 

 

 

Roles ip
mycat01 192.168.199.217
mycat02 192.168.199.120
HA (primary) 192.168.199.174
keepalive (host) 192.168.199.174
HA (primary) 192.168.199.199
keepalive (Host 192.168.199.199

 

First configured mycat and start mycat

 

2 installation configuration HAProxy

1, the installation HAProxy

 
 
2 to extract the / usr / local / src

 

3 after entering the decompression directory, core edition, compiled

[root@mycat05 software]# cd /usr/local/src/haproxy-1.5.18/
[root@mycat05 haproxy-1.5.18]# uname -r
3.10.0-957.el7.x86_64
[root@mycat05 haproxy-1.5.18]# make TARGET=linux310 PREFIX=/usr/local/haproxy ARCH=x86_64

# ARGET = linux310, kernel version, use uname -r kernel view, such as: 3.10.0-957.el7, at this time it is the parameter linux310;
# ARCH = x86_64, system-digit;
# PREFIX = / usr / local / haprpxy # / usr / local / haprpxy, as haprpxy installation path.

 

4 compiled, installed
make install PREFIX=/usr/local/haproxy

 

After the installation is complete, create a directory, create a profile HAProxy
mkdir -p /usr/data/haproxy/
vim /usr/local/haproxy/haproxy.conf

 

6 Insert the following configuration information to the configuration file, and save
global
 log 127.0.0.1 local0
 #log 127.0.0.1 local1 notice
 #log loghost local0 info
 maxconn 4096
 chroot /usr/local/haproxy
 pidfile /usr/data/haproxy/haproxy.pid
 uid 99
 gid 99
 daemon
 #debug
 #quiet
defaults
 log global
 mode tcp
 option abortonclose
 option redispatch
 retries 3
 maxconn 2000
 timeout connect 5000
 timeout client 50000
 timeout server 50000
listen proxy_status 
bind :48066
 mode tcp
 balance roundrobin
 server mycat_1 192.168.140.128:8066 check inter 10s
 server mycat_2 192.168.140.127:8066 check inter 10s
frontend admin_stats 
bind :7777
 mode http
 stats enable
 option httplog
 maxconn 10
 stats refresh 30s
 stats uri /admin
 stats auth admin:123123 //登陆账户and密码
 stats hide-version
 stats admin if TRUE

 

2, boot authentication

1 Start HAProxy
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.conf

 

2 View HAProxy process
ps -ef|grep haproxy

 

3 Open a browser to access

 

 

If Mycat standby machine have been activated, as can be seen in FIG.

 

 

 

 

4 Verify load balancing, access Mycat by HAProxy

Execution (192.168.199.174HA host address) on the host HAProxy

[root@mycat05 haproxy-1.5.18]# mysql -umycat -p123456 -h 192.168.199.174 -P 48066

 

 

 

 

3 Configuration Keepalived 

Download: https://www.keepalived.org/software/

1 Ready Keepalived installation package, reached the / opt directory under 

 

2 to extract the / usr / local / src
tar -zxvf keepalived-1.4.2.tar.gz -C /usr/local/src

 

3 Installation depends plug
yum install -y gcc openssl-devel popt-devel

 

4 into the unpacked directory, configure, compile
cd /usr/local/src/keepalived-1.4.2
./configure --prefix=/usr/local/keepalived
 
5 compiled, installed after the completion of
make && make install
 
 
Before running configuration 6
cp /usr/local/src/keepalived-1.4.2/keepalived/etc/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/src/keepalived-1.4.2/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ 
 
7修改配置文件
vim /etc/keepalived/keepalived.conf 
#修改内容如下
! Configuration File for keepalived
global_defs {
 notification_email {
 [email protected]
 }
 notification_email_from [email protected]
 smtp_server 127.0.0.1
 smtp_connect_timeout 30
 router_id LVS_DEVEL
 vrrp_skip_check_adv_addr
 vrrp_garp_interval 0
 vrrp_gna_interval 0
}
vrrp_instance VI_1 {
 #主机配MASTER,备机配BACKUP
state MASTER
#所在机器网卡
 interface ens33
virtual_router_id 51
#数值越大优先级越高
 priority 100
 advert_int 1
 authentication {
 auth_type PASS
 auth_pass 1111
 }
virtual_ipaddress {
#虚拟IP
 192.168.199.111
 } }
virtual_server 192.168.199.111 48066 {
 delay_loop 6
 lb_algo rr
 lb_kind NAT
 persistence_timeout 50
 protocol TCP
 real_server 192.168.199.174 48066 { # HA的地址(主机)
 weight 1r
 TCP_CHECK {
 connect_timeout 3
 retry 3
 delay_before_retry 3
 } }
real_server 192.168.199.199 48600 {#HA地址(备机r)
 weight 1
 TCP_CHECK {
 connect_timeout 3
 nb_get_retry 3
 delay_before_retry 3
 }
 } }

 

8、启动Keepalived

同时启动备机上的HA

service keepalived start 
 
 
9、登录验证
mysql -umycat -p123456 -h 192.168.199.111 -P 48066 
192.168.199.111 :虚拟ip

 

 

 
 
此时是:
HA隐藏mycat的ip
KeepAlive隐藏HA的ip
 

4 测试高可用 

1关闭mycat 
 
 
2通过虚拟ip查询数据
mysql -umycat -p123456 -h 192.168.199.111 -P 48066 
 
mysql> select * from orders;
ERROR 2013 (HY000): Lost connection to MySQL server during query

mysql
> select * from orders; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 2 Current database: TESTDB +--------+------------+-------------+-----------+ | id | order_type | customer_id | amount | +--------+------------+-------------+-----------+ | 1 | 101 | 100 | 100100.00 | | 2 | 101 | 100 | 100300.00 | | 6 | 102 | 100 | 100020.00 | | 3 | 101 | 101 | 120000.00 | | 4 | 101 | 101 | 103000.00 | | 5 | 102 | 101 | 100400.00 | | 400100 | 102 | 101 | 1000.00 | | 400101 | 102 | 101 | 1000.00 | +--------+------------+-------------+-----------+ 8 rows in set (1.46 sec)

Guess you like

Origin www.cnblogs.com/Mrchengs/p/12307087.html