Experimental Purpose:
use Keepalive to build Mysql 's high availability. MySQL is the master from when a MySQL outage does not affect the call to MySQL .
Lab Environment:
two mysql servers (LAMP -based and master- slave ), both MySQL servers are Apache publishes the Discuz forum (Discuz calls the primary MySQL address ).
Identity Host name IP Address
Master Mysql Master 192.168.1.3
from MYSLQ slave 192.168.1.4
Lamp platform See << build discuz forum in two ways >>
MySQL master-slave see << build MySQL trilogy of the third master case >>
Experimental steps:
First, install the configuration keepalive on the main MySQL
[Email protected] ~]# bash keepalive_install.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/1D/wKiom1VcUVix6gI6AAMDYWrXRzw071.jpg "title=" 1.png " Style= "Float:none;" alt= "wkiom1vcuvix6gi6aamdywrxrzw071.jpg"/>
The " script " content is as follows:
[[Email protected] ~]# cat keepalive_install.sh#!/bin/bashyum -y install kernel-devel openssl-devel popt-devel &&wgethttp://www.keepalived.org/ Software/keepalived-1.1.15.tar.gz &&tar -zxf keepalived-1.1.15.tar.gz &&cd keepalived-1.1.15 &&./configure--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ &&make && make install &&DIR=/usr/local/cp $DIR/etc/ rc.d/init.d/keepalived /etc/rc.d/init.d/ &&cp $DIR/etc/sysconfig/keepalived /etc/sysconfig/&& mkdir -p /etc/keepalived &&cp $DIR/sbin/ keepalived/usr/sbin/&&cp/usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ & &/etc/init.d/keepalived restartif [ $? -eq 0 ];then echo -e ' \e[32minstall keepalive successfully!\e[0m ' else echo -e ' \e[31minstall keepalive failure!\e[0m ' fi
load ip_vs the kernel module
[Email protected] ~]# modprobe ip_vs[[email protected]~]# modprobe ip_vs_wrr[[email protected]~]# modprobe ip_vs_rr
Modify keepalived.conf The configuration file is as follows:
[Email protected] ~]# vim/etc/keepalived/keepalived.conf[[email protected] ~]# cat/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_instance vi_1 { state master interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type pass auth_ pass 1111 } virtual_ipaddress { 192.168.1.77 }} virtual_server 192.168.1.77 3306 { delay_loop 6 lb_algo wrr lb_kind dr persistence_timeout 50 protocol tcp real_server 192.168.1.3 3306 { weight 1 notify_down/data/sh/ keepalive_stop.sh tcp_check { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } }}
[[email protected] ~]# mkdir-p/data/sh[[email protected] ~]# vim/data/sh/keepalive_stop.sh[[email protected] ~]# chmod + X/data/sh/keepalive_stop.sh[[email protected] ~]#/etc/init.d/keepalivedreloadreloading keepalived: [OK] [Email protected] ~]# cat/data/sh/keepalive_stop.sh#!/bin/bash/etc/init.d/keepalived stop[[email protected] ~]#
Second, install the configuration from MySQL keepalive
[Email protected] ~]# bash keepalive_install.sh
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/1D/wKiom1VcUViQFeiwAAMAvbyK6dM432.jpg "title=" 2.png " Style= "Float:none;" alt= "wkiom1vcuviqfeiwaamavbyk6dm432.jpg"/>
The script content is as follows, consistent with scripts executed on master ( not strictly script, install commands together ).
[[email protected] ~]# cat keepalive_install.sh#!/bin/bashyum -y install kernel-developenssl-devel popt-devel &&wget http://www.keepalived.org/ software/keepalived-1.1.15.tar.gz&&tar -zxf keepalived-1.1.15.tar.gz &&cd keepalived-1.1.15 &&./configure--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ &&make && make install &&DIR=/usr/local/cp $DIR/etc/rc.d/ init.d/keepalived /etc/rc.d/init.d/ &&cp $DIR/etc/sysconfig/keepalived/etc/ sysconfig/ && mkdir -p /etc/keepalived &&cp $DIR/sbin/keepalived /usr/sbin/&&cp/usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ &&/etc/ init.d/keepalived restartif [ $? -eq 0 ];then echo -e&nbSP; ' \e[32minstall keepalive successfully!\e[0m ' Else echo -e ' \e[31minstall keepalive failure!\e[0m ' fi[[email protected] ~]#
load ip_vs the kernel module
[[email protected] ~]# modprobe ip_vs[[email protected] ~]# modprobe ip_vs_wrr[[email protected] ~]# modprobe IP_VS_RR
Modify keepalived.conf The configuration file is as follows
[Email protected] ~]# vim/etc/keepalived/keepalived.conf[[email protected] ~]# cat/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_instance vi_1 { state backup ! here is not the same as Master interface eth0 virtual_router_id 51 priority 90 ! Lower priority than Master advert_int 1 authentication{ auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.77 }} virtual_server 192.168.1.77 3306 { delay_loop 6 lb_algo wrr lb_kind dr nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP real_server 192.168.1.4 3306 { ! The ip weight 1 on the slave notify_down/data/sh/keepalive_stop.sh tcp_check { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } }}
[[Email protected] ~]#[email protected] ~]# mkdir-p/data/sh[[email protected] ~]# Vim/data/sh/keepalive_stop.sh[[email Protected] ~]# chmod +x/data/sh/keepalive_stop.sh[[email protected] ~]#/etc/init.d/keepalivedreloadreloading keepalived: [OK][[email protected] ~]# cat/data/sh/keepalive_stop.sh#!/bin/bash/e tc/init.d/keepalived Stop[[email protected] ~]#
Third, modify Discuz Forum Database connection IP for VIP
Direct access to the 192.168.1.3 forum on master is accessible, and direct access to the 192.168.1.4 forum on The slave is also accessible, Now we have direct access to the VIP ( virtual IP) 192.168.1.77 can still access the forum.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6D/17/wKioL1VcUtPSWZQ7AAM64OwyBqg115.jpg "title=" 3.png " Style= "Float:none;" alt= "wkiol1vcutpswzq7aam64owybqg115.jpg"/>
this time because discuz called the database IP on master,so we should let it call VIP 192.168.1.77, This will ensure that you automatically switch to the top when the master hangs.
in the master on
[[Email protected] ~] #sed-i ' s/192.168.1.3/192.168.1.77/'/usr/local/apache/htdocs/config/config_global.php[[email Protected] ~]#/usr/local/apache/bin/apachectl Restart
in slave on
[[Email protected] ~] #sed-i ' s/192.168.1.3/192.168.1.77/'/usr/local/apache/htdocs/config/config_global.php[[email Protected] ~]#/usr/local/apache/bin/apachectl Restart
Iv. Testing
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6D/1D/wKiom1VcUVmSIFOeAAE085AoVaU398.jpg "title=" 4.png " Style= "Float:none;" alt= "wkiom1vcuvmsifoeaae085aovau398.jpg"/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/17/wKioL1VcUtPDmo-JAADg29wc5rc322.jpg "title=" 5.png " Style= "Float:none;" alt= "wkiol1vcutpdmo-jaadg29wc5rc322.jpg"/>
The top two graphs are clearly visible at this time the VIP is on master.
manually simulate the MySQL shutdown on Master
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/1D/wKiom1VcUVqjIT_uAAMB8Um51w4975.jpg "title=" 6.png " Style= "Float:none;" alt= "wkiom1vcuvqjit_uaamb8um51w4975.jpg"/>
VIP automatically floats onto the slave
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/17/wKioL1VcUtSyGjSvAAEx6to-bjA380.jpg "title=" 7.png " Style= "Float:none;" alt= "wkiol1vcutsygjsvaaex6to-bja380.jpg"/>
Forums can still be accessed
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/1D/wKiom1VcUVvAkEFKAAI_A0bWLEc647.jpg "style=" float: none; "title=" 8.png "alt=" Wkiom1vcuvvakefkaai_a0bwlec647.jpg "/>
This article is from the "Step Into the Linux World" blog, please be sure to keep this source http://linuxnote.blog.51cto.com/9876511/1653242
Build a high-availability server with three keepalive equalization MySQL