主机名 | IP地址 | 硬盘(新增) |
node1 | 192.168.43.101 | 10G X 1 |
node2 | 192.168.43.102 | 10G X 1 |
node3 | 192.168.43.103 | 10G X 1 |
node4 | 192.168.43.104 | 10G X 1 |
KVM | 192.168.43.105 |
[root@kvm ~]# cd /mnt
[root@kvm mnt]# ls
CentOS-7-x86_64-DVD-1708.iso
[root@kvm mnt]#
安装KVM相关软件包
[root@kvm ~]# yum install qemu-kvm qemu-kvm-tools virt-install qemu-img bridge-utils libvirt virt-manager -y
##qemu-kvm kvm模块
##qemu-kvm-tools kvm调试工具
##virt-install 构建虚拟机命令行工具
##qemu-img qemu组件,创建磁盘,启动虚拟机等
##bridge-utils 网络支持工具
##libvirt 虚拟机管理工具
##virt-manager 图形化管理工具
查看虚拟化功能是否安装成功
[root@kvm ~]# cat /proc/cpuinfo | grep vmx ##查看是否支持虚拟化
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec arat
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec arat
[root@kvm ~]# lsmod | grep kvm ##检查kvm是否安装
kvm_intel 170086 0
kvm 566340 1 kvm_intel
irqbypass 13503 1 kvm
[root@kvm ~]#
配置桥接网卡,Vmware虚拟机还是在NAT模式,方便连接外网
cd /etc/sysconfig/network-scripts
cp -p ifcfg-ens33 ifcfg-br0
vim ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="e2d1c8b2-c2ab-4689-89d1-e9c6aac7e162"
DEVICE="ens33"
ONBOOT="yes"
#IPADDR="192.168.43.105"
#PREFIX="24"
#GATEWAY="192.168.43.2"
#DNS1="192.168.43.2"
IPV6_PRIVACY="no"
BRIDGE=br0
vim ifcfg-br0
TYPE="Bridge"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
IPADDR="192.168.43.105"
PREFIX="24"
GATEWAY="192.168.43.2"
DNS1="192.168.43.2"
IPV6_PRIVACY="no"
[root@kvm network-scripts]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@kvm network-scripts]# ifconfig
br0: flags=4163 mtu 1500
inet 192.168.43.105 netmask 255.255.255.0 broadcast 192.168.43.255
inet6 fe80::635a:2003:b1b3:6bcd prefixlen 64 scopeid 0x20
ether 00:0c:29:92:43:7a txqueuelen 1000 (Ethernet)
RX packets 212 bytes 13958 (13.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 54 bytes 9003 (8.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163 mtu 1500
ether 00:0c:29:92:43:7a txqueuelen 1000 (Ethernet)
RX packets 20861 bytes 27042556 (25.7 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 4056 bytes 412896 (403.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 115 bytes 19628 (19.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 115 bytes 19628 (19.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:ba:20:1e txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@kvm network-scripts]#
[root@kvm network-scripts]# systemctl stop firewalld
[root@kvm network-scripts]# setenforce 0
[root@kvm network-scripts]#
开启虚拟化功能
[root@kvm ~]# systemctl start libvirtd
[root@kvm ~]# systemctl enable libvirtd
[root@kvm ~]#
开启图形化界面
部署GFS分布式复制卷
四节点虚拟机添加一块新的磁盘、格式化、挂载,修改好各自的主机名,关闭防火墙,四台节点服务器都要执行
创建分区、格式化、挂载磁盘脚本
vim disk.sh
#! /bin/bash
echo "the disks exist list:"
##grep出系统所带磁盘
fdisk -l |grep '磁盘 /dev/sd[a-z]'
echo "=================================================="
PS3="chose which disk you want to create:"
##选择需要创建的磁盘编号
select VAR in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit
do
case $VAR in
sda)
##本地磁盘就退出case语句
fdisk -l /dev/sda
break ;;
sd[b-z])
#create partitions
echo "n ##创建磁盘
p
w" | fdisk /dev/$VAR
#make filesystem
##格式化
mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null
#mount the system
mkdir -p /data/${VAR}"1" &> /dev/null
###永久挂载
echo -e "/dev/${VAR}"1" /data/${VAR}"1" xfs defaults 0 0\n" >> /etc/fstab
###使得挂载生效
mount -a &> /dev/null
break ;;
quit)
break;;
*)
echo "wrong disk,please check again";;
esac
done
##node1为例
hostnamectl set-hostname node1 //永久修改主机名
systemctl stop firewalld //关闭防火墙
setenforce 0 //关闭SElinux功能
bash disk.sh //执行创建磁盘的脚本
挂载如下,以node1为例
在所有主机上建立映射关系,以node1为例
[root@node1 ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.43.101 node1
192.168.43.102 node2
192.168.43.103 node3
192.168.43.104 node4
192.168.43.105 kvm
在node1-4中安装GFS源,开启GFS功能,以node1为例,如下
[root@node1 ~]# cd /opt
[root@node1 opt]# rz ##通过rz工具,下载gfs源包
[root@node1 opt]# ls
gfsrepo.zip rh
[root@node1 opt]# unzip gfsrepo.zip ##解压gfs源包
[root@node1 opt]# cd /etc/yum.repos.d
[root@node1 yum.repos.d]# mkdir bak ##将本地源放到bak中
[root@node1 yum.repos.d]# mv C* bak
[root@node1 yum.repos.d]# vim local.repo ##新建属于gfs的源
[GLFS]
name=glfs
baseurl=file:///opt/gfsrepo
gpgcheck=0
enabled=1
[root@node1 yum.repos.d]# cd
##安装GFS文件系统
[root@node1 ~]# yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-fdma
##开启GFS功能
[root@node1 ~]# systemctl start glusterd.service
仅在node1中添加节点,且查看集群
[root@node1 ~]# gluster peer probe node2
peer probe: success.
[root@node1 ~]# gluster peer probe node3
peer probe: success.
[root@node1 ~]# gluster peer probe node4
peer probe: success.
[root@node1 ~]# gluster peer status
Number of Peers: 3
Hostname: node2
Uuid: 43d361d6-dae4-4bc6-a770-256540827e15
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: 9c3ae410-d1cc-4f82-b098-08111fdea7e1
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: eceda60b-9447-4462-bc2e-61c0b6a82011
State: Peer in Cluster (Connected)
[root@node1 ~]#
在node2上查看集群
[root@node2 ~]# gluster peer status
Number of Peers: 3
Hostname: node1
Uuid: bf2bd8cc-2224-4dbc-9ce3-2c7f9f815fd6
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: 9c3ae410-d1cc-4f82-b098-08111fdea7e1
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: eceda60b-9447-4462-bc2e-61c0b6a82011
State: Peer in Cluster (Connected)
[root@node2 ~]#
创建分布式复制卷,在node1上执行命令
###创建名为kvmdata的分布式复制卷
[root@node1 ~]# gluster volume create kvmdata replica 2 node1:/data node2:/data node3:/data node4:/data force
volume create: kvmdata: success: please start the volume to access data
###开启卷
[root@node1 ~]# gluster volume start kvmdata
volume start: kvmdata: success
###查看kvmdata的具体信息
[root@node1 ~]# gluster volume info kvmdata
Volume Name: kvmdata
Type: Distributed-Replicate
Volume ID: 59e9c924-358a-4738-b4aa-debccba9b5c7
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/data
Brick2: node2:/data
Brick3: node3:/data
Brick4: node4:/data
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
[root@node1 ~]#
在kvm上配置GFS的客户端
配置gfs源,安装GFS
[root@kvm ~]# cd /opt
[root@kvm opt]# rz
[root@kvm opt]# unzip gfsrepo.zip
[root@kvm opt]# cd /etc/yum.repos.d/
[root@kvm yum.repos.d]# mkdir bak
[root@kvm yum.repos.d]# mv C* bak
[root@kvm yum.repos.d]# vim local.repo
[GLFS]
name=glfs
baseurl=file:///opt/gfsrepo
gpgcheck=0
enabled=1
##安装依赖包
[root@kvm yum.repos.d]# yum -y install glusterfs glusterfs-fuse
挂载GFS
[root@kvm ~]# mkdir /kvmdata ##创建一个合适目录
[root@kvm ~]# vim /etc/fstab
node1:kvmdata /kvmdata glusterfs defaults,_netdev 0 0
[root@kvm ~]# mount -a ##永久挂载,使得文件生效
[root@kvm ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda2 xfs 10G 8.5G 1.6G 85% /
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 9.0M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda5 xfs 4.0G 37M 4.0G 1% /home
/dev/sda1 xfs 4.0G 174M 3.9G 5% /boot
tmpfs tmpfs 781M 28K 781M 1% /run/user/0
/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64
node1:kvmdata fuse.glusterfs 30G 10G 21G 34% /kvmdata
[root@kvm ~]#
基于kvm主机的GFS,在KVM虚拟化平台上创建虚拟机
创建两个文件,在/kvmdata中
cd /kvmdata/
mkdir kgc_disk kgc_iso //kgc_disk作为磁盘存储位置;kgc_iso作为镜像存储位置
cd /opt/
mv CentOS-7-x86_64-DVD-1708.iso /kvmdata/kgc_iso/ //将镜像拷贝到刚刚创建好的文件里
创建两个存储池,详细步骤,看上一篇
创建卷
新建虚拟机
查看虚拟机是否正常使用
模拟故障
由于分布式复制卷,可以在node1-4中查看,kvm中的文件
关闭node2,查看KVM平台上的虚拟机是否能够开启,使用
作者:Mr.aaa