DRBD+HeartBeat+MYSQL

介紹

MySQL一主多從,能夠保證數據庫集羣高可用,因爲是多從,因此掛掉一個從庫對集羣沒影響;若是掛了一個主庫咱們能夠把從庫轉換成主庫,可是因爲網絡延遲問題主從角色切換會形成數據丟失,爲了解決這個問題,解決主機單節點運行使用heartbeat作主節點高可用,主爲了保證2個主節點數據同步可使用drbd作主節點數據同步。
多主可使用lvs來實現,若是是多主多從須要Mysql+DRBD+heartbeat來實現,架構以下(拷貝老男孩的一張架構圖):
這裏寫圖片描述
注意事項:
1.db-1-2熱備主,跟db-1-1經過heartbeat作高可用,brdb作數據同步;
2.正常狀況下,db-1-1對外提供寫,從對外提供讀;
3.mysql slave能夠作一個lb,經過vip跟db-1-1作數據同步;
4.web server提供讀寫分離機制,讀分發到mysql slave,寫分發到db-1-1;
5.db-1-一、db-1-2數據同步使用專有鏈路,heartbeat也必須使用專有鏈路,也可使用串口線來完成,不建議使用同一鏈路。node

這裏寫圖片描述
db-1-1故障以後,有db-1-2接管vip及數據庫資源;
mysql slave因爲是使用vip跟主庫同步,因此故障發生以後能夠自動跟db-1-2作數據同步;mysql

部署

Mysql支持多實例,drbd也支持多分區同步。若是節點流量比較大可使用網卡綁定。
咱們能夠把mysql數據庫和數據文件建立在/data目錄,這樣兩個主節點均可以同步共享。
網卡及地址規劃:web

這裏寫圖片描述
主庫sql

node1: 
eth0      10.37.2.100 //管理地址 
eth1      192.168.52.106//心跳線 
vip        10.37.2.240 //vip

node2: 
eth0    10.37.2.111 
eth1    192.168.52.103 
vip       10.37.2.241


從庫
slave1
eth0    10.37.2.160
eth1    192.168.52.160

slave2
eth0    10.37.2.170
eth1    192.168.52.170

主庫每臺機器至少兩塊硬盤,容量大小一致。數據庫

兩臺主庫安裝drbd和heartbeat,安裝步驟及配置請參考前三個博客。api

heartbeat管理drbd

安裝完成以後,heartbeat咱們還須要作一個配置,由heartbeat管理drbd。
兩個主節點建立/data目錄

mkdir -p /data

主節點格式化drbd0

mkfs -t ext3 /dev/drbd0
安全

主節點掛載

mount /dev/drbd0 /data

heartbeat禁止系統自啓動ruby

[root@node1 data]# chkconfig heartbeat off

vi /etc/ha.d/haresources (注意不要換行,兩個主節點都須要配置)服務器

##heartbeat drbd配置
 node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3
 ##把drbd0設備以ext3方式掛載到/data 上。
##heartbeat nfs 配置
  node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 rsdata

 

啓動heartbeat,查看vip和drbd是否正常啓動.markdown

