heartbeat mysql nfs 高可用mysql集羣

一  環境準備

二  拓撲結構

三  安裝heartbeat

四  配置NFS服務

五  安裝mysql

六  crm 配置資源

 

一  環境準備

操作系統

centos 6.4 x86_64 最小化安裝

如使用yum 安裝的方式 centos5.5 安裝的是V2.X ,centos 6.4 安裝的是V3.X

YUM 安裝 Vim man ntp “development tools” “server platform development” “desktop platform development”

mysql-5.5.37  (採用通用二進制包安裝方式)

配置 epel YUM 源

關閉 防火牆 selinux

 

二 拓撲結構

image

三 安裝heartbeart

1 節點之間主機名可以互相解析

web1 ,web2

[root@web1 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.132  web1.daphne.com  web1
192.168.200.133  web2.daphne.com  web2

2 節點之間時間同步

[root@web1 ~]# ntpdate ntp.api.bz

3 節點之間配置SSH互信

[root@web1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@web1 ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
[root@web1 ~]# ssh web2
[root@web2 ~]# 
 
[root@web2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[root@web2 ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
[root@web2 ~]# ssh web1
[root@web2 ~]# 

 

3 heartbeat 組件說明

  • heartbeat 核心組件
  • heartbeat-gui 圖形管理接口
  • heartbeat-ldirectord 爲lvs高可用提供規則自動生成及後端realserver健康狀態檢查組件
  • heartbeat-pils 裝載庫插件接口
  • heartbeat-stonith

4 安裝heartbeat

heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-gui-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

yum install PyXML libnet pygtk2-libglade net-snmp-libs
yum install  libnet
rmp -ivh heartbeat-*

 

配置heartbeat

1配置文件說明

[root@web1 ~]# cd /etc/ha.d/
[root@web1 ha.d]# ls
authkeys  harc         rc.d           resource.d
ha.cf     haresources  README.config  shellfuncs

說明 安裝好的heartbeat 默認沒有配置文件,但提供了配置文件樣本

[root@web1 ha.d]# cd /usr/share/doc/heartbeat-2.1.4/
[root@web1 heartbeat-2.1.4]# ls 
apphbd.cf         faqntips.html        haresources         Requirements.html
authkeys          faqntips.txt         hb_report.html      Requirements.txt
AUTHORS           GettingStarted.html  hb_report.txt       rsync.html
ChangeLog         GettingStarted.txt   heartbeat_api.html  rsync.txt
COPYING           ha.cf                heartbeat_api.txt   startstop
COPYING.LGPL      HardwareGuide.html   logd.cf
DirectoryMap.txt  HardwareGuide.txt    README
我們需要  authkeys ha.cf  兩個配置文件
[root@web1 heartbeat-2.1.4]# cp authkeys ha.cf  /etc/ha.d/

2 配置authkeys

[root@web1 ha.d]# openssl rand -hex 8 >> authkeys 
[root@web1 ha.d]# vim authkeys 
auth 2
#1 crc
#2 sha1 HI!
#3 md5 Hello!
2 sha1 7c0f241959ee845d
[root@web1 ha.d]# chmod 600 authkeys 

3 配置ha.cf文件

[root@web1 ha.d]# vim ha.cf 

修改心跳信息的傳播方式 可以採用 組播 廣播 單播

bcast  eth0

配置集羣中的節點數

node web1.daphne.com
node web2.daphne.com
crm on

4 複製以上兩個文件到web2上

[root@web1 ha.d]# scp authkeys ha.cf  web2:/etc/ha.d/

5 啓動web1與web2

先啓動備份節點

[root@web2 ~]# service heartbeat  start
[root@web1 ~]# service heartbeat  start
 

6 查看集羣狀態

[root@web1 ~]# crm_mon

Node: web2.daphne.com (1eb4208c-1790-491c-bbc9-4b4b8669a6da): online
Node: web1.daphne.com (f145a88d-245f-4b92-b31c-89670502927e): online兩個節點都在線,資源暫時沒有配置

 

7 測試一下hb_gui圖形界面

(如遇到圖形界面亂碼   yum install  system-config-kickstart  )

[root@web1 ~]# hb_gui

 

SNAGHTML260d802

 

四 配置NFS 服務

1  創建數據庫目錄   (生成環境可使用LVM)

[root@bogon ~]# mkdir -pv /mydata/data/

2 創建mysql用戶

在 web1,web2,nfs三個節點都要創建ID保持相同

[root@web1 ~]# useradd -r -u 127 mysql

3 修改數據庫目錄用戶

[root@bogon ~]# chown -R mysql:mysql /mydata/

4 安裝NFS服務

[root@bogon ~]# yum install nfs*
[root@bogon ~]# service rpcbind start
[root@bogon ~]# service nfs start

5 修改NFS配置文件

[root@bogon ~]# vim /etc/exports 
/mydata/data 192.168.200.0/24(rw,no_root_squash)

6 重新輸出一下NFS

[root@bogon ~]# exportfs -avr
exporting 192.168.200.0/24:/mydata/data

7 查看輸出的NFS共享存儲

[root@bogon ~]# showmount -e 192.168.200.130
Export list for 192.168.200.130:
/mydata/data 192.168.200.0/24

8 測試掛載

[root@web1 ~]# mkdir -pv /mydata/data/
[root@web1 ~]# mount -t nfs 192.168.200.130:/mydata/data/ /mydata/data/
[root@web2 ~]# mkdir -pv /mydata/data/
[root@web2 ~]# mount -t nfs 192.168.200.130:/mydata/data /mydata/data

 

(centos 6.4  採用NFS 4v  即使各個節點有相同用戶,也顯示nobody用戶,爲避免此問題 可以修改 /etc/idmapd.conf 文件

#Domain = local.domain.edu  

  Domain = daphne.com 

  服務器端客戶端都要修改

service rpcidmapd restart)

 

五 安裝msyql

 

web1

1  安裝mysql

[root@web1 ~]# tar -zxvf mysql-5.5.37-linux2.6-x86_64.tar.gz -C /usr/local/
[root@web1 ~]# cd /usr/local/
[root@web1 ~]# ln -sv mysql-5.5.37-linux2.6-x86_64 mysql

2 初始化數據庫

[root@web1 ~]# yum install libaio
[root@web1 ~]# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql

3 提供配置文件

[root@web1 ~]# cp support-files/my-large.cnf /etc/my.cnf
[root@web1 ~]# vim /etc/my.cnf 
datadir = /mydata/data
4 提供mysql啓動腳本
[root@web1 ~]# cp support-files/mysql.server /etc/init.d/mysqld
[root@web1 ~]# chmod +x /etc/init.d/mysqld

5 啓動mysql

[root@web1 ~]# service mysqld start

6 查看數據目錄

[root@web1 ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.200.130:/mydata/data/ on /mydata/data type nfs (rw,vers=4,addr=192.168.200.130,clientaddr=192.168.200.132)
[root@web1 ~]# cd /mydata/data/
[root@web1 data]# ls 
ibdata1           mysql-bin.000002  mysql-bin.000007     web1.daphne.com.pid
ib_logfile0       mysql-bin.000003  mysql-bin.index      web2.daphne.com.err
ib_logfile1       mysql-bin.000004  performance_schema
mysql             mysql-bin.000005  test
mysql-bin.000001  mysql-bin.000006  web1.daphne.com.err

7 測試登陸

[root@web1 data]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.37-log MySQL Community Server (GPL)

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> 

8 停止mysql服務  卸載/mydata/data

[root@web1 ~]# service mysqld stop
[root@web1 ~]# umount /mydata/data/

 

web2

1 安裝mysql

[root@web1 ~]# tar -zxvf mysql-5.5.37-linux2.6-x86_64.tar.gz -C /usr/local/
[root@web1 ~]# cd /usr/local/
[root@web1 ~]# ln -sv mysql-5.5.37-linux2.6-x86_64 mysql

2 將web1的配置文件 啓動腳本拷貝至 web2

[root@web1 ~]# scp /etc/my.cnf web2:/etc/
[root@web1 ~]# scp /etc/init.d/mysqld  web2:/etc/init.d/

3 啓動mysql

[root@web2 ~]# service mysqld start
Starting MySQL.. SUCCESS! 

4 測試登陸

[root@web2 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.37-log MySQL Community Server (GPL)

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> 

5 停止mysql  卸載/mydata/data

[root@web2 ~]# service mysqld stop
Shutting down MySQL. SUCCESS! 
[root@web2 ~]# umount /mydata/data/

 

六 crm資源配置

1 新建組資源

adsa

2 設置組ID名

sadf

3 添加VIP資源

12321

4 添加 共享存儲資源

asdf[1]

5 添加mysql 服務資源

sdfs[4]

6 資源添加完成

sdf 

7  啓動全部資源

sfd

8 查看IP

asdf

10 查看資源狀態

as

11  web1 連接測試mysql

asd

12 mysql  授權

mysql> grant all on *.* to 'root'@'192.168.200.%' identified by 'redhat';

mysql> flush privileges;

13 測試集羣

[root@bogon ~]# mysql -uroot -predhat -h 192.168.200.10
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.37-log MySQL Community Server (GPL)

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.

 

14 模擬故障 

1 將web2節點 切換到 standby,資源全部切換到web1上

12323

2 查看web1接口

[root@web1 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:D7  
          inet addr:192.168.200.132  Bcast:192.168.200.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe7d:c1d7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13573 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7765 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:17996747 (17.1 MiB)  TX bytes:831831 (812.3 KiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:D7  
          inet addr:192.168.200.10  Bcast:192.168.200.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1      Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:E1  
          inet addr:192.168.10.132  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe7d:c1e1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:830 (830.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
3 遠程測試mysql
[root@nfs ~]# mysql -uroot -predhat -h 192.168.200.10
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.37-log MySQL Community Server (GPL)

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> 

 

高可用mysql集羣,演示完畢

 
 
 
 
 
 

 

 

 

 

 

 

 

 

 

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