RHCS的整理概括與實踐

1 基礎理論html

1.1 羣集的概念node

羣集由兩個或多個計算機(節點或成員)組成一塊兒執行任務的系統mysql

1.2 羣集的分類linux

1.2.1 存儲型(Storage)git

提供一致的文件系統映象,容許服務器同步讀寫單個文件系統(經過Red Hat GFS提供存儲羣集功能)算法

1.2.2 高可用型(High Availability)sql

消除單點故障並將故障自動恢復(服務自動遷移到一個正常的節點),提供服務可持續的服務。
數據庫

1.2.3 負載均衡型(Load balancing)json

將網絡服務請求分攤到多個羣集節點來分攤負載,並提供單點失效檢測並平滑將服務轉移至正常節點。
vim

1.2.4 高性能型(High performance)

羣集經過多節點執行並行運算來提升應用程序性能。

1.3 羣集的基礎結構

1.3.1 羣集管理

Cluster Manager簡稱CMAN

- CMAN是一個分佈式羣集管理工具

- CMAN用於管理羣集的成員、消息和通知

- CMAN監控每一個節點的運行狀態來了解節點成員之間的關係

- CMAN負責通知底層進而作出相應的調整

Quorum

- 以太網消息決定(由節點票vote的50%加1組成)

- 以太網消息和quorum磁盤決定(由用戶指定的條件組成)

1.3.2 鎖管理

Distributed Lock Manager(DLM)分佈式鎖管理器

- DLM運行於集羣中的每一個節點

- GFS經過鎖管理器的鎖機制來同步訪問文件系統元數據

- CLVM經過鎖管理器來同步更新數據到LVM卷和卷組

1.3.3 Fencing

當CMAN認爲某個節點已經發生故障,他將告知其餘集羣基礎構件並在收到通知後對故障設備進行保護

保護方法:

- Power fencing(電源保護),控制電源關閉不可用節點

- Fibre Channel switch fencing(光釺通道開關保護),禁用不可用節點的光釺通道端口

- GNBD fencing 

- 其餘保護,禁I/O或不可用節點電源(IBM Bladecenters,PAP,DRAC/MC,HP ILO,IPMI,IBM RSAII等)

1.3.4 配置文件管理

Cluster Configuration System(CCS),用於羣集配置文件管理與配置文件在個節點之間同步。

監控的配置文件(XML文件):

/etc/cluster/cluster.conf

配置文件屬性以下:

- 羣集名,顯示羣集的名字、羣集配置文件版本、當節點加入羣集和被保護鎖使用的基本保護時間屬性

- 羣集,顯示羣集的每一個節點,指定節點名、節點ID、quorum vote的數量和其保護方法

- 保護設備,顯示羣集的保護設備和保護設備的具體參數

- 被管理的資源,顯示建立羣集所須要的資源(含故障切換與的定義、資源)

1.4 高可用性管理服務

1.4.1 rgmanager守護進程

實現off-the-shelf應用程序冷失效恢復(控制應用程序和羣集資源來組成高可用性羣集服務)

1.4.2 羣集資源

如IP地址、應用程序初始化腳本或GFS共享分區等

1.4.3 故障切換域

有資格運行特定羣集服務的節點子集(羣集服務可運行和可遷移的節點稱爲一個切換域)

1.5 GFS

GFS是容許羣集節點同時訪問某個共享的塊設備的羣集文件系統

1.5.1 GFS的特色

- GFS是一個原生的文件系統

- GFS直接與Linux內核文件系統接口VFS層通信

- GFS使用分佈式元數據和多個日誌來優化羣集操做

- GFS使用鎖管理器來協調I/O

- GFS節點中數據被修改,其餘節點立馬可見

- GFS提供配合(quota)和多重日子和多路徑支持

- GFS提供良好的性能、靈活性和經濟性

1.5.2 做用

- GFS提供節點間的數據共享

- GFS提供羣集GFS節點單一和一致的文件系統命名空間視圖

- GFS容許安裝和運行應用程序而無需瞭解底層的存儲基礎結構

