Configure mysql+lvs+keeplived to achieve load balancing for MySQL read operations
Environment:
Test1192.168.46.131master
Test2192.168.46.130slave Backup Test Library
TEST3 Scheduler
1, installation and configuration keepalived
First installs the Keepalived software on the node test1, the Test2, the software installation is very simple.
[Root@test1]# yum install-y openssl-devel [root@test1 ~]# wget] http://www.keepalived.org/software/keepalived-1.2 .1.tar.gz [Root@test1 ~]# tar zxvf keepalived-1.2.1.tar.gz [root@test1 ~]# cd keepalived-1.2.1 [Root@test1 keepalived-1.2 .1]#./configure--prefix=/usr/local/keepalived [root@test1 keepalived-1.2.1]# make && make install [root@test1 ~]# cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/[Root@test1 ~]# cp/usr/local/keepalived/etc/ rc.d/init.d/keepalived/etc/init.d/[Root@test1 ~]# mkdir/etc/keepalived] [root@test1 ~]# cp/usr/local/keepalived/etc/ keepalived/keepalived.conf/etc/keepalived/[Root@test1 ~]# ln-s/usr/local/keepalived/sbin/keepalived/usr/sbin/[R Oot@test1 ~]# Service keepalived start starting keepalived: [OK]
Keepalived configuration is also very simple, only need a configuration file to complete the Hacluster and LVS service node monitoring functions, through keepalived to build a highly available LVS cluster instance, the main, The keepalived software needs to be installed Directorserver, and the default profile path is/etc/keepalived/keepalived.conf after the installation is successful.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/
A complete keepalived configuration file consists of three components, namely, the Global Definition section, the VRRP instance Definition section, and the Virtual Server Definition section, and the configured file contents are as follows:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
Notification_email_from root@localhost
smtp_server 192.168.46.131
smtp_connect_timeout Router
_id lvs_master
}
vrrp_instance vi_1 {State
MASTER //library for Backup
interface// through network adapters
virtual_router_id
Priority /reserve for
Advert_int 1
authentication {
Auth_type Pass
auth_pass 1111
}
virtual_ipaddress {
192.168.46.100
}
}
virtual_server 192.168.46.100 3306 {
delay_loop
Lb_algo rr
lb_kind DR
persistence_timeout m
protocol TCP
real_server 192.168.46.131 3306 {
weight 1
misc_check{misc_path
"/etc/keepalived/check_ slave.pl 192.168.46.131 "
misc_dynamic
}
}
real_server 192.168.46.130 3306 {
weight 1
misc_check{
misc_path "/etc/keepalived/check_slave.pl 192.168.46.130"
misc_dynamic
}
}
}
}