corosync + pacemaker + drbd 實現mysql存儲的高可用(二)

 8. 定義資源

定義drbd資源

  1. [root@node1 ~]# crm 
  2. crm(live)# ra 
  3. crm(live)ra# classes                        查看資源類型 
  4. heartbeat 
  5. lsb 
  6. ocf / heartbeat linbit pacemaker 
  7. stonith 
  8. crm(live)ra# list ocf linbit 
  9. drbd       
  10. crm(live)ra# cd 
  11. crm(live)# configure   定義drbd資源 
  12. crm(live)configure# primitive webdrbd ocf:heartbeat:drbd params drbd_resource=web op start timeout=240 op stop timeout=100 op monitor role=Master interval=50s timeout=30s op monitor role=Slave interval=60s timeout=30s 
  13. crm(live)configure# show 
  14. node node1.yue.com \ 
  15.     attributes standby="off" 
  16. node node2.yue.com 
  17. primitive webdrbd ocf:heartbeat:drbd \ 
  18.     params drbd_resource="web" \ 
  19.     op start interval="0" timeout="240" \ 
  20.     op stop interval="0" timeout="100" \ 
  21.     op monitor interval="50s" role="Master" timeout="30s" \ 
  22.     op monitor interval="60s" role="Slave" timeout="30s" 
  23. property $id="cib-bootstrap-options" \ 
  24.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  25.     cluster-infrastructure="openais" \ 
  26.     expected-quorum-votes="2" \ 
  27.     stonith-enabled="false" \ 
  28.     no-quorum-policy="ignore"                    定義克隆資源 
  29. crm(live)configure# master MS_webdrbd webdrbd  meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true 
  30. crm(live)configure# show 
  31. node node1.yue.com \ 
  32.     attributes standby="off" 
  33. node node2.yue.com 
  34. primitive webdrbd ocf:heartbeat:drbd \ 
  35.     params drbd_resource="web" \ 
  36.     op start interval="0" timeout="240" \ 
  37.     op stop interval="0" timeout="100" \ 
  38.     op monitor interval="50s" role="Master" timeout="30s" \ 
  39.     op monitor interval="60s" role="Slave" timeout="30s" 
  40. ms MS_webdrbd webdrbd \ 
  41.     meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" 
  42. property $id="cib-bootstrap-options" \ 
  43.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  44.     cluster-infrastructure="openais" \ 
  45.     expected-quorum-votes="2" \ 
  46.     stonith-enabled="false" \ 
  47.     no-quorum-policy="ignore" 
  48. crm(live)configure# commit                  提交 
  49. crm(live)configure# cd 
  50. crm(live)# status  查看資源狀態
  51. ============ 
  52. Last updated: Fri Aug 10 13:11:07 2012 
  53. Stack: openais 
  54. Current DC: node1.yue.com - partition with quorum 
  55. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  56. 2 Nodes configured, 2 expected votes 
  57. 1 Resources configured. 
  58. ============ 
  59.  
  60. Online: [ node1.yue.com node2.yue.com ] 
  61.  
  62.  Master/Slave Set: MS_webdrbd [webdrbd] 
  63.      Masters: [ node1.yue.com ] 
  64.      Slaves: [ node2.yue.com ] 