1.5.2 CLVM的守護進程

/etc/init.d/clvmd

1.6 羣集邏輯卷管理器

Cluster Logical Volume Manager(CLVM),卷管理經過羣集邏輯卷管理器進行管理

- clvmd,羣集邏輯卷管理器守護進程

- HA-LVM,高可用性邏輯卷管理代理

1.7 全局網絡塊設備

Global Network Block Device(GNBD),提供經過TCP/IP訪問GFS塊設備的功能

1.7.1 GNBD client

GNBD客戶端運行於GFS的節點上並提供基於光釺通道或single-initiator SCSI通道從GNBD服務導入塊級別的設備

1.7.2 GNBD server

GNBD服務端容許從本地存儲(直接附加存儲或SAN存儲)導出塊級別設備

1.8 LVS

LVS提供兩臺以上的服務器之間的IP負載均衡能力(虛擬IP)

- 提供負載均衡能力

- 提供服務狀態檢測能力

1.8.1 LVS的工做原理

wKioL1eFpFHR0VLLAADUYcntLwA331.png

- pulse守護進程運行於活動或備份的LVS路由器上

- pulse定時發送heartbeat到活動路由器公共接口,確保路由器正常工做

- pulse啓動lvs守護進程響應備份lvs路由的heartbeat查詢

- lvs守護進程調用ipvsadm工具配置和維護內核的IPVS(IP虛擬服務器)路由表

- lvs爲每臺服務器配置的虛擬服務器啓動一個nanny進程

- nanny進程檢查一臺真實服務器上的一個配置好的服務狀態,並通告lvs守護進程服務器的當前狀態

- lvs檢測到真實服務器nanny進程通告的故障則會指引ipvsadm從ipvs路由表中刪除真實的服務器條目

- 備份路由沒有收到lvs路由的響應,執行初始化故障切換

- 備份路由調用send_arp將全部虛擬IP地址從新分配給備份LVS路由的MAC地址

- 備份路由經過專用或公用的接口向活動LVS路由器發送關閉lvs守護進程命令

- 備份路由經過啓動lvs守護進程來接受虛擬服務器的請求

1.8.2 LVS的架構

wKiom1eFpInSOL0LAACg-DmVtQg092.png

- LVS路由層(含活動路由和備用路由,鏈接公共網絡和專用網絡)

- 真實服務器層(鏈接專用網絡)

1.8.3 負載均衡算法

- Round-Robin Scheduling(輪詢調度),按順序分發請求到各真實服務器

- Weighted Round-Robin Scheduling(加權輪詢調度),按權重給予性能好服務器更多請求處理機會

- Least-Connection Scheduling(最小鏈接調度),給予請求處理較少的服務器分配跟多的請求

- Weighted Least-connection(權重最小鏈接調度),基於負載數按權重調整給性能好服務器更多的請求

- Locality-Based Least-Connection Scheduling(基於局部性的最小鏈接調度) ,

 根據請求的單臺服務器目的IP少的給予更多分配

- Locality-Based Least-Connection Scheduling with Replication Scheduling

 (帶複製的基於局部最小鏈接調度),

 同上,但使用IP地址服務器子集管理,超載服務器從子集刪除,服務器池中鏈接少的加入子集。

- Source Hash Scheduling(源此地址散列調度),

 按靜態散列表查找源IP地址將請求發送到服務器池

1.8.4 服務器狀態檢測

- 調用send/expect scripts動態檢測服務器狀態

- 調用外部程序檢測服務器狀態

1.8.5 路由方法

- Network Address Translation(NAT),網絡地址轉換(有瓶頸問題)

- 直接路由(只處理轉入的數據包)

1.8.6 持久性和防火牆標記

- persistence,lvs指定時間內記住最後的鏈接,並把請求定位到最後一次鏈接的服務器

- firewall mask,比較適合處理ftp這種根據端口進行鏈接分組狀況

1.9 羣集管理工具

1.9.1 Conga

提供WEB界面配置和管理羣集和存儲的軟件組件