[root@node1 /]# /etc/init.d/heartbeat start Starting High-Availability services: INFO: Resource is stopped INFO: Resource is stopped Done. [root@node1 data]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 00:0c:29:50:f0:77 brd ff:ff:ff:ff:ff:ff inet 10.37.2.100/24 brd 10.37.2.255 scope global eth0 inet 10.37.2.240/24 brd 10.37.2.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe50:f077/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 00:0c:29:50:f0:81 brd ff:ff:ff:ff:ff:ff inet 192.168.52.100/24 brd 192.168.52.255 scope global eth1 inet6 fe80::20c:29ff:fe50:f081/64 scope link valid_lft forever preferred_lft forever [root@node1 data]# cat /proc/drbd version: 8.4.4 (api:1/proto:86-101) GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@node1, 2017-08-30 11:34:17 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:12 nr:8 dw:172 dr:8549339 al:3 bm:526 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0 [root@node1 data]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_ams-lv_root 36G 5.1G 29G 15% / tmpfs 1.6G 224K 1.6G 1% /dev/shm /dev/sda1 477M 32M 420M 8% /boot /dev/sr0 4.4G 4.4G 0 100% /media/CentOS_6.6_Final /dev/sr0 4.4G 4.4G 0 100% /mnt /dev/drbd0 15G 166M 14G 2% /data heartbeat啓動日誌: ep 01 11:31:27 node1 heartbeat: [24937]: info: Pacemaker support: false Sep 01 11:31:27 node1 heartbeat: [24937]: WARN: Logging daemon is disabled --enabling logging daemon is recommended Sep 01 11:31:27 node1 heartbeat: [24937]: info: ************************** Sep 01 11:31:27 node1 heartbeat: [24937]: info: Configuration validated. Starting heartbeat 3.0.4 Sep 01 11:31:27 node1 heartbeat: [24938]: info: heartbeat: version 3.0.4 Sep 01 11:31:27 node1 heartbeat: [24938]: info: Heartbeat generation: 1503900466 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: UDP Broadcast heartbeat started on port 694 (694) interface eth1 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: UDP Broadcast heartbeat closed on port 694 interface eth1 - Status: 1 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth0 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: bound send socket to device: eth0 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: set SO_REUSEPORT(w) Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: bound receive socket to device: eth0 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: set SO_REUSEPORT(w) Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ucast: started on port 694 interface eth0 to 192.168.52.103 Sep 01 11:31:27 node1 heartbeat: [24938]: info: glib: ping heartbeat started. Sep 01 11:31:28 node1 heartbeat: [24938]: info: G_main_add_TriggerHandler: Added signal manual handler Sep 01 11:31:28 node1 heartbeat: [24938]: info: G_main_add_TriggerHandler: Added signal manual handler Sep 01 11:31:28 node1 heartbeat: [24938]: info: G_main_add_SignalHandler: Added signal handler for signal 17 Sep 01 11:31:28 node1 heartbeat: [24938]: info: Local status now set to: 'up' Sep 01 11:31:28 node1 heartbeat: [24938]: info: Link node1:eth1 up. Sep 01 11:32:26 node1 heartbeat: [24938]: info: Link node2:eth1 up. Sep 01 11:32:26 node1 heartbeat: [24938]: info: Status update for node node2: status up harc(default)[24951]: 2017/09/01_11:32:26 info: Running /etc/ha.d//rc.d/status status Sep 01 11:33:28 node1 heartbeat: [24938]: WARN: node 192.168.52.103: is dead harc(default)[24971]: 2017/09/01_11:33:28 info: Running /etc/ha.d//rc.d/status status Sep 01 11:33:29 node1 heartbeat: [24938]: info: Comm_now_up(): updating status to active Sep 01 11:33:29 node1 heartbeat: [24938]: info: Local status now set to: 'active' Sep 01 11:34:27 node1 heartbeat: [24938]: info: Status update for node node2: status active harc(default)[25001]: 2017/09/01_11:34:27 info: Running /etc/ha.d//rc.d/status status Sep 01 11:34:37 node1 heartbeat: [24938]: info: remote resource transition completed. Sep 01 11:34:37 node1 heartbeat: [24938]: info: remote resource transition completed. Sep 01 11:34:37 node1 heartbeat: [24938]: info: Initial resource acquisition complete (T_RESOURCES(us)) /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[25055]: 2017/09/01_11:34:37 INFO: Resource is stopped Sep 01 11:34:37 node1 heartbeat: [25019]: info: Local Resource acquisition completed. harc(default)[25136]: 2017/09/01_11:34:37 info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp ip-request-resp(default)[25136]: 2017/09/01_11:34:37 received ip-request-resp IPaddr::10.37.2.240/24/eth0 OK yes ResourceManager(default)[25159]: 2017/09/01_11:34:37 info: Acquiring resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[25187]: 2017/09/01_11:34:38 INFO: Resource is stopped ResourceManager(default)[25159]: 2017/09/01_11:34:38 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 start IPaddr(IPaddr_10.37.2.240)[25310]: 2017/09/01_11:34:38 INFO: Adding inet address 10.37.2.240/24 with broadcast address 10.37.2.255 to device eth0 IPaddr(IPaddr_10.37.2.240)[25310]: 2017/09/01_11:34:38 INFO: Bringing device eth0 up IPaddr(IPaddr_10.37.2.240)[25310]: 2017/09/01_11:34:38 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.240 eth0 10.37.2.240 auto not_used not_used /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[25284]: 2017/09/01_11:34:38 INFO: Success ResourceManager(default)[25159]: 2017/09/01_11:34:38 info: Running /etc/ha.d/resource.d/drbddisk data start /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[25438]: 2017/09/01_11:34:38 INFO: Resource is stopped ResourceManager(default)[25159]: 2017/09/01_11:34:38 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 start Filesystem(Filesystem_/dev/drbd0)[25528]: 2017/09/01_11:34:38 INFO: Running start for /dev/drbd0 on /data /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[25520]: 2017/09/01_11:34:38 INFO: Success 

 

錯誤1:

ResourceManager(default)[21772]:        2017/09/02_12:32:34 ERROR: Return code 1 from /etc/ha.d/resource.d/drbddisk
ResourceManager(default)[21772]:        2017/09/02_12:32:35 info: Retrying failed stop operation [drbddisk::data]
ResourceManager(default)[21772]:        2017/09/02_12:32:35 info: Running /etc/ha.d/resource.d/drbddisk data stop
ResourceManager(default)[21772]:        2017/09/02_12:32:37 ERROR: Return code 1 from /etc/ha.d/resource.d/drbddisk
ResourceManager(default)[21772]:        2017/09/02_12:32:37 ERROR: Resource script for drbddisk::data probably not LSB-compliant.
ResourceManager(default)[21772]:        2017/09/02_12:32:37 WARN: it (drbddisk::data) MUST succeed on a stop when already stopped
ResourceManager(default)[21772]:        2017/09/02_12:32:37 WARN: Machine reboot narrowly avoided!
ResourceManager(default)[21772]:        2017/09/02_12:32:37 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 stop

 

