mysql系列之8.mysql高可用 (keepalived)

來源:互聯網
上載者:User

標籤:ace   back   from   flush   wal   mkdir   make   code   service   

環境: centos6.5_x64

 

準備:

兩台mysql機器

主1 master:  192.168.32.130

主2 backup:  192.168.32.131

VIP: 192.168.32.100

 

步驟:

 

1.配置mysql的雙主架構

 

2.安裝keepalived

keepalived-1.2.23.tar.gz 

yum -y install openssl openssl-devel

wget http://www.keepalived.org/software/keepalived-1.2.23.tar.gz

tar zxvf keepalived-1.2.23.tar.gz 

cd keepalived-1.2.23

./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686 

make && make install

 

3.把keepalived設定為系統服務

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

mkdir /etc/keepalived/

cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

 

4.修改keepalived配置

vi /etc/keepalived/keepalived.conf  //詳見.conf詳細配置

vi /usr/local/keepalived/mysql.sh

#!/bin/bashpkill keepalived

chmod +x /usr/local/keepalived/mysql.sh

/etc/init.d/keepalived start

 

5.測試

5.1 分別在兩台mysql機器上授權, 允許使用者遠程登入

mysql> grant all on *.* to‘kkk‘@‘192.168.32.%‘ identified by ‘123456‘;

mysql> flush privileges;

5.2 在任何一台機器上, 通過虛擬IP來串連mysql伺服器

mysql -ukkk -p123456 -h192.168.32.100

5.3 停止master,看是否能正常切換到backup,然後來查看VIP在哪台服務器上

service mysqld stop

ip addr

5.4 master伺服器故障恢複後,是否主動搶佔資源,成為活動伺服器 (取決於這個參數nopreempt)

 

keepalived.conf詳細配置

! Configuration File for keepalived global_defs {   notification_email {     [email protected]     [email protected]     [email protected]   }   notification_email_from [email protected]   smtp_server 192.168.200.1   smtp_connect_timeout 30   router_id LVS_DEVEL   vrrp_skip_check_adv_addr   vrrp_strict   vrrp_garp_interval 0   vrrp_gna_interval 0} vrrp_instance VI_1 {    state BACKUP    interface eth0    virtual_router_id 51    priority 100  #優先順序 (backup設定為90)    advert_int 1    nopreempt  #不主動搶佔資源,只在master這台優先順序高的設定 (backup不設定)     authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.32.100    }} virtual_server 192.168.32.100 3306 {     delay_loop 2     #lb_algo wrr     #lb_kind DR     persistence_timeout 60     protocol TCP     real_server 192.168.32.130 3306 {  #真實mysql伺服器的ip地址         weight 3         notify_down /usr/local/keepalived/mysql.sh  #貌似沒有執行指令碼, why?         TCP_CHECK {             connect_timeout 10             nb_get_retry 3             delay_before_retry 3             connect_port 3306         }     } 
View Code

 

 

 

 

 

;

mysql系列之8.mysql高可用 (keepalived)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.