Conga的組件:

- luci,運行於管理端,經過ricci與多個羣集和機器通信,包含三個功能

 - homebase,提供添加、刪除機器和用戶及配置用戶權限的工具

 - cluster,提供建立和配置羣集的工具

 - storage,提供遠程管理存儲設備的工具

- ricci,運行於羣集中的每臺機器

1.9.2 羣集的管理圖形界面

Cluster Configuration Tool以分層結構的形式在面板左邊顯示配置文件(/etc/cluster/cluster.conf)的羣集配置

- Cluster Nodes,顯示羣集節點

- Fence Devices,顯示保護設備

- Managed Resources,顯示故障切換與、資源和服務

 - Failover Domains,配置一個或多個羣集節點子集

 - Resource,配置用於高可用性服務的共享資源

 - Services,建立和配置高可用服務

1.9.3 羣集的命令行工具

- ccs_tool,羣集配置工具

- cman_tool,羣集管理工具

- fence_tool,保護工具

- clustat,羣集狀態工具

- clusvcadm,羣集用戶服務管理工具


1.10 服務的端口

wKiom1eDWRzBrPzUAACCIIP_tQ0853.png

2 實踐部分

2.1 環境信息

2.1.1 業務與管理網絡

vip=10.168.0.50


rhcsh01:

ipaddress=10.168.0.51/24

gateway=10.168.0.1

device=eth0

hostname=node01.cmdschool.org

OS=CentOS 6.8


rhcsh02:

ipaddress=10.168.0.52/24

gateway=10.168.0.1

device=eth0

hostname=node02.cmdschool.org

OS=CentOS 6.8


rhcsm:

ipaddress=10.168.0.59

gateway=10.168.0.1

device=eth0

hostname=rhcsm.cmdschool.org

OS=CentOS 6.8


storage:

ipaddress=10.168.0.200

gateway=10.168.0.1

device=eth0

hostname=storage01.cmdschool.org

OS=CentOS 7.1

2.1.2 存儲網絡

node01(rhcsh01):

ipaddress=10.0.0.51/24

device=eth1


node02(rhcsh02):

ipaddress=10.0.0.52/24

device=eth1


storage:

ipaddress=10.0.0.200/24

device=eth1

2.1.3 心跳網絡

node01(rhcsh01):

ipaddress=192.168.1.51/24

device=eth2


node02(rhcsh02):

ipaddress=192.168.1.52/24

device=eth2


rhcsm:

ipaddress=192.168.1.59/24

device=eth2

2.2 環境配置

2.2.1 關閉selinux

In rhcsh0[1-2] & rhcsm:

getenforce

如顯示以下:

Enforcing

則執行

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

2.2.2 關閉防火牆

In rhcsh0[1-2] & rhcsm

/etc/init.d/iptables stop
chkconfig iptables off

2.2.3 名稱解析配置

In rhcsh0[1-2] & rhcsm & storage:

vim /etc/hosts

輸入以下內容:

192.168.1.51 node01.cmdschool.org
192.168.1.52 node02.cmdschool.org
192.168.1.59 rhcsm.cmdschool.org

2.2.4 時間與時區配置

In rhcsh0[1-2] & rhcsm & storage:

1)時區配置

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

2)安裝ntp同步服務

yum install -y chrony

3)啓動ntp服務

#CentOS 6
/etc/init.d/chronyd start
chkconfig chronyd on
#CentOS 7
systemctl start chronyd
systemctl enable chronyd

4)同步時間

chronyc sources

2.3 存儲服務配置

In storage:

2.3.1 建立存儲分區(200G)

fdisk /dev/sdb

詳細嚮導以下:

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe381cdb3.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

檢查新建的分區

partprobe
ll /dev/sdb*

2.3.2 安裝iscsi服務端相關包

yum -y install targetcli

2.3.3 啓動服務並配置默認啓動

systemctl enable target
systemctl restart target

2.3.4 配置存儲服務

targetcli

詳細嚮導以下:

/>help
/>ls
/> /backstores/block create dev=/dev/sdb1 name=scan1
/>ls
/> /iscsi create wwn=iqn.2014-11.org.cmdschool:storage01
/>ls
/>cd /iscsi/iqn.2014-11.org.cmdschool:storage01/tpg1/
/iscsi/iqn.20...:storage01/tpg1>ls
/iscsi/iqn.20...:storage01/tpg1>acls/ create wwn=iqn.2014-11.org.cmdschool:node
/iscsi/iqn.20...:storage01/tpg1>ls
/iscsi/iqn.20...:storage01/tpg1>luns/ create /backstores/block/san1
/iscsi/iqn.20...:storage01/tpg1>cd /
/>ls
/>saveconfig
/>exit

檢查配置

vim /etc/target/saveconfig.json

2.3.5 防火牆配置

firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload

2.4 節點連接iscsi存儲

In rhcsh0[1-2]:

2.4.1 安裝基礎包

yum install -y iscsi* tree

2.4.2 配置服務默認啓動

chkconfig iscsid on


2.4.3 修改配置

vim /etc/iscsi/initiatorname.iscsi

輸入以下內容:

InitiatorName=iqn.2014-11.org.cmdschool:node

2.4.4 發現scsi存儲

iscsiadm -m discovery node -t st -p 10.0.0.200:3260

校驗

tree /var/lib/iscsi/

顯示以下:

/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2014-11.org.cmdschool:storage01
│       └── 10.0.0.200,3260,1
│           └── default
├── send_targets
│   └── 10.0.0.200,3260
│       ├── iqn.2014-11.org.cmdschool:storage01,10.0.0.200,3260,1,default -> /var/lib/iscsi/nodes/iqn.2014-11.org.cmdschool:storage01/10.0.0.200,3260,1
│       └── st_config
├── slp
└── static

2.4.5 檢查存儲發現狀況

fdisk -l

可發現新增長的硬盤

[...]
Disk /dev/sdb: 214.7 GB, 214747316224 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk identifier: 0x00000000

注:若是沒法發現請執行重啓操做

2.4.6 分區並格式化存儲(單節點作便可)

1)存儲分區

fdisk /dev/sdb

嚮導以下:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x62b02e8b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-26108, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-26108, default 26108): 
Using default value 26108

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

2)存儲格式化

mkfs.ext4 /dev/sdb1

2.4.7 刪除iscsi存儲(無需執行)

iscsiadm -m session -i /dev/sdb
iscsiadm -m node --logoutall=all
iscsiadm -m node -o delete -T iqn.2014-11.org.cmdschool:storage01 -p 10.0.0.200
iscsiadm -m session

2.5 節點配置

In rhcsh0[1-2]

2.5.1 安裝yum源

yum groupinstall "High Availability" "Resilient Storage"

2.5.2 配置認證密碼

passwd ricci

2.5.3 啓動服務並配置默認啓動

/etc/init.d/ricci start
chkconfig ricci on

2.6 MySQL安裝配置

2.6.1 yum源安裝

In rhcsh0[1-2]:

 yum install -y mysql mysql-devel mysql-server

2.6.2 配置數據庫

1)修改數據庫目錄

In rhcsh0[1-2]:

vim  /etc/my.cnf

加入以下參數

[mysqld]
bind-address=10.168.0.50
datadir=/data

2)修改目錄權限

In rhcsh0[1-2]:

chown -R mysql:mysql /data/

3)啓動服務

In rhcsh01:

/etc/init.d/mysqld start

4)初始化服務

In rhcsh01:

mysql_secure_installation

嚮導以下:

[...]
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
[...]
Remove anonymous users? [Y/n] y
 ... Success!
[...]
Disallow root login remotely? [Y/n] n
 ... skipping.
[...]
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
[...]
Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...
[...]

5)中止服務

In rhcsh01:

/etc/init.d/mysqld stop

2.7 集羣luci管理器配置

In rhcsm:

2.7.1 安裝yum源

 yum groupinstall -y "High Availability Management"