定義文件系統資源:

  1. crm(live)# configure  
  2. crm(live)configure# primitive WebFS ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/data fstype=ext3 op start timeout=60 op stop timeout=60  
  3. crm(live)configure# colocation WebFS_on_MS_webdrbd inf: WebFS MS_webdrbd:Master          排列約束 
  4. crm(live)configure# order WebFS_after_MS_webddrbd inf: MS_webdrbd:promote  WebFS:start   順序約束 
  5. crm(live)configure# show 
  6. node node1.yue.com \ 
  7.     attributes standby="off" 
  8. node node2.yue.com 
  9. primitive WebFS ocf:heartbeat:Filesystem \ 
  10.     params device="/dev/drbd0" directory="/data" fstype="ext3" \ 
  11.     op start interval="0" timeout="60" \ 
  12.     op stop interval="0" timeout="60" 
  13. primitive webdrbd ocf:heartbeat:drbd \ 
  14.     params drbd_resource="web" \ 
  15.     op start interval="0" timeout="240" \ 
  16.     op stop interval="0" timeout="100" \ 
  17.     op monitor interval="50s" role="Master" timeout="30s" \ 
  18.     op monitor interval="60s" role="Slave" timeout="30s" 
  19. ms MS_webdrbd webdrbd \ 
  20.     meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" 
  21. colocation WebFS_on_MS_webdrbd inf: WebFS MS_webdrbd:Master 
  22. order WebFS_after_MS_webddrbd inf: MS_webdrbd:promote WebFS:start 
  23. property $id="cib-bootstrap-options" \ 
  24.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  25.     cluster-infrastructure="openais" \ 
  26.     expected-quorum-votes="2" \ 
  27.     stonith-enabled="false" \ 
  28.     no-quorum-policy="ignore" 
  29. crm(live)configure# commit  提交
  30.  
  31. crm(live)configure# cd
  32. crm(live)# status  查看此時的資源狀態
  33. ============ 
  34. Last updated: Fri Aug 10 13:13:54 2012 
  35. Stack: openais 
  36. Current DC: node1.yue.com - partition with quorum 
  37. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  38. 2 Nodes configured, 2 expected votes 
  39. 2 Resources configured. 
  40. ============ 
  41.  
  42. Online: [ node1.yue.com node2.yue.com ] 
  43.  
  44.  Master/Slave Set: MS_webdrbd [webdrbd] 
  45.      Masters: [ node1.yue.com ] 
  46.      Slaves: [ node2.yue.com ] 
  47.  WebFS  (ocf::heartbeat:Filesystem):    Started node1.yue.com 
  48. crm(live)# bye 
  49. bye 
  50.  

測試一下資源是否真的已經綁定在node1上:

  1. [root@node1 ~]# drbd-overview                   查看資源情況 
  2.   0:web  Connected Primary/Secondary UpToDate/UpToDate C r---- /data ext3 479M 40M 415M 9%  
  3. [root@node1 ~]# ls /data/  查看一下數據目錄下是否存在數據文件
  4. fstab    ib_logfile0  my.cnf  mysql-bin.000001  mysql-bin.index    node2.yue.com.err   test 
  5. ibdata1  ib_logfile1  mysql   mysql-bin.000002  node1.yue.com.err  performance_schema  testdb 
  6.  
  7. 從上面可以看出數據目錄下已經有數據文件了,我們再來測試一下mysql是否可以正常啓動
  8. [root@node1 ~]# /etc/init.d/mysqld start 
  9. Starting MySQL...                                          [  OK  ] 
  10. [root@node1 ~]# mysql 
  11. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  12. Your MySQL connection id is 1 
  13. Server version: 5.5.24-log MySQL Community Server (GPL) 
  14.  
  15. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 
  16.  
  17. Oracle is a registered trademark of Oracle Corporation and/or its 
  18. affiliates. Other names may be trademarks of their respective 
  19. owners. 
  20.  
  21. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  22.  
  23. mysql> SHOW DATABASES;  查看一下數據庫
  24. +--------------------+ 
  25. | Database           | 
  26. +--------------------+ 
  27. | information_schema | 
  28. | mysql              | 
  29. | performance_schema | 
  30. | test               | 
  31. | testdb             | 
  32. +--------------------+ 
  33. 5 rows in set (0.08 sec) 
  34.  
  35. mysql> quit 
  36. Bye 

下面我們來進行資源切換,測試一下資源切換是否正常

1)停止mysql

  1. [root@node1 ~]# /etc/init.d/mysqld stop                                      
  2. Shutting down MySQL.                                       [  OK  ] 

2)讓node1 處於standby

  1. [root@node1 ~]# crm node standby                            讓執行命令的當前節點處於standby狀態
  2. [root@node1 ~]# crm status 
  3. ============ 
  4. Last updated: Fri Aug 10 13:24:40 2012 
  5. Stack: openais 
  6. Current DC: node1.yue.com - partition with quorum 
  7. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  8. 2 Nodes configured, 2 expected votes 
  9. 2 Resources configured. 
  10. ============ 
  11.  
  12. Node node1.yue.comstandby 
  13. Online: [ node2.yue.com ] 
  14.  
  15.  Master/Slave Set: MS_webdrbd [webdrbd] 
  16.      Masters: [ node2.yue.com ] 
  17.      Stopped: [ webdrbd:0 ] 
  18.  WebFS  (ocf::heartbeat:Filesystem):    Started node2.yue.com 
  19.  
  20. [root@node1 ~]# drbd-overview 
  21.   0:web  Unconfigured . . . .  

