(I) actual environment
| Server Name · |
IP |
OS |
MySQL |
| Odd.example.com |
192.168.1.116 |
RHEL-5.8 |
5.5.16 |
| Even.example.com |
192.168.1.115 |
RHEL-5.8 |
5.5.16 |
(Ii) advantages and disadvantages of the Solution
Advantages
● The installation and configuration are simple, easy to implement, and highly available, and can be switched based on the availability of services and systems
● You can set the write VIP and read VIP respectively to prepare for read/write splitting.
● Multiple slave servers can be added to the backend to achieve load balancing.
Disadvantages
● After startup or restoration, the defined sorry_server will be replaced immediately
Therefore, if you want to replace or not replace the specified conditions, you must use other methods, such as temporarily changing the MySQL port.
● Expansion is not very convenient
● Switching takes about 1 s
(Iii) applicable scenarios
This solution is applicable when only two database servers are used and the database read/write splitting is not implemented. VIP is configured for both read and write operations.
This solution facilitates the management, maintenance, and switchover of a single database.
For example, it is very convenient to modify the table structure of a large table and upgrade the database.
(Iv) solution architecture
(V) deployment steps
(1) install MySQL
Please refer to one of my previous articles: MySQL 5.5 three major installation methods: [binary, source code compilation and RPM package] installation steps and comparison of advantages and disadvantages
(2) MySQL master/Master synchronization Configuration
Please refer to my previous article. HA: MySQL master/Master synchronization Configuration
(3) LVS Installation
In odd even:
# Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
# Ln-S/usr/src/kernels/2.6.18-308. el5xen-i686 // usr/src/Linux
# Tar-zxv-F ipvsadm-1.24.tar.gz
# Cd ipvsadm-1.24
# Make
# Make install
(4) install keepalived
In odd even:
# Wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
# Tar-zxv-F keepalived-1.1.19.tar.gz
# Cd keepalived-1.1.19
#./Configure -- prefix =/usr/local/keepalived
# Make
# Make install
# Cp/usr/local/keepalived/sbin/keepalived/usr/sbin/
# Cp/usr/local/keepalived/etc/sysconfig/
# Cp/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/
# Mkdir/etc/keepalived
⑸ Keepalived Configuration
In odd
global_defs { notification_email { linwaterbin@gmail.com } notification_email_from bychjzh@gmail.com smtp_server smtp.gmail.com smtp_connect_timeout 30 router_id LVS1} vrrp_sync_group test {group { loadbalance}} vrrp_instance loadbalance { state BACKUP interface eth0 lvs_sync_daemon_inteface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111} virtual_ipaddress { 192.168.1.128 dev eth0 label eth0:1}} virtual_server 192.168.1.128 3306 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 20 protocol TCP sorry_server 192.168.1.115 3306 real_server 192.168.1.116 3306 { weight 3 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 3306}}}
In even:
Most of them are the same as odd, with only two points:
● State backup
● Priority 150
Realsever configuration of movie odd even
On odd even
#!/bin/bash# description: Config realserver lo and apply noarp SNS_VIP=192.168.1.128/etc/rc.d/init.d/functionscase "$1" in start) ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP /sbin/route add -host $SNS_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) ifconfig lo:0 down route del $SNS_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 1esacexit 0
Enable keepalived and realsever
In the odd even
#/Etc/rc. d/init. d/RealServer. Sh start
#/Etc/rc. d/init. d/keepalived start
# Echo "/etc/rc. d/init. d/RealServer. Sh start">/etc/rc. Local
# Echo "/etc/rc. d/init. d/keepalived start">/etc/rc. Local
The configuration is almost done here. Next let's take a look at the test.
(Vi) Simple Test
Stop the odd MySQL server and check whether it can be automatically switched to sorry_server.
Before stopping: [root @ odd keepalived] # ipvsadm-lnip virtual server version 1.2.1 (size = 4096) prot localaddress: Port sched1_flags-> remoteaddress: port forward weight activeconn inactconntcp 192.168.1.128: 3306 RR persistent 20-> 192.168.1.116: 3306 local 3 0 0 stop: [MySQL @ odd ~] $ Mysqladmin shutdown130508 00:53:50 mysqld_safe mysqld from PID file/home/MySQL/data/odd.example.com. after PID ended [1] + done mysqld_safe is stopped: [root @ odd keepalived] # ipvsadm-lnip virtual server version 1.2.1 (size = 4096) prot localaddress: Port sched1_flags-> remoteaddress: port forward weight activeconn inactconntcp 192.168.1.128: 3306 RR persistent 20-> 192.168.1.115: 3306 Route 1 0 0 success !!