lvs+keepalived+glusterfs群集
- 一、部署lvs+keepalived服務器
- 1.lvs主調度器配置
- 2.lvs副調度器配置
- 二、部署節點服務器
- 1.安裝Apache服務
- 2.配置群集介面
- 3.調整/proc內核引數,關閉ARP回應
- 4.添加到群集IP地址的本地路由記錄
- 5.客戶機進行驗證
- 1)客戶機瀏覽器訪問:http://192.168.1.188
- 2)lvs服務器 查看負載均衡情況
- 三、部署glusterfs服務器
- 1.磁盤磁區
- 2.格式化并掛載
- 3.配置hosts檔案
- 4.配置yum本地源,安裝環境包
- 5.創建群集,并添加節點
- 6.創建復制卷
- 四、web集群即glusterfs客戶端配置
- 1.web1,web2安裝客戶端軟體
- 2.修改hosts檔案
- 3.驗證:ping -c 2 node1 測驗
- 4.掛載glusterfs檔案系統
- 1)web1上操作
- 2)web2上操作
- 驗證:在node1,node2分別訪問掛載目錄,查看是否有復制檔案存在
- 五、專案驗證
- 驗證1:關閉主調度器,查看整個集群是否能夠正常作業
- 驗證2:關閉web集群節點1,查看整個集群是否能夠正常作業
- 驗證3:關閉存盤節點1,查看整個集群是否能夠正常作業
準備作業:
| 主機名 | 作業系統 | IP地址 | 擔任角色 |
|---|---|---|---|
| master | CentOS7 | 192.168.1.1 | lvs主調度器 |
| backup | CentOS7 | 192.168.1.2 | lvs副調度器 |
| web1 | CentOS7 | 192.168.1.3 | web服務器1,glusterfs客戶端 |
| web2 | CentOS7 | 192.168.1.4 | web服務器2,glusterfs客戶端 |
| node1 | Centos7 | 192.168.1.5 | 分布式檔案系統節點1 |
| node2 | Centos7 | 192.168.1.6 | 分布式檔案系統節點2 |
glusterfs軟體包從下面鏈接下載:
https://pan.baidu.com/s/19P8ReLY4fdVnrfYfVD9mnA
提取碼:7unm
實驗描述:
- 搭建 lvs–DR web 群集負載均衡調度系統,利用 keepalived 技術實作調度器的雙機熱備
- 資料存盤采用分布式檔案系統群集 glusterfs
- web群集提供服務的群集IP為192.168.1.188
一、部署lvs+keepalived服務器
1.lvs主調度器配置
192.168.1.1
[root@localhost ~]# hostnamectl set-hostname master #配置主機名
[root@localhost ~]# bash
[root@master ~]# mount /dev/cdrom /media/cdrom #掛載光碟
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@master ~]# yum -y install keepalived ipvsadm
[root@master ~]# systemctl enable keepalived #設定開機自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/keepalived.service to /usr/lib/systemd/system/keepalived.service.
[root@master ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@master ~]# vim /etc/keepaplived/keepalived.conf
global_defs {
router_id 1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.1.188
}
}
virtual_server 192.168.1.188 80 {
delay_loop 15
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.1.3 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.1.4 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
[root@master ~]# ipvsadm -C
[root@master ~]# modprobe ip_vs
[root@master ~]# lsmod | grep ip_vs
ip_vs 145497 0
nf_conntrack 139224 1 ip_vs
libcrc32c 12644 3 xfs,ip_vs,nf_conntrack
[root@master ~]# echo "modprobe ip_vs" >> /etc/rc.local
[root@master ~]# systemctl restart keepalived
[root@master ~]# ip a #查看漂移IP是否存在

2.lvs副調度器配置
192.168.1.2
[root@localhost ~]# hostnamectl set-hostname backup #配置主機名
[root@localhost ~]# bash
[root@backup ~]# mount /dev/cdrom /media/cdrom #掛載光碟
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@backup ~]# yum -y install keepliaved ipvsadm
[root@backup ~]# systemctl enable keepalived #設定開機自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/keepalived.service to /usr/lib/systemd/system/keepalived.service.
[root@backup ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@backup ~]# vim /etc/keepalived/keepalived.conf
lvs副調度器和主調度器配置配置一致,但要做以下修改:
將 router_id 1 改為 router_id 2
將 state MASTER 改為 state BACKUP
將 priority 100 改為 priority 99
[root@backup ~]# modprobe ip_vs
[root@backup ~]# lsmod | grep ip_vs
[root@backup ~]# echo "modprobe ip_vs" >> /etc/rc.local
[root@backup ~]# systemctl restart keepalived
為了驗證lvs+keepalived集群是否正常運行,部署httpd的本地網站目錄進行驗證
二、部署節點服務器
1.安裝Apache服務
192.168.1.3:
[root@localhost ~]# hostnamectl set-hostname web1
[root@localhost ~]# bash
[root@web1 ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@web1 ~]# yum -y install httpd
[root@web1 ~]# echo "<h1>This is web1</h1>" > /var/www/html/index.html
[root@web1 ~]# systemctl enable httpd
[root@web1 ~]# systemctl start httpd
[root@web1 ~]# curl 192.168.1.3 #訪問本機測驗
<h1>This is web1</h1>
192.168.1.4:
[root@localhost ~]# hostnamectl set-hostname web2
[root@localhost ~]# bash
[root@web2 ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@web2 ~]# yum -y install httpd
[root@web2 ~]# echo "<h1>This is web2</h1>" > /var/www/html/index.html
[root@web2 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@web2 ~]# systemctl start httpd
[root@web2 ~]# curl 192.168.1.4 #訪問本機測驗
<h1>This is web2</h1>
2.配置群集介面
web1,web2配置一致
[root@web1 ~]# cat <<END >> /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVEICE=lo:0
ONBOOT=yes
IPADDR=192.168.1.188
NETMASK=255.255.255.255
END
[root@web1 ~]# systemctl restart network
[root@web1 ~]# ifconfig lo:0