3). 在node2上查看資源切換的結果

  1. [root@node2 ~]# crm status 
  2. ============ 
  3. Last updated: Fri Aug 10 13:26:25 2012 
  4. Stack: openais 
  5. Current DC: node1.yue.com - partition with quorum 
  6. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  7. 2 Nodes configured, 2 expected votes 
  8. 2 Resources configured. 
  9. ============ 
  10.  
  11. Node node1.yue.com: standby 
  12. Online: [ node2.yue.com ] 
  13.  
  14.  Master/Slave Set: MS_webdrbd [webdrbd] 
  15.      Masters: [ node2.yue.com ] 
  16.      Stopped: [ webdrbd:0 ] 
  17.  WebFS  (ocf::heartbeat:Filesystem):    Started node2.yue.com  資源運行在node2 上
  18. [root@node2 ~]# drbd-overview 
  19.   0:web  WFConnection Primary/Unknown UpToDate/DUnknown C r---- /data ext3 479M 40M 415M 9%  
  20.    
  21. [root@node2 ~]# ls /data/ 
  22. fstab    ib_logfile0  my.cnf  mysql-bin.000001  mysql-bin.000003  node1.yue.com.err  performance_schema  testdb 
  23. ibdata1  ib_logfile1  mysql   mysql-bin.000002  mysql-bin.index   node2.yue.com.err  test 

讓node 1 重新上線,看一下會有什麼效果:

  1. [root@node1 ~]# crm node online 
  2. [root@node1 ~]# drbd-overview 
  3.   0:web  Connected Secondary/Primary UpToDate/UpToDate C r----  
  4. [root@node1 ~]# crm status 
  5. ============ 
  6. Last updated: Fri Aug 10 13:30:13 2012 
  7. Stack: openais 
  8. Current DC: node1.yue.com - partition with quorum 
  9. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  10. 2 Nodes configured, 2 expected votes 
  11. 2 Resources configured. 
  12. ============ 
  13.  
  14. Online: [ node1.yue.com node2.yue.com ] 
  15.  
  16.  Master/Slave Set: MS_webdrbd [webdrbd] 
  17.      Masters: [ node2.yue.com ] 
  18.      Slaves: [ node1.yue.com ] 
  19.  WebFS  (ocf::heartbeat:Filesystem):    Started node2.yue.com      資源依然在node2 上並沒有自動切換回來 

 此時我們再模擬node2 故障,資源應該會轉移到node1上去

  1. [root@node2 ~]# crm node standby 
  2. [root@node2 ~]# crm status 
  3. ============ 
  4. Last updated: Fri Aug 10 13:35:46 2012 
  5. Stack: openais 
  6. Current DC: node1.yue.com - partition with quorum 
  7. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  8. 2 Nodes configured, 2 expected votes 
  9. 2 Resources configured. 
  10. ============ 
  11.  
  12. Node node2.yue.com: standby 
  13. Online: [ node1.yue.com ] 
  14.  
  15.  Master/Slave Set: MS_webdrbd [webdrbd] 
  16.      Masters: [ node1.yue.com ] 
  17.      Stopped: [ webdrbd:1 ] 
  18.  WebFS  (ocf::heartbeat:Filesystem):    Started node1.yue.com 
  19. [root@node2 ~]# drbd-overview 
  20.   0:web  Unconfigured . . . .  
  21.  
  22.   
  23. 由上面的結果可以看到資源已經轉移到node1 上了
  24. [root@node1 ~]# crm status 
  25. ============ 
  26. Last updated: Fri Aug 10 13:37:19 2012 
  27. Stack: openais 
  28. Current DC: node1.yue.com - partition with quorum 
  29. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  30. 2 Nodes configured, 2 expected votes 
  31. 2 Resources configured. 
  32. ============ 
  33.  
  34. Node node2.yue.com: standby 
  35. Online: [ node1.yue.com ] 
  36.  
  37.  Master/Slave Set: MS_webdrbd [webdrbd] 
  38.      Masters: [ node1.yue.com ] 
  39.      Stopped: [ webdrbd:1 ] 
  40.  WebFS  (ocf::heartbeat:Filesystem):    Started node1.yue.com 
  41. [root@node1 ~]# drbd-overview 
  42.   0:web  WFConnection Primary/Unknown UpToDate/DUnknown C r---- /data ext3 479M 40M 415M 9%  
  43. [root@node1 ~]# ls /data/ 
  44. fstab    ib_logfile0  my.cnf  mysql-bin.000001  mysql-bin.000003  node1.yue.com.err  performance_schema  testdb 
  45. ibdata1  ib_logfile1  mysql   mysql-bin.000002  mysql-bin.index   node2.yue.com.err  test 