解決方案:查看 ha-log日誌,發現heartbeat管理drbd資源一直報錯,能夠先把drbd手動啓動起來。
這樣雖然能夠正常啓動,可是沒有被heartbeat接管,可能會形成某一個節點宕機,另一個節點的drbd會起不起來,最好的方法是讓heartbeat接管drbd。

以上能夠看到,heartbeat正常啓動並正常接管資源(drbd,vip),drbd0正常掛載。
以上drbd跟heartbeat整合完成,下面開始整合mysql。

4臺服務器安裝mysql,採用編譯安裝mysql-5.5.32
安裝cmake
安裝依賴包

yum -y install ncurses-devel bison gcc gcc-c++

 

進到cmake解壓包目錄,編譯安裝

./configure  
   make 
   make install

 

編譯安裝mysql-5.5.32

cmake . -DCMAKE_INSTALL_PREFIX=/data/app/mysql  \
-DMYSQL_DATADIR=/data/app/mysql/data \ -DMYSQL_UNIX_ADDR=/data/app/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ -DENABLED_LOCAL_INFILE=on \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FAST_MUTEXES=1 \ -DWITH_ZLIB=BUNDLED \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_READLINE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_DEBUG=0

 

 

錯誤:

CMake Error: The current CMakeCache.txt directory /data/app/mysql/CMakeCache.txt is different than the directory /home/mysql/mysql-5.5.32 where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt

 

解決:

rm -rf CMakeCache.txt

 

接下來開始編譯安裝

make 
 make install

 

建立mysql帳戶

groupadd -u mysql 
useradd -u 5001 -g mysql -s /sbin/nologin   -d /home/ mysql  mysql

 

注意:「-s /sbin/nologin」 禁止該用戶登陸。
配置
cp support-files/my-small.cnf /etc/my.cnf
配置環境變量:export PATH=/home/mysql/app/bin:$PATH
權限:chown -R mysql.mysql ./mysql/app/data/
chmod -R 1777
初始化:

[root@web app]# /home/mysql/app/scripts/mysql_install_db --basedir=/home/mysql/app 
--datadir=/home/mysql/app/data --user=mysql

 

啓動:

[root@web app]# mysqld_safe --defaults-file=/home/mysql/app/data/my.conf 

 

錯誤1:

InnoDB: Error: space header page consists of zero bytes in data file ./ibdata1
170903 12:43:39 InnoDB: Could not open or create data files.
170903 12:43:39 InnoDB: If you tried to add new data files, and it failed here,
170903 12:43:39 InnoDB: you should now edit innodb_data_file_path in my.cnf back
170903 12:43:39 InnoDB: to what it was, and remove the new ibdata files InnoDB created
170903 12:43:39 InnoDB: in this failed attempt. InnoDB only wrote those files full of
170903 12:43:39 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
170903 12:43:39 InnoDB: remove old data files which contain your precious data!
170903 12:43:39 [ERROR] Plugin 'InnoDB' init function returned error.
170903 12:43:39 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
170903 12:43:39 [ERROR] Unknown/unsupported storage engine: InnoDB
170903 12:43:39 [ERROR] Aborting

 

解決:
看如上提示,mysql在安裝數據文件ibdata1失敗,最簡單的方法就是從新初始化mysql。

其他3臺服務器相似如上步驟安裝mysql。
兩臺從庫開啓binlog,用於同步。
到目前爲止,兩個主節點安裝了heartbeat,drbd和mysql;
heartbeat接管drbd服務,drbd數據盤掛載到/data目錄用於同步兩個主節點數據,咱們能夠把mysql數據文件掛在/data目錄。
手工切換在drbd管理的node1節點,在node1節點執行

[root@node1 data]# /usr/share/heartbeat/hb_standby 
Going standby [all].

