KVM + GFS virtual platform to build

KVM + GFS virtual platform to build

Experimental topology:

Here Insert Picture Description

Experimental demand

In order to build a KVM virtual platform, we need to create a striped volume copy, set up the environment and provide distributed storage capabilities for virtual hosts,

GFS cluster structures

Here Insert Picture Description
We need to add a hard drive for each node in the GFS, as they will strip loaded with space to copy volumes.

Environment to build

1, for the four node node, each adding a 20G removable hard disk, and open virtualization engine on the client

Here Insert Picture Description

2, change the name of node node

They were revised to node1, node2, node3, node4

[root@localhost ~]#hostnamectl set-hostname node1
[root@localhost ~]# su

3, the disk is formatted on four servers, and mount

Here we use the script executes the mount

#进入opt目录
[root@node1 ~]# cd /opt
#磁盘格式化、挂载脚本
[root@node1 opt]# vim a.sh
#! /bin/bash
echo "the disks exist list:"
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)
        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
#给于脚本执行权限
[root@node1 opt]# chmod +x a.sh

The script scp pushed to three other servers

scp a.sh [email protected]:/opt
scp a.sh [email protected]:/opt
scp a.sh [email protected]:/opt
Execute scripts on four servers, and complete

This is just a sample

[root@node1 opt]# ./a.sh
the disks exist list:
==================================================
1) sdb
2) quit
chose which disk you want to create:1      //选择要格式化的盘
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 0x37029e96.

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

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

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

4, set the hosts file

On the first modification node1

#在文件末尾添加
vim /etc/hosts
192.168.45.133 node1
192.168.45.130 node2
192.168.45.134 node3
192.168.45.136 node4

Scp file by the hosts pushed to other servers and clients

#将/etc/hosts文件推送给其他主机
[root@node1 opt]# scp /etc/hosts [email protected]:/etc/hosts
[email protected]'s password: 
hosts                                      100%  242    23.6KB/s   00:00    
[root@node1 opt]# scp /etc/hosts [email protected]:/etc/hosts
[email protected]'s password: 
hosts                                      100%  242   146.0KB/s   00:00    
[root@node1 opt]# scp /etc/hosts [email protected]:/etc/hosts
[email protected]'s password: 
hosts              

View pushing the case on other servers
Here Insert Picture Description

Shut down all servers and client firewall
[root@node1 ~]# systemctl stop firewalld.service 
[root@node1 ~]# setenforce 0

Yum warehouse built on the client and server node

#进入yum文件路径
[root@node1 ~]# cd /etc/yum.repos.d/
#创建一个空文件夹
[root@node1 yum.repos.d]# mkdir abc
#将CentOS-文件全部移到到abc下
[root@node1 yum.repos.d]# mv CentOS-* abc
#创建私有yum源
[root@node1 yum.repos.d]# vim GLFS.repo
[demo]
name=demo
baseurl=http://123.56.134.27/demo
gpgcheck=0
enable=1

[gfsrepo]
name=gfsrepo
baseurl=http://123.56.134.27/gfsrepo
gpgcheck=0
enable=1

#重新加载yum源
[root@node1 yum.repos.d]# yum list

Install the necessary software packages

[root@node1 yum.repos.d]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
Start glusterd on four servers, and set to boot from the start
[root@node1 yum.repos.d]# systemctl start glusterd.service 
[root@node1 yum.repos.d]# systemctl enable glusterd.service

Adding node information

[root@node1 yum.repos.d]# gluster peer probe node2
peer probe: success. 
[root@node1 yum.repos.d]# gluster peer probe node3
peer probe: success. 
[root@node1 yum.repos.d]# gluster peer probe node4
peer probe: success. 

View node information on other servers

[root@node1 yum.repos.d]# gluster peer status

Creating a distributed replicated volumes

#创建分布式复制卷
[root@node2 yum.repos.d]# gluster volume create dis-rep replica 2 node1:/data/sdb1 node2:/data/sdb1 node3:/data/sdb1 node4:/data/sdb1 force
volume create: dis-rep: success: please start the volume to access data
#开启复制卷
[root@node2 yum.repos.d]# gluster volume start dis-rep 
volume start: dis-rep: success