4)若以上的測試都沒有問題,下面我們來配置mysql資源:

  1. [root@node1 ~] # crm
  2. crm(live)# configure  
  3. crm(live)configure# primitive web_mysql lsb:mysqld   定義mysql資源
  4. crm(live)configure# primitive web_ip ocf:heartbeat:IPaddr2 params ip=172.16.45.2 nic=eth0 cidr_netmask=16 broadcast=172.16.45.255 
  5.   此時額外定義一個vip,主要是爲mysql做爲後端負載均衡時的考慮,實驗中並未使用到相關的功能
  6. crm(live)configure# show 
  7. node node1.yue.com \ 
  8.         attributes standby="off" 
  9. node node2.yue.com \ 
  10.         attributes standby="on" 
  11. primitive WebFS ocf:heartbeat:Filesystem \ 
  12.         params device="/dev/drbd0" directory="/data" fstype="ext3" \ 
  13.         op start interval="0" timeout="60" \ 
  14.         op stop interval="0" timeout="60" 
  15. primitive web_ip ocf:heartbeat:IPaddr2 \ 
  16.         params ip="172.16.45.2" nic="eth0" cidr_netmask="16" broadcast="172.16.45.255" 
  17. primitive web_mysql lsb:mysqld 
  18. primitive webdrbd ocf:heartbeat:drbd \ 
  19.         params drbd_resource="web" \ 
  20.         op start interval="0" timeout="240" \ 
  21.         op stop interval="0" timeout="100" \ 
  22.         op monitor interval="50s" role="Master" timeout="30s" \ 
  23.         op monitor interval="60s" role="Slave" timeout="30s" 
  24. ms MS_webdrbd webdrbd \ 
  25.         meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" 
  26. colocation WebFS_on_MS_webdrbd inf: WebFS MS_webdrbd:Master 
  27. order WebFS_after_MS_webddrbd inf: MS_webdrbd:promote WebFS:start 
  28. property $id="cib-bootstrap-options" \ 
  29.         dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  30.         cluster-infrastructure="openais" \ 
  31.         expected-quorum-votes="2" \ 
  32.         stonith-enabled="false" \ 
  33.         no-quorum-policy="ignore" 
  34.  
  35. crm(live)configure# commit  確認資源定義沒問題,然後提交讓其生效
  36.  
  37.  
  38. 還要定義排列線束和順序約束: 
  39. crm(live)configure# colocation mysql_on_ip inf: web_mysql web_ip 
  40. crm(live)configure# order mysql_after_FS inf: WebFS:start web_mysql  讓文件系統啓動成功後再啓動mysql
  41. crm(live)configure# order ip_after_mysql inf: web_mysql web_ip  
  42. crm(live)configure# group cluster WebFS web_ip web_mysql     定義一個羣組,讓幾個資源在一起
  43.  
  44. crm(live)configure# show 
  45. node node1.yue.com \ 
  46.     attributes standby="off" 
  47. node node2.yue.com \ 
  48.     attributes standby="off" 
  49. primitive WebFS ocf:heartbeat:Filesystem \ 
  50.     params device="/dev/drbd0" directory="/data" fstype="ext3" \ 
  51.     op start interval="0" timeout="60" \ 
  52.     op stop interval="0" timeout="60" 
  53. primitive web_ip ocf:heartbeat:IPaddr2 \ 
  54.     params ip="172.16.45.2" nic="eth0" cidr_netmask="16" broadcast="172.16.45.255" 
  55. primitive web_mysql lsb:mysqld 
  56. primitive webdrbd ocf:heartbeat:drbd \ 
  57.     params drbd_resource="web" \ 
  58.     op start interval="0" timeout="240" \ 
  59.     op stop interval="0" timeout="100" \ 
  60.     op monitor interval="50s" role="Master" timeout="30s" \ 
  61.     op monitor interval="60s" role="Slave" timeout="30s" 
  62. group cluster WebFS web_ip web_mysql 
  63. ms MS_webdrbd webdrbd \ 
  64.     meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" 
  65. colocation WebFS_on_MS_webdrbd inf: cluster MS_webdrbd:Master 
  66. order WebFS_after_MS_webddrbd inf: MS_webdrbd:promote cluster:start 
  67. property $id="cib-bootstrap-options" \ 
  68.     dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \ 
  69.     cluster-infrastructure="openais" \ 
  70.     expected-quorum-votes="2" \ 
  71.     stonith-enabled="false" \ 
  72.     no-quorum-policy="ignore" 
  73.      
  74. crm(live)configure# commit 確認提交