[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ams-lv_root
                       36G  7.6G   27G  23% /
tmpfs                 1.6G     0  1.6G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot

 

查看node2節點:

[root@node2 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_web-lv_root
                       35G  5.7G   28G  18% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  1.7G  6.0G  23% /data

 

發現node2節點已經自動掛載了/data目錄。
在node2安裝mysql數據庫,把數據文件,my.cnf和mysql.sock文件映射到/data目錄。(注意權限)
在node2節點啓動mysql :

[root@node2 /]# mysqld_safe --defaults-file=/home/mysql/app/data/my.conf 
Warning: World-writable config file '/home/mysql/app/data/my.conf' is ignored
Warning: World-writable config file '/home/mysql/app/data/my.conf' is ignored
170903 16:29:36 mysqld_safe Logging to '/home/mysql/app/data/node2.err'.
170903 16:29:36 mysqld_safe Starting mysqld daemon with databases from /home/mysql/app/data

 

可知node2節點mysql啓動正常。
因爲heartbeat暫時沒有接管mysql,因此先在node2把mysql殺掉,在node1節點接管資源,在啓動mysql服務.以下:
node2節點殺掉mysql服務:

[root@node2 /]# mysqladmin -uroot -p'ckf77856' shutdown 

 

node1節點接管drbd資源

[root@node1 ~]# /usr/share/heartbeat/hb_takeover local
[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ams-lv_root
                       36G  6.4G   28G  19% /
tmpfs                 1.6G     0  1.6G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  176M  7.5G   3% /data

 

在drbd主節點啓動mysql服務
mysqld_safe --defaults-file=/home/mysql/app/data/my.conf
可知主節點mysql服務正常。

heartbeat管理mysql服務

以上都是手工管理mysql服務,下面使用heartbeat來實現mysql資源接管。
vi /etc/ha.d/haresources,把mysql添加以下配置(drbd兩個節點都需執行)

#node-name resource1 resource2 ... resourceN
 node2 IPaddr::10.37.2.241/24/eth0
 node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql

 

把mysql啓動腳本放在/etc/ha.d/resource.d/下面並添加可執行權限。(drbd兩個節點都需執行)

[root@node2 ~]# cp /home/mysql/app/support-files/mysql.server /etc/ha.d/resource.d/mysql
[root@node2 ~]# chmod +x /etc/ha.d/resource.d/mysql

 

禁止mysql自啓動

chkconfig mysqld off

 

啓動heartbeat服務,在node1,node2節點查看查看vip和drbd角色啓動狀態。
在node1節點查看drbd管理drbd0設備掛載狀況和mysql服務狀態。
測試故障轉移:
在node1節點把heartbeat中止掉,在node2節點查看vip,drbd角色狀態,drbd0設備掛載和mysql服務狀態。

node2節點:
啓動heartbeat

[root@node2 ~]# /etc/init.d/heartbeat start 
Starting High-Availability services: INFO:  Resource is stopped
INFO:  Resource is stopped
Done.

 

查看heartbeat日誌

tail -f /var/log/ha-log
 Sep 08 18:01:54 node2 heartbeat: [9343]: info: **************************
Sep 08 18:01:54 node2 heartbeat: [9343]: info: Configuration validated. Starting heartbeat 3.0.4
Sep 08 18:01:54 node2 heartbeat: [9344]: info: heartbeat: version 3.0.4
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Heartbeat generation: 1503897788
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: UDP Broadcast heartbeat started on port 694 (694) interface eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: UDP Broadcast heartbeat closed on port 694 interface eth1 - Status: 1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: bound send socket to device: eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: set SO_REUSEPORT(w)
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: bound receive socket to device: eth1
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: set SO_REUSEPORT(w)
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ucast: started on port 694 interface eth1 to 192.168.52.100
Sep 08 18:01:54 node2 heartbeat: [9344]: info: glib: ping heartbeat started.
Sep 08 18:01:54 node2 heartbeat: [9344]: info: G_main_add_TriggerHandler: Added signal manual handler
Sep 08 18:01:54 node2 heartbeat: [9344]: info: G_main_add_TriggerHandler: Added signal manual handler
Sep 08 18:01:54 node2 heartbeat: [9344]: info: G_main_add_SignalHandler: Added signal handler for signal 17
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Local status now set to: 'up'
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Link 192.168.52.100:192.168.52.100 up.
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Status update for node 192.168.52.100: status ping
Sep 08 18:01:54 node2 heartbeat: [9344]: info: Link node2:eth1 up.
Sep 08 18:03:55 node2 heartbeat: [9344]: WARN: node node1: is dead
Sep 08 18:03:55 node2 heartbeat: [9344]: info: Comm_now_up(): updating status to active
Sep 08 18:03:55 node2 heartbeat: [9344]: info: Local status now set to: 'active'
Sep 08 18:03:55 node2 heartbeat: [9344]: WARN: No STONITH device configured.
Sep 08 18:03:55 node2 heartbeat: [9344]: WARN: Shared disks are not protected.
Sep 08 18:03:55 node2 heartbeat: [9344]: info: Resources being acquired from node1.
harc(default)[9357]:    2017/09/08_18:03:55 info: Running /etc/ha.d//rc.d/status status
mach_down(default)[9393]:       2017/09/08_18:03:55 info: Taking over resource group IPaddr::10.37.2.240/24/eth0
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Acquiring resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[9425]:    2017/09/08_18:03:55 INFO:  Resource is stopped
Sep 08 18:03:55 node2 heartbeat: [9358]: info: Local Resource acquisition completed.
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[9497]:    2017/09/08_18:03:55 INFO:  Resource is stopped
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 start
IPaddr(IPaddr_10.37.2.240)[9669]:       2017/09/08_18:03:55 INFO: Adding inet address 10.37.2.240/24 with broadcast address 10.37.2.255 to device eth0
IPaddr(IPaddr_10.37.2.240)[9669]:       2017/09/08_18:03:55 INFO: Bringing device eth0 up
IPaddr(IPaddr_10.37.2.240)[9669]:       2017/09/08_18:03:55 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.240 eth0 10.37.2.240 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[9643]:    2017/09/08_18:03:55 INFO:  Success
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/drbddisk data start
/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[9797]:     2017/09/08_18:03:55 INFO:  Resource is stopped
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 start
Filesystem(Filesystem_/dev/drbd0)[9887]:        2017/09/08_18:03:55 INFO: Running start for /dev/drbd0 on /data
/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[9879]:     2017/09/08_18:03:55 INFO:  Success
ResourceManager(default)[9444]: 2017/09/08_18:03:55 info: Running /etc/ha.d/resource.d/mysql  start
mach_down(default)[9393]:       2017/09/08_18:03:56 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down(default)[9393]:       2017/09/08_18:03:56 info: mach_down takeover complete for node node1.
Sep 08 18:03:56 node2 heartbeat: [9344]: info: mach_down takeover complete.
Sep 08 18:03:56 node2 heartbeat: [9344]: info: Initial resource acquisition complete (mach_down)
harc(default)[10120]:   2017/09/08_18:03:56 info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp
ip-request-resp(default)[10120]:        2017/09/08_18:03:56 received ip-request-resp IPaddr::10.37.2.241/24/eth0 OK yes
ResourceManager(default)[10143]:        2017/09/08_18:03:56 info: Acquiring resource group: node2 IPaddr::10.37.2.241/24/eth0
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[10171]:   2017/09/08_18:03:56 INFO:  Resource is stopped
ResourceManager(default)[10143]:        2017/09/08_18:03:57 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.241/24/eth0 start
IPaddr(IPaddr_10.37.2.241)[10294]:      2017/09/08_18:03:57 INFO: Adding inet address 10.37.2.241/24 with broadcast address 10.37.2.255 to device eth0
IPaddr(IPaddr_10.37.2.241)[10294]:      2017/09/08_18:03:57 INFO: Bringing device eth0 up
IPaddr(IPaddr_10.37.2.241)[10294]:      2017/09/08_18:03:57 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.241 eth0 10.37.2.241 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[10268]:   2017/09/08_18:03:57 INFO:  Success
Sep 08 18:04:05 node2 heartbeat: [9344]: info: Local Resource acquisition completed. (none)
Sep 08 18:04:05 node2 heartbeat: [9344]: info: local resource transition completed.

 

vip分配狀況

[root@node2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:2b brd ff:ff:ff:ff:ff:ff
    inet 10.37.2.111/24 brd 10.37.2.255 scope global eth0
    inet 10.37.2.240/24 brd 10.37.2.255 scope global secondary eth0
    inet 10.37.2.241/24 brd 10.37.2.255 scope global secondary eth0
    inet6 fe80::20c:29ff:fed1:92b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.52.111/24 brd 192.168.52.255 scope global eth1
    inet6 fe80::20c:29ff:fed1:935/64 scope link 
       valid_lft forever preferred_lft forever

 

共享文件系統掛載狀態

[root@node2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_web-lv_root
                       35G  5.7G   28G  18% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  176M  7.5G   3% /data

 

drbd狀態

[root@node2 ~]# cat /proc/drbd 
version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@node2, 2017-08-30 11:32:34
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:96304 nr:19388 dw:25092 dr:126028 al:18 bm:24 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

 

查看mysql服務是否能夠正常登陸

[root@node2 ~]# mysql -uroot -pckf77856
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases; +---------------------+
| Database | +---------------------+
| information_schema | | #mysql50#lost+found | | mysql | | performance_schema  |
| test | +---------------------+
5 rows in set (0.01 sec)

 

以上可知,一切資源都正常啓動,mysql能正常登陸。
能夠測試把備節點heart中止模擬備節點主機故障,看主節點是否能正常接管。
能夠經過/usr/share/heartbeat/hb_standby 把本幾點置爲備角色;
/usr/share/heartbeat/hb_takeover 把資源都接管過來,把本幾點置爲主。
角色劃分由heartbeat來負責,根據haresource配置文件來決定,除非人爲設置。
注意:
我把drbd,mysql服務在node1節點配置接管,在通常狀況下,mysql和drbd都會隨着node1漂移而漂移。
node2節點宕機,node1接管全部的服務;
node1都node2正常,drbd和mysql服務會在node1上啓動;
node1節點宕機,node1節點的資源和ip都會在node2上啓動;因此mysql服務對外提供的地址和端口應該跟node1 vip和端口一致。
node1和node2凡是跟主機節點相關的文件及配置都儘可能放在/data目錄或者都配置成同樣,這裏建議都改爲同樣,如 binlog文件,relaylog文件,日誌文件(錯誤日誌文件,查詢日誌,慢查詢日誌),sock文件和配置文件
這裏寫圖片描述

錯誤1:
node2節點不能正常接管node1的資源,可是node1能夠接管node2。
防火牆也沒問題,查node2後臺日誌

Sep 10 12:01:22 node2 heartbeat: [4416]: info: foreign HA resource release completed (standby).
Sep 10 12:01:22 node2 heartbeat: [2029]: info: Local standby process completed [foreign].
Sep 10 12:01:23 node2 heartbeat: [2029]: info: all clients are now resumed
Sep 10 12:01:23 node2 heartbeat: [2029]: info: Link 10.37.2.240:10.37.2.240 up.
Sep 10 12:01:23 node2 heartbeat: [2029]: WARN: Late heartbeat: Node 10.37.2.240: interval 53813710 ms
Sep 10 12:01:23 node2 heartbeat: [2029]: info: Status update for node 10.37.2.240: status ping Sep 10 12:01:25 node2 heartbeat: [2029]: WARN: 1 lost packet(s) for [node1] [13:15] Sep 10 12:01:25 node2 heartbeat: [2029]: info: remote resource transition completed. Sep 10 12:01:25 node2 heartbeat: [2029]: info: No pkts missing from node1! Sep 10 12:01:25 node2 heartbeat: [2029]: info: Other node completed standby takeover of foreign resources. Sep 10 12:03:15 node2 heartbeat: [2029]: info: Received shutdown notice from 'node1'. Sep 10 12:03:15 node2 heartbeat: [2029]: info: Resources being acquired from node1. Sep 10 12:03:15 node2 heartbeat: [4714]: info: acquire local HA resources (standby). ResourceManager(default)[4740]: 2017/09/10_12:03:15 info: Acquiring resource group: node2 IPaddr::10.37.2.241/24/eth0 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[4789]: 2017/09/10_12:03:15 INFO: Running OK Sep 10 12:03:15 node2 heartbeat: [4714]: info: local HA resource acquisition completed (standby). Sep 10 12:03:15 node2 heartbeat: [2029]: info: Standby resource acquisition done [foreign]. /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.241)[4795]: 2017/09/10_12:03:15 INFO: Running OK Sep 10 12:03:15 node2 heartbeat: [4715]: info: Local Resource acquisition completed. harc(default)[4947]: 2017/09/10_12:03:15 info: Running /etc/ha.d//rc.d/status status mach_down(default)[4964]: 2017/09/10_12:03:15 info: Taking over resource group IPaddr::10.37.2.240/24/eth0 ResourceManager(default)[4991]: 2017/09/10_12:03:15 info: Acquiring resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[5019]: 2017/09/10_12:03:15 INFO: Resource is stopped ResourceManager(default)[4991]: 2017/09/10_12:03:15 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 start IPaddr(IPaddr_10.37.2.240)[5142]: 2017/09/10_12:03:15 INFO: Adding inet address 10.37.2.240/24 with broadcast address 10.37.2.255 to device eth0 IPaddr(IPaddr_10.37.2.240)[5142]: 2017/09/10_12:03:15 INFO: Bringing device eth0 up IPaddr(IPaddr_10.37.2.240)[5142]: 2017/09/10_12:03:15 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-10.37.2.240 eth0 10.37.2.240 auto not_used not_used /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[5116]: 2017/09/10_12:03:15 INFO: Success ResourceManager(default)[4991]: 2017/09/10_12:03:16 info: Running /etc/ha.d/resource.d/drbddisk data start /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[5270]: 2017/09/10_12:03:16 INFO: Resource is stopped ResourceManager(default)[4991]: 2017/09/10_12:03:16 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 start Filesystem(Filesystem_/dev/drbd0)[5360]: 2017/09/10_12:03:16 INFO: Running start for /dev/drbd0 on /data /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[5352]: 2017/09/10_12:03:16 INFO: Success ResourceManager(default)[4991]: 2017/09/10_12:03:16 info: Running /etc/ha.d/resource.d/mysql start ResourceManager(default)[4991]: 2017/09/10_12:03:17 ERROR: Return code 1 from /etc/ha.d/resource.d/mysql ResourceManager(default)[4991]: 2017/09/10_12:03:17 CRIT: Giving up resources due to failure of mysql ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Releasing resource group: node1 IPaddr::10.37.2.240/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysql ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/mysql stop ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext3 stop Filesystem(Filesystem_/dev/drbd0)[5864]: 2017/09/10_12:03:17 INFO: Running stop for /dev/drbd0 on /data Filesystem(Filesystem_/dev/drbd0)[5864]: 2017/09/10_12:03:17 INFO: Trying to unmount /data Filesystem(Filesystem_/dev/drbd0)[5864]: 2017/09/10_12:03:17 INFO: unmounted /data successfully /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[5856]: 2017/09/10_12:03:17 INFO: Success ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/drbddisk data stop ResourceManager(default)[4991]: 2017/09/10_12:03:17 info: Running /etc/ha.d/resource.d/IPaddr 10.37.2.240/24/eth0 stop IPaddr(IPaddr_10.37.2.240)[6025]: 2017/09/10_12:03:17 INFO: IP status = ok, IP_CIP= /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_10.37.2.240)[5999]: 2017/09/10_12:03:17 INFO: Success mach_down(default)[4964]: 2017/09/10_12:03:17 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired mach_down(default)[4964]: 2017/09/10_12:03:17 info: mach_down takeover complete for node node1. Sep 10 12:03:17 node2 heartbeat: [2029]: info: mach_down takeover complete. Sep 10 12:03:46 node2 heartbeat: [2029]: WARN: node 10.37.2.240: is dead Sep 10 12:03:46 node2 heartbeat: [2029]: info: Link 10.37.2.240:10.37.2.240 dead. harc(default)[6134]: 2017/09/10_12:03:46 info: Running /etc/ha.d//rc.d/status status Sep 10 12:03:47 node2 heartbeat: [2029]: WARN: node node1: is dead Sep 10 12:03:47 node2 heartbeat: [2029]: info: Dead node node1 gave up resources. Sep 10 12:03:47 node2 heartbeat: [2029]: info: Link node1:eth1 dead. hb_standby(default)[6171]: 2017/09/10_12:03:47 Going standby [foreign]. Sep 10 12:03:48 node2 heartbeat: [2029]: info: node2 wants to go standby [foreign] Sep 10 12:03:58 node2 heartbeat: [2029]: WARN: No reply to standby request. Standby request cancelled.

 

–解決 :
其中能夠看到,最開始資源都正常,可是我注意到‘ERROR: Return code 1 from /etc/ha.d/resource.d/mysql’啓動mysql報了個錯致使後面把服務都殺掉了。
嘗試在node2手動掛載/data目錄,而後啓動mysql報‘/home/mysql/app/bin/mysqld: File ‘/home/mysql/app/data/mysql-bin.index’ not found (Errcode: 13)’錯誤,懷疑drbd沒有執行,而後在node1角色切換成備,在node2觀察發如今很短一個時間內會mount /data目錄,而後又被umount了,多是啓動mysql失敗而後資源接管失敗,最後發現兩個節點的數據目錄(/data)所屬組id不同,真是粗心害死人。

auto_failback on參數講解:
auto_failback 若是設置爲打開,若是發生故障切換,當主修復好了以後,會自動把mysql服務切換到主節點,可是有一個問題,mysql服務是切換過去了,若是資源沒有切換到主節點是否是出問題了。
以上實現了mysql高可用,heartbeat控制vip(對外提供服務地址),數據文件(/data)和mysql服務切換,vip和mysql服務在node1,node2之間漂移,始終保證vip能夠鏈接到mysql服務,數據文件經過drbd在node1,node2之間同步,始終保證兩邊數據一致,確保不會產生腦裂問題,從而保證服務高可用。

配置mysql主從同步

node1,node2在同一個時間點只能有一個提供服務,爲了保證數據安全,把主節點數據同步到備節點。

從庫
slave1
eth0 10.37.2.160
eth1 192.168.52.160

注意,因爲主庫兩個節點有可能會發生切換,因此備庫跟主庫同步地址須要時主庫對外提供服務器的vip即配置node1的vip(10.37.2.240)。

mysql主從同步

  1. 主庫配置
    1.1 修改主庫my.cnf
主庫開啓binlog,肯定 server-id惟一性。
server-id=1   #設置服務器id,爲1表示主服務器,注意:若是原來的配置文件中已經有這一行,就不用再添加了。
log_bin=mysql-bin  #啓動MySQ二進制日誌系統,注意:若是原來的配置文件中已經有這一行,就不用再添加了。
binlog-do-db=osyunweidb  #須要同步的數據庫名,若是有多個數據庫,可重複此參數,每一個數據庫一行;若是想同步整個庫,這個參數可不寫。
binlog-ignore-db=mysql   #不一樣步mysql系統數據庫;mysql數據庫是系統配置信息,不建議同步。

 

1.2 主庫添加同步用戶及權限

grant replication slave on *.* to 'bobo'@'10.37.2.%' identified by 'ckf77856';
flush privileges;

 

1.3 主庫備份

mysql> flush table with read lock;( MySql 5.1使用 flush tables with read lock;)
mysql> show master status;
[root@node1 ~]# mysqldump -uroot -pckf77856 -S /home/mysql/app/3306/mysql.sock -A -B -F --events --master-data=2 >/tmp/3306_master.sql;
注意:鎖表以後備份數據庫使用了‘-F’參數,會強制刷新binlog會致使位置點(postition)變化,因爲鎖表無dml操做,因此不用擔憂會有數據未備份,建議不要加‘-F’。
添加「--master-data=2」參數在備份信息有記錄binlog位置。
mysql> unlock tables;

 

2 從庫配置

2.1 修改從庫my.cnf

vi /etc/my.cnf   #編輯配置文件,在[mysqld]部分添加下面內容
server-id=2   #此參數不能與集羣其餘庫重複,惟一值。
log-bin=mysql-bin  #啓動MySQ二進制日誌系統,注意:若是原來的配置文件中已經有這一行,就不用再添加了; 
replication-do-db=osyunweidb  #須要同步的數據庫名,若是有多個數據庫,可重複此參數,每一個數據庫一行;若是想同步整個庫,這個參數可不寫。
replication -ignore-db=mysql   #不一樣步mysql系統數據庫;mysql數據庫是系統配置信息,不建議同步。
replication-do-table=
replication-ignore-table=
replication-wild-do-table=''; 通配同步表
replication-wild-ignore-table=''

 

2.2 恢復從庫

[root@web ~]# mysqld_safe --defaults-file=/home/mysql/app/3307/my.conf #啓動
[root@web ~]# mysql -uroot -pabcd.1234 -S /home/mysql/app/3307/mysql.sock </tmp/3306_master.sql
[root@web ~]# mysql -ubobo -pckf77856 -h 192.168.21.169 -P3306 #遠程登陸3306端口數據庫

 

2.3 修改備庫同步參數

mysql> change master to 
    -> master_host='10.37.2.240',     -> master_port=3306,     -> master_user='bobo',     -> master_password='ckf77856',     -> master_log_file='mysql3306-bin.000455', #能夠不要     -> master_log_pos=107; #能夠不要 Query OK, 0 rows affected (0.02 sec)

 

錯誤1:

mysql> change master to  master_host='10.37.2.240', master_port=3306, master_user='bobo', master_password='ckf77856';
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
170909 18:33:51 [ERROR] Failed to open the relay log './rac1-relay-bin.000004' (relay_log_pos 250)
170909 18:33:51 [ERROR] Could not find target log during relay log initialization

 

以上可知,從庫找不到主庫傳輸過來的日誌,檢查從庫relay-log.info查看日誌,發現從庫以前跟別的庫同步過,刪除以前的relay-log.info,從新建立。

2.4 備庫開啓同步

mysql> start slave;
mysql> show slave status\G;
mysql> show slave status\G
*************************** 1. row ***************************
 Slave_IO_State: Waiting for master to send event
 Master_Host: 10.37.2.240
 Master_User: bobo
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: mysql-bin.000002
 Read_Master_Log_Pos: 107
 Relay_Log_File: slave1-relay-bin.000011
 Relay_Log_Pos: 253
 Relay_Master_Log_File: mysql-bin.000002
 Slave_IO_Running: Yes
 Slave_SQL_Running: Yes
 Replicate_Do_DB: 
 Replicate_Ignore_DB: 
 Replicate_Do_Table: 
 Replicate_Ignore_Table: 
 Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
 Last_Errno: 0
 Last_Error: 
 Skip_Counter: 0
 Exec_Master_Log_Pos: 107
 Relay_Log_Space: 453
 Until_Condition: None
 Until_Log_File: 
 Until_Log_Pos: 0
 Master_SSL_Allowed: No
 Master_SSL_CA_File: 
 Master_SSL_CA_Path: 
 Master_SSL_Cert: 
 Master_SSL_Cipher: 
 Master_SSL_Key: 
 Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
 Last_IO_Errno: 0
 Last_IO_Error: 
 Last_SQL_Errno: 0
 Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
 Master_Server_Id: 1
1 row in set (0.00 sec)

 

 

至此主從同步完成。
能夠測試同步結果,在主庫建立一個表而後在備庫查詢看是否存在。

若是從庫級聯從庫,須要打開binlog 和 log-slave-updates參數。
主庫binlog文件和Position點跟從庫的relay-log.info、master.info信息一致。
relay-log.info信息提供sql salve進程使用,master.info提供給io slave進程使用。

錯誤1:

mysql> start slave;
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO

 

–解決:檢查change_master是否正確,通常狀況下主從同步,會形成主從的server-id也重複,主要改爲不一致就能夠。

[+拓展]
若是從庫作級聯(備庫同步到另一臺機器),須要設置從庫,步驟以下:
1. 備庫開啓binlog
2. 備庫設置log-slave-updates參數
3. 備庫設置過時時間 expire_logs_days = 7
4. 同步備庫數據主機設置 change master參數。

主從同步完成,這個時候測試切換主庫,看備庫是否還能正常同步數據。
node1是primary角色,如今要把node2切換成syandby角色,在node1執行:
[root@node1 ~]# /usr/share/heartbeat/hb_standby
Going standby [all].

查看node2資源
node2 ip信息

[root@node2 data]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:2b brd ff:ff:ff:ff:ff:ff
    inet 10.37.2.111/24 brd 10.37.2.255 scope global eth0
    inet 10.37.2.241/24 brd 10.37.2.255 scope global secondary eth0
    inet 10.37.2.240/24 brd 10.37.2.255 scope global secondary eth0
    inet6 fe80::20c:29ff:fed1:92b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:d1:09:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.52.111/24 brd 192.168.52.255 scope global eth1
    inet6 fe80::20c:29ff:fed1:935/64 scope link 
       valid_lft forever preferred_lft forever

 

 

node2 /data掛載信息

[root@node2 data]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_web-lv_root
                       35G  5.7G   28G  18% /
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/drbd0            8.1G  176M  7.5G   3% /data

 

node2 drbd狀態及角色

[root@node2 data]# cat /proc/drbd
version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@node2, 2017-08-30 11:32:34
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:432 nr:584 dw:1016 dr:6225 al:12 bm:3 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[root@node2 data]# netstat -pan|grep 330
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      27899/mysqld        
tcp        0      0 10.37.2.240:3306            10.37.2.160:53472           ESTABLISHED 27899/mysqld

 

在node2節點對數據庫操做,在備庫查詢node2數據是否傳輸到備庫。
在node2對數據庫操做

mysql> show databases; +---------------------+
| Database | +---------------------+
| information_schema | | #mysql50#lost+found | | mysql | | p1 | | performance_schema  |
| test | +---------------------+
6 rows in set (0.02 sec)

mysql> create database d111;
Query OK, 1 row affected (0.01 sec)

備庫查看數據

mysql> show databases; +---------------------+
| Database | +---------------------+
| information_schema | | bobo | | d111 | | d3306 | | #mysql50#lost+found | | merg | | mysql | | p1 | | performance_schema  |
| pvs                 |
| test | +---------------------+
11 rows in set (0.00 sec)

 

注意:heartbeat檢測對方心跳使用vip來傳遞信號。

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息