3.調整/proc內核引數,關閉ARP回應
web1,web2配置一致:
[root@web1 ~]# cat <<END >> /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
END
[root@web1 ~]# sysctl -p #讓其生效

4.添加到群集IP地址的本地路由記錄
[root@web1 ~]# echo "/sbin/route add -host 192.168.1.188 dev lo:0" >> /etc/rc.local
[root@web1 ~]# route add -host 192.168.1.188 dev lo:0

5.客戶機進行驗證
1)客戶機瀏覽器訪問:http://192.168.1.188
192.168.1.188是剛才設定的漂移IP


2)lvs服務器 查看負載均衡情況
[root@master ~]# ipvsadm -ln

驗證成功后,web1,web2 分別洗掉首頁,為后續掛載glusterfs做準備
[root@web1 ~]# rm -rf /var/www/html/*
[root@web1 ~]# ll /var/www/html/
總用量 0

三、部署glusterfs服務器
分別為node1,node2各添加一塊20G硬碟,分成兩個磁區,各10G容量
1.磁盤磁區
[root@localhost ~]# fdisk /dev/sdb
-------
命令(輸入 m 獲取幫助):n #創建磁區
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):p #創建主磁區
磁區號 (1-4,默認 1): #回車
起始 扇區 (2048-41943039,默認為 2048): #回車
將使用默認值 2048
Last 扇區, +扇區 or +size{K,M,G} (2048-41943039,默認為 41943039):+10G #容量設定為10G
磁區 1 已設定為 Linux 型別,大小設為 10 GiB
-------
命令(輸入 m 獲取幫助):n #創建磁區
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p #創建主磁區
磁區號 (2-4,默認 2): #回車
起始 扇區 (20973568-41943039,默認為 20973568): #回車
將使用默認值 20973568
Last 扇區, +扇區 or +size{K,M,G} (20973568-41943039,默認為 41943039):+10G #容量設定為10G
磁區 2 已設定為 Linux 型別,大小設為 10 GiB
命令(輸入 m 獲取幫助):wq #保存退出
2.格式化并掛載
[root@localhost ~]# mkfs.xfs /dev/sdb1 #格式化sdb1
[root@localhost ~]# mkfs.xfs /dev/sdb2 #格式化sdb2
[root@localhost ~]# mkdir -p /brick1/sdb{1..2} #創建兩個掛載點
[root@localhost ~]# mount /dev/sdb1 /brick1/sdb1 #掛載sdb1磁區
[root@localhost ~]# mount /dev/sdb2 /brick1/sdb2 #掛載sdb2磁區
[root@localhost ~]# cat <<END >> /etc/fstab #設定開機自掛載
/dev/sdb1 /brick1/sdb1 xfs defaults 0 0
/dev/sdb2 /brick1/sdb2 xfs defaults 0 0
END
[root@localhost ~]# df -hT #查看是否掛載成功
3.配置hosts檔案
[root@localhost ~]# cat <<END >> /etc/hosts
192.168.1.5 node1
192.168.1.6 node2
END
[root@localhost ~]# hostnamectl set-hostname node1 #設定主機名
[root@localhost ~]# bash

