In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to build LVS+Keepalived+MySQL". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build LVS+Keepalived+MySQL.
LVS is responsible for forwarding requests from load balancers, and keepalived is responsible for checking the realserver status of LVS and timely remove failure nodes and add resurrection nodes.
This lab focuses on functional testing, so only two MySQL servers are prepared for simple explanation.
Vm1 10.0.0.11 master server_id 11
Vm2 10.0.0.12 slave server_id 12
Director:
Vm3 10.0.0.14
VIP: 10.0.0.20
1 install ipvsadm and keepalived on Directory server vm3
Yum install ipvsadm
Install keepalived
Yum install libnfnetlink*
Tar-zxvf keepalived-1.2.7.tar.gz
. / configure-- prefix=/usr/local/keepalived
Make & & make install
Cp / usr/local/keepalived/sbin/keepalived / usr/sbin/
Cp / usr/local/keepalived/etc/sysconfig/keepalived / etc/sysconfig/
Cp / usr/local/keepalived/etc/rc.d/init.d/keepalived / etc/init.d/
Mkdir / etc/keepalived
On vm1 vm2, do the following.
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
Ifconfig lo:0 10.0.0.20 netmask 255.255.255.255
3. Edit the / etc/keepalived/keepalived.conf file on Directory server vm3, as follows:
Click (here) to collapse or open
Global_defs {
Router_id HaMySQL_1
}
Vrrp_sync_group VGM {
Group {
VI_MYSQL
}
}
Vrrp_instance VI_MYSQL {
State MASTER
Interface eth0
Virtual_router_id 100
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
10.0.0.20
}
}
Virtual_server 10.0.0.20 3306 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Protocol TCP
Nat_mask 255.255.255.0
Persistence_timeout 10
Real_server 10.0.0.11 3306 {
Weight 3
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
Connect_port 3306
}
}
Real_server 10.0.0.12 3306 {
Weight 3
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
Connect_port 3306
}
}
}
4 start MySQL and keepalived.
Vm1:
/ usr/local/mysql/bin/mysqld_safe-defaults-file=/data/mysql3306/my.cnf &
Vm2:
/ usr/local/mysql/bin/mysqld_safe-- defaults-file=/data/mysql3306/my.cnf
Vm3:
/ etc/init.d/keepalived start
5 Verification
Vm3:
[root@vm3 keepalived] # ipvsadm-Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.0.0.20:3306 rr persistent 2
-> 10.0.0.11 Route 3306
-> 10.0.0.12 Route 3306
You can see that the load balancer has been started and vm2 vm3 has been added.
Connect to VIP 10.0.0.20 from the client side 3306
C:\ mysql-5.7.11-winx64\ mysql-5.7.11-winx64\ bin > mysql.exe-uroot-pmysql-h20.0.0.20-P3306
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 90
Server version: 5.6.27-log Source distribution
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 > select @ @ server_id;exit
+-+
| | @ @ server_id |
+-+
| | 11 |
+-+
1 row in set (0.00 sec)
From the server_id, you can see that the client is connected to vm1.
Turn off the MySQL service on vm1.
[root@vm3 keepalived] # ipvsadm-Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.0.0.20:3306 rr persistent 2
-> 10.0.0.12 Route 3306
The LVS rules have been updated to remove the vm1 and connect from the client again.
C:\ mysql-5.7.11-winx64\ mysql-5.7.11-winx64\ bin > mysql.exe-uroot-pmysql-h20.0.0.20-P3306
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 61
Server version: 5.6.27-log Source distribution
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 > select @ @ server_id;exit
+-+
| | @ @ server_id |
+-+
| | 12 |
+-+
1 row in set (0.00 sec)
Restart the MySQL service on vm1.
[root@vm3 ~] # ipvsadm-Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.0.0.20:3306 rr persistent 2
-> 10.0.0.11 Route 3306
-> 10.0.0.12 Route 3306
The LVS rule has been automatically refreshed and the vm1 has been rejoined.
At this point, I believe you have a deeper understanding of "how to build LVS+Keepalived+MySQL", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.