MySQL主主複製故障自動切換解決方案

來源:互聯網
上載者:User

 1. MySQL-VIP:192.168.0.50 
    2. MySQL-master1:192.168.0.42
    3. MySQL-master2:192.168.0.49
   
    5. OS版本:CentOS 5.5 
    6. MySQL版本:5.5.13
    7. Keepalived版本:keepalived-1.2.7.tar.gz
 

一、MySQL master-master配置
  1、修改MySQL設定檔
   兩台MySQL均如要開啟binlog日誌功能,開啟方法:在MySQL設定檔[MySQLd]段中加上log-bin=MySQL-bin選項
   兩台MySQL的server-ID不能一樣,預設情況下兩台MySQL的serverID都是1,需將其中一台修改為2即可
   這裡省略掉建立主主過程,簡單描述如下,在2太伺服器上分別建立帳號,然後執行個體化彼此的從伺服器!即可!
 二、keepalived安裝及配置
 安裝keepalived
    1. #tar zxvf keepalived-1.1.20.tar.gz 
    2. #cd keepalived-1.1.20 
    3. #./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686 
    4. #make && make install
 [root@slave01 keepalived-1.2.7]# ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686
 checking for gcc... gcc
 checking whether the C compiler works... yes
 checking for C compiler default output file name... a.out
 checking for suffix of executables...
 checking whether we are cross compiling... no
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether gcc accepts -g... yes
 checking for gcc option to accept ISO C89... none needed
 checking for a BSD-compatible install... /usr/bin/install -c
 checking for strip... strip
 checking how to run the C preprocessor... gcc -E
 checking for grep that handles long lines and -e... /bin/grep
 checking for egrep... /bin/grep -E
 checking for ANSI C header files... yes
 checking for sys/wait.h that is POSIX.1 compatible... yes
 checking for sys/types.h... yes
 checking for sys/stat.h... yes
 checking for stdlib.h... yes
 checking for string.h... yes
 checking for memory.h... yes
 checking for strings.h... yes
 checking for inttypes.h... yes
 checking for stdint.h... yes
 checking for unistd.h... yes
 checking fcntl.h usability... yes
 checking fcntl.h presence... yes
 checking for fcntl.h... yes
 checking syslog.h usability... yes
 checking syslog.h presence... yes
 checking for syslog.h... yes
 checking for unistd.h... (cached) yes
 checking sys/ioctl.h usability... yes
 checking sys/ioctl.h presence... yes
 checking for sys/ioctl.h... yes
 checking sys/time.h usability... yes
 checking sys/time.h presence... yes
 checking for sys/time.h... yes
 checking openssl/ssl.h usability... yes
 checking openssl/ssl.h presence... yes
 checking for openssl/ssl.h... yes
 checking openssl/md5.h usability... yes
 checking openssl/md5.h presence... yes
 checking for openssl/md5.h... yes
 checking openssl/err.h usability... yes
 checking openssl/err.h presence... yes
 checking for openssl/err.h... yes
 checking whether ETHERTYPE_IPV6 is declared... no
 checking for MD5_Init in -lcrypto... yes
 checking for SSL_CTX_new in -lssl... yes
 checking for poptGetContext in -lpopt... yes
 checking for nl_socket_modify_cb in -lnl... no
 configure: WARNING: keepalived will be built without libnl support.
 checking for kernel version... 2.6.18
 checking for IPVS syncd support... yes
 checking for kernel macvlan support... no
 checking for an ANSI C-conforming const... yes
 checking for pid_t... yes
 checking whether time.h and sys/time.h may both be included... yes
 checking whether gcc needs -traditional... no
 checking for working memcmp... yes
 checking return type of signal handlers... void
 checking for gettimeofday... yes
 checking for select... yes
 checking for socket... yes
 checking for strerror... yes
 checking for strtol... yes
 checking for uname... yes
 configure: creating ./config.status
 config.status: creating Makefile
 config.status: creating genhash/Makefile
 config.status: creating keepalived/core/Makefile
 config.status: creating keepalived/include/config.h
 config.status: creating keepalived.spec
 config.status: creating keepalived/Makefile
 config.status: creating lib/Makefile
 config.status: creating keepalived/vrrp/Makefile
 config.status: creating keepalived/check/Makefile
 config.status: creating keepalived/libipvs-2.6/Makefile
 

