mariadb高可用集羣

配置前的準備html


(1)節點間時間必須同步:使用ntp協議實現;node


1mysql

2linux

[root@node1 ~]# ntpdate 172.16.0.1       #172.16.0.1是我這裏的時間服務器算法

[root@node2 ~]# ntpdate 172.16.0.1sql

(2) 節點間須要經過主機名互相通訊,必須解析主機至IP地址;數據庫


(a)建議名稱解析功能使用hosts文件來實現;bootstrap


(b)通訊中使用的名字與節點名字必須保持一致:「uname -n」命令,或「hostname」展現出的名字保持一致;vim


1centos

2

3

4

5

6

7

8

[root@node1 ~]# sed -i's@\(HOSTNAME=\).*@\1node1.xmfb.com@g' /etc/sysconfig/network

[root@node1 ~]# hostname node1.xmfb.com

[root@node1 ~]# echo "172.16.4.100node1.xmfb.com node1" >> /etc/hosts

[root@node1 ~]# echo "172.16.4.101node2.xmfb.com node2" >> /etc/hosts  

[root@node2 ~]# sed -i's@\(HOSTNAME=\).*@\1node2.xmfb.com@g' /etc/sysconfig/network

[root@node2 ~]# hostname node2.xmfb.com

[root@node2 ~]# echo "172.16.4.100 node1.xmfb.comnode1" >> /etc/hosts

[root@node2 ~]# echo "172.16.4.101node2.xmfb.com node2" >> /etc/hosts

(3)考慮仲裁設備是否會用到;


(4) 創建各節點之間的root用戶可以基於密鑰認證;


#ssh-keygen -t rsa -P ''


#ssh-copy-id -i /root/.ssh/id_rsa.pub root@HOSTNAME


1

2

3

4

5