來驗證下效果:

  1. [root@node1 ~]# crm status 
  2. ============ 
  3. Last updated: Fri Aug 10 15:17:57 2012 
  4. Stack: openais 
  5. Current DC: node1.yue.com - partition with quorum 
  6. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  7. 2 Nodes configured, 2 expected votes 
  8. 2 Resources configured. 
  9. ============ 
  10.  
  11. Online: [ node1.yue.com node2.yue.com ] 
  12.  
  13.  Master/Slave Set: MS_webdrbd [webdrbd] 
  14.      Masters: [ node1.yue.com ] 
  15.      Slaves: [ node2.yue.com ] 
  16.  Resource Group: cluster 
  17.      WebFS  (ocf::heartbeat:Filesystem):    Started node1.yue.com 
  18.      web_ip (ocf::heartbeat:IPaddr2):   Started node1.yue.com 
  19.      web_mysql  (lsb:mysqld):   Started node1.yue.com 
  20.  
  21. [root@node1 ~]# ip addr show 
  22. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue  
  23.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
  24.     inet 127.0.0.1/8 scope host lo 
  25. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 
  26.     link/ether 00:0c:29:e7:3d:5c brd ff:ff:ff:ff:ff:ff 
  27.     inet 172.16.45.11/16 brd 172.16.255.255 scope global eth0 
  28.     inet 172.16.45.2/16 brd 172.16.45.255 scope global secondary eth0  ip也已經綁定
  29.      
  30. [root@node1 ~]# drbd-overview 
  31.   0:web  WFConnection Primary/Unknown UpToDate/DUnknown C r---- /data ext3 479M 40M 415M 9%  

看一下mysql的狀態:

  1. [root@node1 ~]# /etc/init.d/mysqld status 
  2. MySQL running (2225)                                       [  OK  ] 
  1. [root@node1 ~]# mysql  連上mysql看一下
  2. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  3. Your MySQL connection id is 1 
  4. Server version: 5.5.24-log MySQL Community Server (GPL) 
  5.  
  6. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 
  7.  
  8. Oracle is a registered trademark of Oracle Corporation and/or its 
  9. affiliates. Other names may be trademarks of their respective 
  10. owners. 
  11.  
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  13.  
  14. mysql> SHOW DATABASES; 
  15. +--------------------+ 
  16. | Database           | 
  17. +--------------------+ 
  18. | information_schema | 
  19. | mysql              | 
  20. | performance_schema | 
  21. | test               | 
  22. testdb             | 
  23. +--------------------+ 
  24. 5 rows in set (0.07 sec) 
  25.  
  26. mysql> use testdb
  27. Database changed 
  28. mysql> CREATE TABLE student (Name char(20));            創建一張表 
  29. Query OK, 0 rows affected (0.14 sec) 
  30.  
  31. mysql> DESC student; 
  32. +-------+----------+------+-----+---------+-------+ 
  33. | Field | Type     | Null | Key | Default | Extra | 
  34. +-------+----------+------+-----+---------+-------+ 
  35. | Name  | char(20) | YES  |     | NULL    |       | 
  36. +-------+----------+------+-----+---------+-------+ 
  37. 1 row in set (0.05 sec) 
  38.  
  39. mysql> INSERT INTO student (Name) VALUE ('Redhat'),('Gentoo');   在表中插入一些數據 
  40. Query OK, 2 rows affected (0.01 sec) 
  41. Records: 2  Duplicates: 0  Warnings: 0 
  42.  
  43. mysql> SELECT * FROM student; 
  44. +--------+ 
  45. | Name   | 
  46. +--------+ 
  47. | Redhat | 
  48. | Gentoo | 
  49. +--------+ 
  50. 2 rows in set (0.00 sec) 
  51.  
  52. mysql> quit 
  53. Bye 

四、模擬故障