Keepalived configuration
 ------------------------
 Keepalived version      : 1.2.7
 Compiler                : gcc
 Compiler flags          : -g -O2 -DETHERTYPE_IPV6=0x86dd
 Extra Lib                : -lpopt -lssl -lcrypto
 Use IPVS Framework      : Yes
 IPVS sync daemon support : Yes
 IPVS use libnl          : No
 Use VRRP Framework      : Yes
 Use VRRP VMAC            : No
 SNMP support            : No
 Use Debug flags          : No
 [root@slave01 keepalived-1.2.7]# make && make install
 make -C lib || exit 1;
 make[1]: Entering directory `/usr/local/keepalived-1.2.7/lib'
 make[1]: Nothing to be done for `all'.
 make[1]: Leaving directory `/usr/local/keepalived-1.2.7/lib'
 make -C keepalived
 make[1]: Entering directory `/usr/local/keepalived-1.2.7/keepalived'
 make[2]: Entering directory `/usr/local/keepalived-1.2.7/keepalived/core'
 gcc -g -O2 -DETHERTYPE_IPV6=0x86dd  -I/usr/src/kernels/2.6.18-164.el5-i686/include -I/usr/src/kernels/2.6.18-164.el5-i686/include -I../include -I../../lib -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_  -c main.c
 make[2]: Leaving directory `/usr/local/keepalived-1.2.7/keepalived/core'
 make[2]: Entering directory `/usr/local/keepalived-1.2.7/keepalived/check'
 make[2]: Nothing to be done for `all'.
 make[2]: Leaving directory `/usr/local/keepalived-1.2.7/keepalived/check'
 make[2]: Entering directory `/usr/local/keepalived-1.2.7/keepalived/vrrp'
 make[2]: Nothing to be done for `all'.
 make[2]: Leaving directory `/usr/local/keepalived-1.2.7/keepalived/vrrp'
 make[2]: Entering directory `/usr/local/keepalived-1.2.7/keepalived/libipvs-2.6'
 gcc -g -O2 -DETHERTYPE_IPV6=0x86dd  -I/usr/src/kernels/2.6.18-164.el5-i686/include -I/usr/src/kernels/2.6.18-164.el5-i686/include -DLIBIPVS_DONTUSE_NL -Wall -Wunused -c -o libipvs.o libipvs.c
 gcc -g -O2 -DETHERTYPE_IPV6=0x86dd  -I/usr/src/kernels/2.6.18-164.el5-i686/include -I/usr/src/kernels/2.6.18-164.el5-i686/include -DLIBIPVS_DONTUSE_NL -Wall -Wunused -c -o ip_vs_nl_policy.o ip_vs_nl_policy.c
 ar rv libipvs.a libipvs.o ip_vs_nl_policy.o
 r - libipvs.o
 r - ip_vs_nl_policy.o
 rm libipvs.o ip_vs_nl_policy.o
 make[2]: Leaving directory `/usr/local/keepalived-1.2.7/keepalived/libipvs-2.6'
 Building ../bin/keepalived
 strip ../bin/keepalived
 

Make complete
 make[1]: Leaving directory `/usr/local/keepalived-1.2.7/keepalived'
 make -C genhash
 make[1]: Entering directory `/usr/local/keepalived-1.2.7/genhash'
 strip ../bin/genhash
 

Make complete
 make[1]: Leaving directory `/usr/local/keepalived-1.2.7/genhash'
 

Make complete
 make -C keepalived install
 make[1]: Entering directory `/usr/local/keepalived-1.2.7/keepalived'
 install -d /usr/local/keepalived/sbin
 install -m 700 ../bin/keepalived /usr/local/keepalived/sbin/
 install -d /usr/local/keepalived/etc/rc.d/init.d
 install -m 755 etc/init.d/keepalived.init /usr/local/keepalived/etc/rc.d/init.d/keepalived
 install -d /usr/local/keepalived/etc/sysconfig
 install -m 755 etc/init.d/keepalived.sysconfig /usr/local/keepalived/etc/sysconfig/keepalived
 install -d /usr/local/keepalived/etc/keepalived/samples
 install -m 644 etc/keepalived/keepalived.conf /usr/local/keepalived/etc/keepalived/
 install -m 644 ../doc/samples/* /usr/local/keepalived/etc/keepalived/samples/
 install -d /usr/local/keepalived/share/man/man5
 install -d /usr/local/keepalived/share/man/man8
 install -m 644 ../doc/man/man5/keepalived.conf.5 /usr/local/keepalived/share/man/man5
 install -m 644 ../doc/man/man8/keepalived.8 /usr/local/keepalived/share/man/man8
 make[1]: Leaving directory `/usr/local/keepalived-1.2.7/keepalived'
 make -C genhash install
 make[1]: Entering directory `/usr/local/keepalived-1.2.7/genhash'
 install -d /usr/local/keepalived/bin
 install -m 755 ../bin/genhash /usr/local/keepalived/bin/
 install -d /usr/local/keepalived/share/man/man1
 install -m 644 ../doc/man/man1/genhash.1 /usr/local/keepalived/share/man/man1
 make[1]: Leaving directory `/usr/local/keepalived-1.2.7/genhash

  • 1
  • 2
  • 3
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.