4.配置yum本地源,安裝環境包
node1,node2操作步驟一致:
[root@node1 ~]# cd /mnt/
上傳gfsrepo檔案夾里的軟體到此目錄
[root@node1 mnt]# mount /dev/cdrom /media/cdrom #掛載光碟
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@node1 mnt]# yum -y install attr psmisc #安裝依賴包
[root@node1 mnt]# vi /etc/yum.repos.d/GLFS.repo
[GLFS]
name=GLFS
baseurl=file:///mnt
enable=1
gpgcheck=0
[root@node1 mnt]# yum clean all #清空yum快取
[root@node1 mnt]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
[root@node1 mnt]# systemctl start glusterd #開啟gluster
[root@node1 mnt]# systemctl enable glusterd #設定開機自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.
[root@node1 mnt]# netstat -anpt | grep glusterd #查看埠是否開啟
tcp 0 0 0.0.0.0:24007 0.0.0.0:* LISTEN 16040/glusterd
5.創建群集,并添加節點
node1,node2上任意一臺上操作即可
[root@node1 ~]# gluster peer probe node1
peer probe: success. Probe on localhost not needed
[root@node1 ~]# gluster peer probe node2
peer probe: success.
[root@node1 ~]# gluster peer status #查看節點狀態
Number of Peers: 1
Hostname: node2
Uuid: 42e9950f-e49d-44f2-80c9-502a31bf6b8b
State: Peer in Cluster (Connected)

6.創建復制卷
[root@node1 ~]# gluster volume create rep-web1 replica 2 node1:/brick1/sdb1 node2:/brick2/sdb1 force
volume create: rep-web1: success: please start the volume to access data
[root@node1 ~]# gluster volume start rep-web1 #開啟復制卷
volume start: rep-web1: success
[root@node1 ~]# gluster volume info rep-web1 #查看復制卷狀態
Volume Name: rep-web1
Type: Replicate
Volume ID: 8e9ad069-cd65-4db8-8be8-2a5d8bafecce
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node1:/brick1/sdb1
Brick2: node2:/brick2/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
[root@node1 ~]# gluster volume create rep-web2 replica 2 node1:/brick1/sdb2 node2:/brick2/sdb2 force
volume create: rep-web2: success: please start the volume to access data
[root@node1 ~]# gluster volume start rep-web2 #開啟復制卷
volume start: rep-web2: success
[root@node1 ~]# gluster volume info rep-web2 #查看府志卷狀態
Volume Name: rep-web2
Type: Replicate
Volume ID: 2732d944-415b-4625-b192-7274201474ed
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node1:/brick1/sdb2
Brick2: node2:/brick2/sdb2
Options Reconfigured:
transport.address-family: inet
nfs.disable: on


四、web集群即glusterfs客戶端配置
1.web1,web2安裝客戶端軟體
[root@web1 ~]# yum -y install attr psmisc #安裝依賴包
[root@web1 ~]# cd /mnt/
上傳gfsrepo檔案夾里的軟體到此目錄
[root@web1 mnt]# vi /etc/yum.repos.d/GLFS.repo
[GLFS]
name=GLFS
baseurl=file:///mnt
enable=1
gpgcheck=0
[root@web1 mnt]# yum clean all #清空yum快取
[root@web1 mnt]# yum -y install glusterfs glusterfs-fuse
2.修改hosts檔案
[root@web1 mnt]# cat <<END >> /etc/hosts
192.168.1.5 node1
192.168.1.6 node2
END
3.驗證:ping -c 2 node1 測驗

4.掛載glusterfs檔案系統
1)web1上操作
[root@web1 ~]# mount.glusterfs node1:rep-web1 /var/www/html/
[root@web1 ~]# echo "<h1>This is we1</h1>" > /var/www/html/index.html
2)web2上操作
[root@web2 ~]# mount.glusterfs node1:rep-web2 /var/www/html/
[root@web2 ~]# echo "<h1>This is web2</h1>" > /var/www/html/index.html
驗證:在node1,node2分別訪問掛載目錄,查看是否有復制檔案存在

五、專案驗證
驗證1:關閉主調度器,查看整個集群是否能夠正常作業


驗證2:關閉web集群節點1,查看整個集群是否能夠正常作業

驗證3:關閉存盤節點1,查看整個集群是否能夠正常作業

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/206530.html
標籤:其他