[root@node1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa-P ''

[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pubnode2

 

[root@node2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa-P ''

[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pubnode1

注意:定義成爲集羣服務中的資源,必定不能開機自動啓動;由於它們將由crm管理;


Corosync配置


安裝corosync


1

2

[root@node1~]# yum -y install corosync pacemaker

[root@node2~]# yum -y install corosync pacemaker

安裝crm


1

2

[root@node1 ~]# yum--nogpgcheck localinstall crmsh-2.1-1.6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm –y                                                                                       

[root@node2 ~]# yum --nogpgcheck localinstallcrmsh-2.1-1.6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm -y

複製配置文件模版


1

[root@node1 ~]# cp/etc/corosync/corosync.conf.example /etc/corosync/corosync.conf

修改配置文件


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

[root@node1 ~]# vim /etc/corosync/corosync.conf

compatibility: whitetank

totem {

       version: 2

       secauth: on

       threads: 0

       interface {

               ringnumber: 0

               bindnetaddr: 172.16.0.0

               mcastaddr: 239.165.17.11

               mcastport: 5405

               ttl: 1

        }

}

 

logging {

       fileline: off

       to_stderr: no

       to_logfile: no

       logfile: /var/log/cluster/corosync.log

       to_syslog: yes

       debug: off

       timestamp: on

       logger_subsys {

               subsys: AMF

               debug: off

        }

}

service {

  ver:  0

  name:pacemaker

   use_mgmtd:yes

   }

   aisexec {

     user:root

    group:  root

    }

生成驗證密鑰


1

[root@node1 ~]# corosync-keygen

複製配置文件和密鑰到節點2


1

2

3

[root@node1 ~]# scp/etc/corosync/{authkey,corosync.conf} node2:/etc/corosync/

authkey                                                 100%  128     0.1KB/s  00:00   

corosync.conf                                           100% 2790     2.7KB/s   00:00

啓動corosync


1

[root@node1 ~]# service corosync start;ssh node2'service corosync start'

查看集羣狀態信息


1

2

3

4

5

6

7

8

9

10

[root@node1 ~]# crm status

Last updated: Sun May 31 17:32:28 2015

Last change: Sun May 31 17:32:22 2015

Stack: classic openais (with plugin)

Current DC: node1.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

0 Resources configured

 

Online: [ node1.xmfb.com node2.xmfb.com ]

解決corosync中STONITH報錯問題


1

2

crm(live)configure# property stonith-enabled=false

crm(live)configure# commit

資源轉移配置


1

crm(live)configure# property no-quorum-policy=ignore

資源粘性配置


1

crm(live)configure# propertydefault-resource-stickiness=50

Corosync就先配置到這裏,而後配置drbd


drbd配置


配置以前須要配置好作drbd磁盤的分區,並且不要格式化(此處省略)


安裝配置drbd


安裝drbd


1

rpm -ivh kmod-drbd84-8.4.5-504.1.el6.x86_64.rpmdrbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm

配置global_common.conf


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

[root@node1 ~]# vim /etc/drbd.d/global_common.conf

global {

        usage-count no;

        # minor-countdialog-refresh disable-ip-verification

}    

 

common {

        protocol C;

 

        handlers {

               pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ;reboot -f";

               pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ;reboot -f";

                local-io-error"/usr/lib/drbd/notify-io-error.sh;/usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ;halt -f";

                # fence-peer"/usr/lib/drbd/crm-fence-peer.sh";

                # split-brain"/usr/lib/drbd/notify-split-brain.sh root";

                # out-of-sync"/usr/lib/drbd/notify-out-of-sync.sh root";

                #before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 ---c 16k";

                #after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;

        }

 

        startup {

                #wfc-timeout120;

               #degr-wfc-timeout 120;

        }

 

        disk {

                on-io-errordetach;    #若是磁盤故障就拆掉,不讓磁盤繼續同步

                #fencingresource-only;

        }

 

        net {

                cram-hmac-alg"sha1";   #同步的算法

                shared-secret"mydrbdlab";  #同步的隨機碼

        }

 

        syncer {

                rate200M;    #設置同步的速率

        }

}

定義一個資源,文件結尾必須是res


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

[root@node1 ~]# vim /etc/drbd.d/mystore.res #文件名最好和資源一致。

resource mystore {

  onnode1.xmfb.com {

   device    /dev/drbd0;   #資源名稱

    disk      /dev/sda3;    #本地drbd設備

   address   172.16.4.100:7789;  #drbd節點設置,並且須要保證能夠解析對方的節點

    meta-diskinternal;     #drbd網絡設置

  }

  onnode2.xmfb.com {

   device    /dev/drbd0;

    disk      /dev/sda3;

   address   172.16.4.101:7789;

    meta-diskinternal;

  }

}

以上文件在兩個節點上必須相同,所以,能夠基於ssh將剛纔配置的文件所有同步至另一個節點。


1

2

3

4

[root@node1 ~]# scp-r /etc/drbd.* node2:/etc/   

drbd.conf                                               100%  133     0.1KB/s  00:00   

mystore.res                                             100%  201     0.2KB/s  00:00   

global_common.conf                                       100%2197     2.2KB/s   00:00

初始化資源,兩個節點都運行


1

2

3

4

5

6

7

8

9

10

[root@node1 ~]# drbdadm create-md mystore

initializing activity log

NOT initializing bitmap

Writing meta data...

New drbd meta data block successfully created.

[root@node2 ~]# drbdadm create-md mystore

initializing activity log

NOT initializing bitmap

Writing meta data...

New drbd meta data block successfully created.

啓動drbd


1

2

[root@node1 ~]# service drbd start

[root@node2 ~]# service drbd start

說明,第一個節點啓動的時候會等待第二個節點啓動,若是第二個節點不啓動那麼第一個節點也沒法啓動


drbd做爲集羣資源須要設置開機不啓動


1

2

3

[root@node1 ~]# chkconfig drbd off

[root@node1 ~]# chkconfig --list  drbd

drbd          0:off  1:off  2:off  3:off  4:off  5:off  6:off

啓動後的配置


查看狀態,因爲都沒有配置主節點因此都是從節點


1

2

3

4

5

[root@node1 ~]# cat /proc/drbd

version: 8.4.5 (api:1/proto:86-101)

GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96build by root@node1.magedu.com, 2015-01-02 12:06:20

 0:cs:Connected ro:Secondary/Secondaryds:Inconsistent/Inconsistent C r-----

    ns:0 nr:0dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:5252056

設置主從


1

2

3

4

5

6

7

8

[root@node1 ~]# drbdadm -- --overwrite-data-of-peerprimary mystore

[root@node1 ~]# cat /proc/drbd

version: 8.4.5 (api:1/proto:86-101)

GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96build by root@node1.magedu.com, 2015-01-02 12:06:20

 0:cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n-

    ns:160720nr:0 dw:0 dr:164648 al:0 bm:0 lo:0 pe:9 ua:5 ap:0 ep:1 wo:f oos:5093336

    [>....................]sync'ed:  3.2% (4972/5128)M

    finish:0:02:40 speed: 31,744 (31,744) K/sec

主從已經設置完成,正在同步數據


 


格式化掛載drbd設備


1

2

3

[root@node1 ~]# mkfs.ext4 -j /dev/drbd0

[root@node1 ~]# mkdir /mydata

[root@node1 ~]# mount /dev/drbd0 /mydata/

drbd複製驗證


在主節點的drbd分區建立一個測試文件


1

2

3

4

[root@node1 ~]# cd /mydata/

[root@node1 mydata]# touch test

[root@node1 mydata]# ls

lost+found test

調換主從角色,調換以前須要卸載文件系統,由於主從節點不能同時使用


1

2

3

4

[root@node1 ~]# umount /mydata/

[root@node1 ~]# drbdadm secondary mystore

[root@node1 ~]# drbd-overview

 0:mystore/0 Connected Secondary/Secondary UpToDate/UpToDate

從節點掛載查看主節點建立的文件還在說明drbd配置成功


1

2

3

4

5

6

7

8

[root@node2 ~]# drbd-overview

 0:drbd/0  ConnectedSecondary/Secondary UpToDate/UpToDate C r-----

[root@node2 ~]# drbdadm primary mystore

[root@node2 ~]# mkdir /mydata

[root@node2 ~]# mount /dev/drbd0 /mydata

[root@node2 ~]# cd /mydata

[root@node2 mydata]# ls

lost+found testdrbd

配置corosync+drbd高可用


配置以前須要先關閉drbd


1

2

[root@node1 ~]# service drbd stop

[root@node2 ~]# service drbd stop

使用corosync定義drbd高可用是由linbit實現的


1

2

3

4

5

6

crm(live)ra# classes

lsb

ocf / heartbeat linbit pacemaker

service

stonith

crm(live)ra# info ocf:linbit:drbd   #查看drbd幫助信息

定義drbd資源和克隆


1

2

crm(live)configure# primitive mystorocf:linbit:drbd params drbd_resource="mystore" op monitorrole="Master" interval=10s timeout=20s op monitorrole="Slave" interval=20s timeout=20s op start timeout=240s op stoptimeout=100s

crm(live)configure# ms my_mystor mystor metaclone-max="2" clone-node-max="1" master-max="1"master-node-max="1" notify="true"

定義drbd掛載


1

crm(live)configure# primitive mydataocf:heartbeat:Filesystem params device="/dev/drbd0"directory="/mydata" fstype="ext4" op monitor interval=20stimeout=40s op start timeout=60s op stop timeout=60s

設置位置約束


1

crm(live)configure# colocationmydata_with_ms_mystor_master inf: mydata my_mystor:Master

順序約束


1

crm(live)configure#order mydata_after_ms_mystor_master Mandatory: my_mystor:promote mydata:start

轉換測試


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

[root@node1 /]# crm status

Last updated: Sun May 31 14:16:28 2015

Last change: Sun May 31 14:16:13 2015

Stack: classic openais (with plugin)

Current DC: node2.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

3 Resources configured

 

 

Online: [ node1.xmfb.com node2.xmfb.com ]

 

 Master/SlaveSet: my_mystor [mystor]

     Masters:[ node1.xmfb.com ]

     Slaves:[ node2.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node1.xmfb.com

[root@node1 ~]# crm node standby

[root@node2 ~]# crm status

Last updated: Sun May 31 22:10:17 2015

Last change: Sun May 31 22:09:20 2015

Stack: classic openais (with plugin)

Current DC: node2.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

3 Resources configured

 

 

Node node1.xmfb.com: standby

Online: [ node2.xmfb.com ]

 

 Master/SlaveSet: my_mystor [mystor]

     Masters:[ node2.xmfb.com ]

     Stopped:[ node1.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node2.xmfb.com

drbd主從也是正常的


1

2

[root@node2 ~]# drbd-overview

 0:mystore/0 Connected Primary/Secondary UpToDate/UpToDate /mydata ext4 4.9G 11M 4.6G1%

Mariadb配置


主節點部署mariadb


建立mariadb用戶和數據目錄


1

2

3

4

[root@node1 ~]# groupadd -r -g 306 mysql

[root@node1 ~]# useradd -r -g 306 -u 306 mysql

[root@node1 ~]# mkdir /mydata/data

[root@node1 ~]# chown -R mysql.mysql /mydata/data/

安裝mariadb


1

2

3

4

5

6

tar xfmariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/

cd/usr/local/

ln -smariadb-5.5.43-linux-x86_64/ mysql

cd mysql/

chown -Rroot.mysql ./*

scripts/mysql_install_db--user=mysql --data=/mydata/data/

設置啓動腳本


1

2

3

cp support-files/mysql.server/etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld off

設置配置文件


1

2

3

4

5

[root@node1 ~]# cp support-files/my-large.cnf/etc/my.cnf

[root@node1 ~]# vim /etc/my.cnf

thread_concurrency = 2     #設置CPU核心數量乘以2

datadir = /mydata/data     #設置數據文件目錄

innodb_file_per_table = 1  #使用inoodb引擎,每表一個表文件

優化執行路徑


1

2

echo "exportPATH=/usr/local/mysql/bin:$PATH" >> /etc/profile.d/mysql

. /etc/profile.d/mysql

啓動測試


1

2

3

4

5

6

7

8

9

10

11

12

[root@node1 mysql]# service mysqld start

Starting MySQL...                                         [  OK  ]

[root@node1 mysql]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.43-MariaDB-log MariaDB Server

 

Copyright (c) 2000, 2015, Oracle, MariaDBCorporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

 

MariaDB [(none)]>

設置root用戶能夠遠程鏈接


1

2

MariaDB [(none)]> GRANT ALL ON *.* TO'root'@'172.16.%.%' IDENTIFIED BY 'centos';

MariaDB [(none)]> FLUSH PRIVILEGES;

設置完成關閉mysql服務


1

service mysqld stop

設置節點1爲備節點


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

[root@node1 ~]# crm node standby

[root@node1 ~]# crm node online

[root@node2 ~]# crm status

Last updated: Wed Jun  3 21:19:10 2015

Last change: Wed Jun  3 21:19:07 2015

Stack: classic openais (with plugin)

Current DC: node1.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

3 Resources configured

 

 

Node node1.xmfb.com: standby

Online: [ node2.xmfb.com ]

 

 Master/SlaveSet: MS_Mysql [mysqldrbd]

     Masters:[ node2.xmfb.com ]

     Stopped:[ node1.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node2.xmfb.com

備用節點部署mariadb


部署以前確保,主節點安裝的文件已經轉移到備節點


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[root@node2 ~]# ll /mydata/

total 20

-rw-r--r-- 1 root root     0 May 31 21:46 a.txt

drwxr-xr-x 5 306  306  4096 May 31 22:16 data

drwx------ 2 root root 16384 May 31 21:46lost+found

[root@node2 ~]# ll /mydata/data/

total 28716

-rw-rw---- 1 306 306    16384 May 31 22:16aria_log.00000001

-rw-rw---- 1 306 306       52 May 31 22:16aria_log_control

-rw-rw---- 1 306 306 18874368 May 31 22:16 ibdata1

-rw-rw---- 1 306 306  5242880 May 31 22:16ib_logfile0

-rw-rw---- 1 306 306  5242880 May 31 22:16ib_logfile1

drwx------ 2 306 root     4096 May 31 22:15 mysql

-rw-rw---- 1 306 306      476 May 31 22:16mysql-bin.000001

-rw-rw---- 1 306 306       19 May 31 22:16mysql-bin.index

-rw-r----- 1 306 root     2414 May 31 22:16 node1.xmfb.com.err

drwx------ 2 306 306     4096 May 31 22:15performance_schema

drwx------ 2 306 root     4096 May 31 22:14 test

建立mysql相關用戶


1

2

[root@node1 ~]# groupadd -r -g 306 mysql

[root@node1 ~]# useradd -r -g 306 -u 306 mysql

安裝mariadb不須要初始化


1

2

3

4

5

tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C/usr/local/

cd /usr/local/

ln -s mariadb-5.5.43-linux-x86_64/ mysql

cd mysql/

chown -R root.mysql ./*

複製配置文件


1

[root@node1 ~]# scp /etc/my.cnf node2:/etc/my.cnf

設置啓動腳本


1

2

3

cp support-files/mysql.server/etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld off

優化執行路徑


1

2

echo "export PATH=/usr/local/mysql/bin:$PATH">> /etc/profile.d/mysql

. /etc/profile.d/mysql

啓動mariadb


1

[root@node2 ~]# service mysqld start

建立一個數據庫


1

2

3

4

5

6

7

8

9

10

11

12

13

14

MariaDB [(none)]> create database testdb;

Query OK, 1 row affected (0.06 sec)

 

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql             |

| performance_schema |

| test              |

| testdb            |

+--------------------+

5 rows in set (0.00 sec)

關閉mysql服務


 


1

[root@node2 ~]# service mysqld stop

切換主從節點


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[root@node2 ~]# crm node standby

[root@node2 ~]# crm node online

[root@node2 ~]# crm status

Last updated: Sun May 31 22:32:38 2015

Last change: Sun May 31 22:32:33 2015

Stack: classic openais (with plugin)

Current DC: node2.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

3 Resources configured

 

 

Online: [ node1.xmfb.com node2.xmfb.com ]

 

 Master/SlaveSet: my_mystor [mystor]

     Masters:[ node1.xmfb.com ]

     Slaves:[ node2.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node1.xmfb.com

node1啓動mysql服務


1

[root@node1 ~]# service mysqld start

登陸數據庫能夠看到node2上面建立的數據庫


1

2

3

4

5

6

7

8

9

10

11

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql             |

| performance_schema |

| test              |

| testdb            |

+--------------------+

5 rows in set (0.00 sec)

查看完成中止mysql服務


1

[root@node1 ~]# service mysqld stop

配置mysql高可用集羣


設置vip資源


1

crm(live)configure# primitive myipocf:heartbeat:IPaddr params ip="172.16.4.1" op monitor interval=10stimeout=20s

定義mysql服務爲集羣資源


1

crm(live)configure# primitive myserver lsb:mysqldop monitor interval=20s timeout=20s

定義位置約束


1

2

crm(live)configure# colocationmyip_with_ms_mystor_master inf: myip my_mystor:Master

crm(live)configure# colocation myserver_with_mydatainf: myserver mydata

定義順序約束


1

2

crm(live)configure# order myserver_after_mydataMandatory: mydata:start myserver:start

crm(live)configure# order myserver_after_myipMandatory: myip:start myserver:start

設置完成commit提交,而且查看狀態


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[root@node1 ~]# crm status

Last updated: Sun May 31 22:48:39 2015

Last change: Sun May 31 22:48:27 2015

Stack: classic openais (with plugin)

Current DC: node2.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

5 Resources configured

 

 

Online: [ node1.xmfb.com node2.xmfb.com ]

 

 Master/SlaveSet: my_mystor [mystor]

     Masters:[ node1.xmfb.com ]

     Slaves:[ node2.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node1.xmfb.com

 myip  (ocf::heartbeat:IPaddr):Started node1.xmfb.com

 myserver  (lsb:mysqld):Startednode1.xmfb.com

 驗證


設置完成以後,使用其餘節點可使用vip地址鏈接mysql


1

2

3

4

5

6

7

8

9

10

11

12

[root@node2 ~]# mysql -u root -h172.16.4.1 –p

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql             |

| performance_schema |

| test              |

| testdb            |

+--------------------+

5 rows in set (0.01 sec)

主備轉換測試


1

[root@node1 ~]# crm node standby

節點2已經啓動vip和mysql資源


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[root@node2 ~]# crm status

Last updated: Sun May 31 22:57:34 2015

Last change: Sun May 31 22:57:23 2015

Stack: classic openais (with plugin)

Current DC: node2.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

5 Resources configured

 

 

Online: [ node1.xmfb.com node2.xmfb.com ]

 

 Master/SlaveSet: my_mystor [mystor]

     Masters:[ node2.xmfb.com ]

     Slaves:[ node1.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node2.xmfb.com

 myip  (ocf::heartbeat:IPaddr):Started node2.xmfb.com

 myserver  (lsb:mysqld):Startednode2.xmfb.com

鏈接數據庫依舊正常


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

[root@node2 ~]# mysql -u root -h172.16.4.1 -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.43-MariaDB-log MariaDB Server

 

Copyright (c) 2000, 2015, Oracle, MariaDBCorporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

 

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql             |

| performance_schema |

| test              |

| testdb            |

+--------------------+

5 rows in set (0.06 sec)

建立一個表


1

2

3

4

5

6

7

8

9

10

11

12

MariaDB [(none)]> use testdb;

Database changed

MariaDB [testdb]> create table t1 (id int,namevarchar(20));

Query OK, 0 rows affected (0.10 sec)

 

MariaDB [testdb]> show tables;

+------------------+

| Tables_in_testdb |

+------------------+

| t1              |

+------------------+

1 row in set (0.00 sec)

再次進行主從切換


1

2

[root@node2 ~]# crm node standby

[root@node2 ~]# crm node online

節點轉移到node1


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[root@node2 ~]# crm status

Last updated: Sun May 31 23:03:37 2015

Last change: Sun May 31 23:03:32 2015

Stack: classic openais (with plugin)

Current DC: node2.xmfb.com - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

5 Resources configured

 

 

Online: [ node1.xmfb.com node2.xmfb.com ]

 

 Master/SlaveSet: my_mystor [mystor]

     Masters:[ node1.xmfb.com ]

     Slaves:[ node2.xmfb.com ]

 mydata(ocf::heartbeat:Filesystem):    Started node1.xmfb.com

 myip  (ocf::heartbeat:IPaddr):Started node1.xmfb.com

 myserver  (lsb:mysqld):Startednode1.xmfb.com

數據庫訪問依舊正常


1

2

3

4

5

6

7

MariaDB [testdb]> show tables;

+------------------+

| Tables_in_testdb |

+------------------+

| t1              |

+------------------+

1 row in set (0.00 sec)

Corosync最終配置環境


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

crm(live)configure# show

node node1.xmfb.com \

       attributes standby=on

node node2.xmfb.com \

       attributes standby=off

primitive mydata Filesystem \

       params device="/dev/drbd0" directory="/mydata"fstype=ext4 \

        opmonitor interval=20s timeout=40s \

        opstart timeout=60s interval=0 \

        opstop timeout=60s interval=0

primitive myip IPaddr \

       params ip=172.16.4.1 \

        opmonitor interval=10s timeout=20s

primitive myserver lsb:mysqld \

        opmonitor interval=20s timeout=20s

primitive mystor ocf:linbit:drbd \

       params drbd_resource=mystore \

        opmonitor role=Master interval=10s timeout=20s \

        opmonitor role=Slave interval=20s timeout=20s \

        opstart timeout=240s interval=0 \

        opstop timeout=100s interval=0

ms my_mystor mystor \

        metaclone-max=2 clone-node-max=1 master-max=1 master-node-max=1 notify=true

colocation mydata_with_ms_mystor_master inf: mydatamy_mystor:Master

colocation myip_with_ms_mystor_master inf: myipmy_mystor:Master

colocation myserver_with_mydata inf: myservermydata

order mydata_after_ms_mystor_master Mandatory:my_mystor:promote mydata:start

order myserver_after_mydata Mandatory: mydata:startmyserver:start

order myserver_after_myip Mandatory: myip:startmyserver:start

property cib-bootstrap-options: \

       dc-version=1.1.11-97629de \

       cluster-infrastructure="classic openais (with plugin)" \

       expected-quorum-votes=2 \

       stonith-enabled=false \

       no-quorum-policy=ignore \

       default-resource-stickiness=50 \

       last-lrm-refresh=1433085584


本文轉自 服務器託管  http://www.fwqtg.net/mariadb.html

相關文章
相關標籤/搜索