KVM virtual host operating

1, we will need to install the system image package to mount on a virtual machine

#挂载软件包
mount.cifs //192.168.100.3/lzp /mnt
#先将安装镜像包复制到/opt/目录下
cp -r /mnt/CentOS-7-x86_64-DVD-1708.iso /opt/ &

2, configure your own source

#进入yum文件路径
[root@node1 ~]# cd /etc/yum.repos.d/
#删除刚才在客户端上创建的私有源
[root@node1 yum.repos.d]# rm -rf GLFS.repo
#将CentOS-文件全部移到到yum.repos.d下
[root@node1 abc]# mv CentOS-* ../
# 重新加载公有源
root@node1 yum.repos.d]# 

3, you must configure KVM environment package

#安装桌面环境
yum groupinstall "GNOME Desktop" -y

#KVM模块
yum install qemu-kvm -y

# 调试工具
yum install qemu-kvm-tools -y

#构建虚拟主机的命令工具
yum install virt-install -y

#qemu组件,创建磁盘,启动虚拟机
yum install qemu-img -y

#网络支持工具
yum install -y bridge-utils

#虚拟机管理工具
 yum install libvirt -y

#图形化管理虚拟机
yum install virt-manager -y

4, to determine whether cpu virtualization. And view the virtual machine module

egrep '(vmx|svm)' /proc/cpuinfo

#查看,模块
lsmod | grep kvm

5, open the service and set the boot from the start

#开启服务
systemctl start libvirtd
#开机自启动
systemctl enable libvirtd

Moving package, the package moves to the next mount / data / directory

#创建挂载点
 mkdir /data/
 #将刚才创建好的条带复制卷挂碍到data目录下
 mount.glusterfs node3:dis-rep /data/
#创建两个文件
mkdir vdisk viso
#复制并调到后台运行
cp -r /mnt/CentOS-7-x86_64-DVD-1708.iso /data/viso &

Configure the bridge virtual machine's NIC

#进入网卡文件
cd /etc/sysconfig/network-scripts/
#复制创建br0网卡
cp -p ifcfg-ens33 ifcfg-br0
#进入ens33网卡,设置桥接命令
vim ifcfg-ens33
#桥接命令
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.45.140
NETMASK=255.255.255.0
GATEWAY=192.168.45.2

#重启网卡
service network restart 
View card information

Here Insert Picture Description

Into the graphical management interface

virt-manager

Here Insert Picture Description
Select store, click Select, enter the storage control interface

Here Insert Picture Description
Select Create a new storage pool, and then enter a name
Here Insert Picture Description
and then select forward and then jump inside page, click Browse. Enter the following interface
Click on the icon to
Here Insert Picture Description
enter vdisk file in the data directory folder selected, click and select Open
Here Insert Picture Description
Click Finish to exit interface to complete the creation of a new storage pool

On the plus dis choose to add new volumes, enter the name click into, and enter the interval size to be allocated on the bottom of the storage volume quota
Here Insert Picture Description

Like the top of the steps to create a storage pool iso
Here Insert Picture Description
here selection / data / z in viso / of / mirror, and then click Open
Here Insert Picture Description
and then click Finish to complete the addition of address pool, check the created storage pool, create after a good, click on the file and exit.
Here Insert Picture Description
Click File, select Create New Web Hosting
Here Insert Picture Description
forward in the selection, then, the choice of system to be installed in the mirror when selecting iso mirrored
Here Insert Picture Description
image selection is complete, click Forward
Here Insert Picture Description
assigned memory size, generally based on the size of their actual memory dispatch
Here Insert Picture Description
the option of creating custom storage, select Centos7 file you just created in the vdisk
Here Insert Picture Description
Here Insert Picture Description
click select, custom configuration prior to installation, and then click Finish
Here Insert Picture Description
to start the virtual machine when the boot options, select the host boot
Here Insert Picture Description
click to start the installation, just behind us CentOS installation steps, like a
Here Insert Picture Description
natural to start the automatic installation, you can view the virtual usage on a virtual machine manager
Here Insert Picture Description

Guess you like

Origin blog.51cto.com/14469918/2461464