2.7.2 啓動luci管理器並配置開機啓動

/etc/init.d/luci start
chkconfig luci on

2.7.3 瀏覽器測試

https://10.168.0.59:8084

wKioL1eF7bXhW2moAACtQF5Ry50676.png

注:以上使用系統賬號登陸

2.8 luci管理器操做

In client:

2.8.1 建立羣集並添加節點

1)建立羣集

wKiom1eG3IGQUnP8AAEyc6KlU6w724.png

2)建立完成

wKiom1eG3IGBE7hSAAD3E0VeQv0228.png

2.8.2 建立故障域

1)建立故障域

wKioL1eG3NfxzmVIAAE4PuFGttc793.png

2)建立完成

wKioL1eG3Nix1Q3tAAE-EziY90M200.png

2.8.3 添加資源-虛擬IP

1)添加虛擬IP

wKiom1eG3VbisZEgAAEztCtmCHg777.png

2)添加完成

wKioL1eG3VeC-qmMAAEeTwWNFEI776.png

2.8.4 集羣的服務組-添加虛擬IP資源

1)添加虛擬IP資源到羣集服務組

wKioL1eG3buyzvJRAAGTZNMXcUc897.png

2)添加完成

wKiom1eG3buxutpoAAD1RBz4K_w548.png

3)客戶端驗證

wKioL1eG3bziXATfAABmDg8d0GY741.png

4)節點驗證

wKiom1eG3byBEpuFAADHY4aFQDA046.png

2.8.5 集羣的服務組-添加共享硬盤資源

1)添加共享硬盤資源

wKiom1eG4AzQkvaoAAFP2OawmrM747.png

2)選擇集羣服務組

wKiom1eG4AzQiR7OAADnkrPrMds561.png

3)往集羣組添加共享磁盤

wKioL1eG4A3xeikvAAFzbl7M5wM732.png

4)驗證共享磁盤掛載

wKioL1eG4A7QPm7MAAAxKMKaqi0094.png

2.8.6 集羣的服務組-添加數據庫服務資源

1)添加MySQL服務到資源

wKioL1eINhKS86RfAAE9jdbUKJI756.png

2)添加完成顯示

wKiom1eINhPhpvoGAAEp7ho8dA4182.png

3)選擇羣組

wKiom1eINhPzxeG0AADzj_NbC4M427.png

4)往羣集組添加資源-MySQL服務

wKioL1eINhTzUEglAAFlAu5mzY8465.png

5)添加完畢顯示

wKioL1eINhXgLAX2AAGRGZL62Tk718.png

6)驗證

wKioL1eIPM_hXfmbAAF56uUWd_I226.png

-------------------------------------------------------------------------

參閱文獻:

官方文檔

---------

集羣管理

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Cluster_Administration/index.html

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html-single/Cluster_Administration/index.html

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html-single/Cluster_Administration/index.html

集羣管理中文版

https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/6/html-single/Cluster_Administration/index.html

集羣套件概述

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Cluster_Suite_Overview/index.html

集羣管理員

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Cluster_Administration/index.html

基於集羣套件的Oracle HA

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Configuration_Example_-_Oracle_HA_on_Cluster_Suite/index.html

Conga的配置使用

https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/6/html-single/Cluster_Administration/index.html#ch-config-conga-CA

非官方文檔

----------

http://www.limingit.com/sitecn/itjq/1645_1694.html

http://linux.it.net.cn/e/cluster/qun/2015/0226/13496.html

http://www.linuxidc.com/Linux/2013-08/89166.htm

http://blog.chinaunix.net/uid-26931379-id-3558604.html

http://blog.chinaunix.net/uid-26931379-id-3558613.html

www.tuicool.com/articles/JjqUve

http://wangziyin.blog.51cto.com/6948950/1303239/

ISCSI資料:

http://linux-iscsi.org/wiki/Targetcli

http://czmmiao.iteye.com/blog/2055805

IBM多路徑軟件

http://blog.chinaunix.net/uid-316679-id-384033.html

相關文章
相關標籤/搜索