讓node1 處於standby

  1. [root@node1 ~]# crm node standby 
  2. [root@node1 ~]# crm status 
  3. ============ 
  4. Last updated: Fri Aug 10 15:20:12 2012 
  5. Stack: openais 
  6. Current DC: node1.yue.com - partition with quorum 
  7. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  8. 2 Nodes configured, 2 expected votes 
  9. 2 Resources configured. 
  10. ============ 
  11.  
  12. Node node1.yue.com: standby 
  13. Online: [ node2.yue.com ] 
  14.  
  15.  Master/Slave Set: MS_webdrbd [webdrbd] 
  16.      Masters: [ node2.yue.com ] 
  17.      Stopped: [ webdrbd:0 ] 
  18.  Resource Group: cluster 
  19.      WebFS  (ocf::heartbeat:Filesystem):    Started node2.yue.com 
  20.      web_ip (ocf::heartbeat:IPaddr2):   Started node2.yue.com 
  21.      web_mysql  (lsb:mysqld):   Stopped   mysql資源正在切換
  22.  
  23. [root@node1 ~]# crm status 
  24. ============ 
  25. Last updated: Fri Aug 10 15:20:22 2012 
  26. Stack: openais 
  27. Current DC: node1.yue.com - partition with quorum 
  28. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f 
  29. 2 Nodes configured, 2 expected votes 
  30. 2 Resources configured. 
  31. ============ 
  32.  
  33. Node node1.yue.com: standby 
  34. Online: [ node2.yue.com ] 
  35.  
  36.  Master/Slave Set: MS_webdrbd [webdrbd] 
  37.      Masters: [ node2.yue.com ] 
  38.      Stopped: [ webdrbd:0 ] 
  39.  Resource Group: cluster 
  40.      WebFS  (ocf::heartbeat:Filesystem):    Started node2.yue.com 
  41.      web_ip (ocf::heartbeat:IPaddr2):   Started node2.yue.com 
  42.      web_mysql  (lsb:mysqld):   Started node2.yue.com  mysql已經切換完成
  43.       
  44. [root@node1 ~]# drbd-overview 
  45.   0:web  Unconfigured . . . .  
  1. [root@node2 ~]# drbd-overview 
  2.   0:web  StandAlone Primary/Unknown UpToDate/DUnknown r---- /data ext3 479M 40M 415M 9%  

查看mysql

  1.  
  2. [root@node2 ~]# /etc/init.d/mysqld status 
  3. MySQL running (1274)                                       [  OK  ] 
  4. [root@node2 ~]# ip addr show 
  5. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue  
  6.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
  7.     inet 127.0.0.1/8 scope host lo 
  8. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 
  9.     link/ether 00:0c:29:d9:75:df brd ff:ff:ff:ff:ff:ff 
  10.     inet 172.16.45.12/16 brd 172.16.255.255 scope global eth0 
  11.     inet 172.16.45.2/16 brd 172.16.45.255 scope global secondary eth0 
  12.  
  13. [root@node2 ~]# mysql 
  14. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  15. Your MySQL connection id is 1 
  16. Server version: 5.5.24-log MySQL Community Server (GPL) 
  17.  
  18. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 
  19.  
  20. Oracle is a registered trademark of Oracle Corporation and/or its 
  21. affiliates. Other names may be trademarks of their respective 
  22. owners. 
  23.  
  24. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  25.  
  26. mysql> SHOW DATABASES; 
  27. +--------------------+ 
  28. | Database           | 
  29. +--------------------+ 
  30. | information_schema | 
  31. | mysql              | 
  32. | performance_schema | 
  33. | test               | 
  34. | testdb             | 
  35. +--------------------+ 
  36. 5 rows in set (0.09 sec) 
  37.  
  38. mysql> use testdb 
  39. Database changed 
  40. mysql> SHOW TABLES; 
  41. +------------------+ 
  42. | Tables_in_testdb | 
  43. +------------------+ 
  44. | student          | 
  45. +------------------+ 
  46. 1 row in set (0.04 sec) 
  47.  
  48. mysql> SELECT * FROM student;  我們剛纔在node1上創建的數據存在,
  49. +--------+ 
  50. | Name   | 
  51. +--------+ 
  52. Redhat | 
  53. | Gentoo | 
  54. +--------+ 
  55. 2 rows in set (0.02 sec) 
  56.  
  57. mysql> quit 
  58. Bye 

由此也說明了我們在一定的程度上保證了mysql數據的完整性,由於發生故障時資源切換和mysql啓動都需要一定的時間,所以還不能1保證數據是100%完整的!

另外在做實驗時曾出現瞭如下問題:

  1. # /etc/init.d/mysqld status 
  2. MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED

可能是我在做資源切換的時候忘記關閉mysql所導致的,此時可以將鎖文件刪除即可!

# cd /var/lock/subsys/
# rm -rf mysql

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章