CentOS8.1 部署GlusterFS使用CTDB和Samba实现高可用
分布式文件系统是一种允许文件通过网络在多台主机上分享的文件系统,可让多台主机上的多用户分享文件和存储空间。单独使用Samba挂载gluster volume无法实现高可用,需要使用CTDB和Samba
每台服务器加1块1G的nvme磁盘,将合并做成4G的分区提供SMB服务
拓扑:
服务器1 fs1 192.168.101.10
服务器2 fs2 192.168.101.11
服务器3 fs3 192.168.101.12
服务器4 fs4 192.168.101.13
客户端Win7 192.168.101.20
GlusterFS几种卷模式说明
1.默认模式,既DHT, 也叫分布卷: 将文件已hash算法随机分布到一台服务器节点中存储 gluster volume create test-volume server1:/exp1 server2:/exp2 2.复制模式,既AFR, 创建volume时带replica X数量,将文件复制到replica X个节点中 gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 3.条带模式,既Striped, 创建volume时带stripe X数量,将文件切割成数据块,分别存储到stripe X个节点中 (类似raid 0) gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2 4.分布式条带模式,最少需要4台服务器才能创建。创建volume时stripe 2 server=4个节点,是DHT与Striped的组合型 gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 5.分布式复制模式, 最少需要4台服务器才能创建。创建volume时replica 2 server=4个节点,是DHT与AFR的组合型 gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 6.条带复制卷模式, 最少需要4台服务器才能创建。创建volume时stripe 2 replica 2 server=4个节点,是Striped与AFR的组合型 gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 7.三种模式混合, 至少需要8台服务器才能创建。创建volume时stripe 2 replica 2 , 每4个节点组成一个组。 gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8
系统设置
nmtui修改完ip后执行nmcli con reload && nmcli networking off && nmcli networking on #节点1 systemctl disable firewalld && systemctl stop firewalld sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config && setenforce 0 hostnamectl --static set-hostname fs1 echo "192.168.101.10 fs1" >> /etc/hosts echo "192.168.101.11 fs2" >> /etc/hosts echo "192.168.101.12 fs3" >> /etc/hosts echo "192.168.101.13 fs4" >> /etc/hosts #节点2 systemctl disable firewalld && systemctl stop firewalld sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config && setenforce 0 hostnamectl --static set-hostname fs2 echo "192.168.101.10 fs1" >> /etc/hosts echo "192.168.101.11 fs2" >> /etc/hosts echo "192.168.101.12 fs3" >> /etc/hosts echo "192.168.101.13 fs4" >> /etc/hosts #节点3 systemctl disable firewalld && systemctl stop firewalld sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config && setenforce 0 hostnamectl --static set-hostname fs3 echo "192.168.101.10 fs1" >> /etc/hosts echo "192.168.101.11 fs2" >> /etc/hosts echo "192.168.101.12 fs3" >> /etc/hosts echo "192.168.101.13 fs4" >> /etc/hosts #节点4 systemctl disable firewalld && systemctl stop firewalld sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config && setenforce 0 hostnamectl --static set-hostname fs4 echo "192.168.101.10 fs1" >> /etc/hosts echo "192.168.101.11 fs2" >> /etc/hosts echo "192.168.101.12 fs3" >> /etc/hosts echo "192.168.101.13 fs4" >> /etc/hosts
挂载新盘
#所有节点 #创建成LVM pvcreate /dev/nvme0n2 vgcreate vg_gluster /dev/nvme0n2 lvcreate -l100%VG -n lv_gluster vg_gluster mkfs.xfs /dev/vg_gluster/lv_gluster
#挂载新目录 mkdir -p /gluster mkdir -p /gluster/brick echo '/dev/vg_gluster/lv_gluster /gluster xfs defaults 0 0' >> /etc/fstab mount -a && mount mount -l | grep gluster
时间同步
#所有节点 dnf -y install chrony systemctl enable --now chronyd timedatectl set-ntp true timedatectl set-timezone Asia/Shanghai
安装GlusterFS
#CentOS8 dnf -y install epel-release wget https://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-rhel8.repo -P /etc/yum.repos.d/ dnf -y install dnf-utils dnf --enablerepo=PowerTools -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma systemctl enable glusterd.service && systemctl start glusterd.service gluster --version #CentOS7 yum search centos-release-gluster yum install -y centos-release-gluster7.noarch yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma gluster --version systemctl start glusterd systemctl enable glusterd
配置GlusterFS
#将节点2、3加入集群 #节点1执行 gluster peer probe fs2 gluster peer probe fs3 gluster peer probe fs4 gluster peer status #若要删除节点gluster peer detach fs2
创建卷
#节点1执行 #新版本中stripe条带卷参数已经废弃 #CentOS8 gluster volume create smb_volume tansport tcp fs1:/gluster/brick fs2:/gluster/brick fs3:/gluster/brick fs4:/gluster/brick gluster volume info #CentOS7 gluster volume create smb_volume fs1:/gluster/brick fs2:/gluster/brick fs3:/gluster/brick fs4:/gluster/brick
激活卷
gluster volume start smb_volume
将卷挂载出来才可使用
#节点1 mkdir -p /storage mount -t glusterfs fs1:/smb_volume /storage #节点2 mkdir -p /storage mount -t glusterfs fs2:/smb_volume /storage #节点3 mkdir -p /storage mount -t glusterfs fs3:/smb_volume /storage 节点4 mkdir -p /storage mount -t glusterfs fs4:/smb_volume /storage
查看glusterfs的pool
gluster volume list gluster pool list
如果需要删除卷
gluster volume stop smb_volume gluster volume delete smb_volume
安装SMB和ctdb
#所有节点 yum install -y ctdb samba samba-common samba-winbind-clients
配置SMB
#节点1 #/storage为后端集群存储系统的挂载点,/storage/public为用户最后通过Samba访问到的目录 systemctl stop smb.service systemctl disable smb.service mkdir -p /storage/ctdb mkdir -p /storage/public chmod 777 /storage/public cp /etc/samba/smb.conf /storage/ctdb/smb.conf vim /storage/ctdb/smb.conf 改为 workgroup = WORKGROUP server string = Samba Server Version %v log file = /var/log/samba/log.%m security = user passdb backend = tdbsam clustering = yes private dir = /storage/ctdb ctdbd socket = /var/run/ctdb/ctdbd.socket [share] comment = GlusterFS and CTDB based share path = /storage/public public = yes guest ok = yes writeable = yes read only = no browsable = yes kernel share modes = no create mask = 0775 执行testparm测试配置
配置ctdb
#所有节点 mkdir /var/lib/ctdb/{persistent,volatile,state} mkdir -p /etc/ctdb/events/legacy #节点1 vim /storage/ctdb/ctdb.conf 添加 CTDB_RECOVERY_LOCK=/storage/ctdb/lockfile CTDB_NODES=/storage/ctdb/nodes CTDB_PUBLIC_ADDRESSES=/storage/ctdb/public_addresses CTDB_MANAGES_SAMBA=yes CTDB_MAX_OPEN_FILES=10000 CTDB_LOGGING=file:/var/log/log.ctdb CTDB_DEBUGLEVEL=ERR CTDB_SET_TDBMutexEnabled=0 #配置集群节点的IP地址 vim /storage/ctdb/nodes 添加 192.168.101.10 192.168.101.11 192.168.101.12 192.168.101.13 #配置提供给客户访问的虚拟地址 vim /storage/ctdb/public_addresses 添加 192.168.101.110/24 ens160 创建链接符号 ln -s /storage/ctdb/ /etc/ctdb/ ln -s /storage/ctdb/public_addresses /etc/ctdb/public_addresses ln -s /storage/ctdb/nodes /etc/ctdb/nodes ln -s /storage/ctdb/smb.conf /etc/samba/smb.conf #设置自启 systemctl enable ctdb --now systemctl start ctdb ctdb status
#tail -f /var/log/log.ctdb #解决ctdb-recoverd[]: Assigned IP not on an interface错误 chmod +x /etc/ctdb/functions #无法调用开启samba vim/etc/ctdb/event.d/50.samba 改为 # Use redhat style as default: CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb} CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
本站所有文章均可随意转载,转载时请保留原文链接及作者。