Gluster+CTDB+Samba 安裝架設

IP Address

Smartshop-file01 172.16.25.98

Smartshop-file02 172.16.25.111

硬盤配置

GLUSTER_CTDB_SAMBA_20181026-1

GLUSTER_CTDB_SAMBA_20181026-2

VIP: 172.16.25.112

 

安裝前預先設定:

在每一台主機上 /etc/hosts加入所有群集的每一台機器,要先確保所有的服務器都能透過主機名稱存取至每一台主機,也建議將 ssh key 加入 authorized_keys 中

GLUSTER_CTDB_SAMBA_20181026-3

GLUSTER_CTDB_SAMBA_20181026-4

格式化

Smartshop-file1

#mkfs.xfs /dev/lv2/lv_data -f

Smartshop-file2

#mkfs.xfs /dev/lv2/lv_data -f

 

加入 /etc/fstab 讓開機時自動掛載這邊是掛載至 /data/bricks/brick1 , 目錄不存在時請先預先建立.

Smartshop-file1

GLUSTER_CTDB_SAMBA_20181026-5

Smartshop-file2

GLUSTER_CTDB_SAMBA_20181026-6

確認掛載成功

GLUSTER_CTDB_SAMBA_20181026-7

GLUSTER_CTDB_SAMBA_20181026-8

安裝 glusterd

[centos-gluster50]
name=CentOS-$releasever - Gluster 5.0 (Long Term Maintanance)
baseurl=https://buildlogs.centos.org/centos/7/storage/x86_64/gluster-5/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Storage

加入 yum 源

# 安裝 glusterfs 及啟用服務
# for i in 1 2 ;do ssh root@smartshop-file0${i} "yum -y install glusterfs-server";done
# for i in 1 2 ;do ssh root@smartshop-file0${i} "systemctl enable glusterd;systemctl start glusterd;systemctl status glusterd"

# 設置glusterfs peer 查找
@Smartshop-file1
# gluster peer probe smartshop-file02
@Smartshop-file2
# gluster peer probe smartshop-file01

# 建立glusterfs volume (建立 ctdb, share 二個volume)
@Smartshop-file1
# gluster volume create ctdb replica 2 transport tcp smartshop-file01:/data/bricks/brick1/ctdb smartshop-file02:/data/bricks/brick1/ctdb
# gluster volume create share01 replica 2 transport tcp smartshop-file01:/data/bricks/brick1/share01 smartshop-file02:/data/bricks/brick1/share01

@Smartshop-file2
# gluster volume create ctdb replica 2 transport tcp smartshop-file01:/data/bricks/brick1/ctdb smartshop-file02:/data/bricks/brick1/ctdb
# gluster volume create share01 replica 2 transport tcp smartshop-file01:/data/bricks/brick1/share01 smartshop-file02:/data/bricks/brick1/share01

Gluster 建立好後將他掛載至 /glusterfs/smartstore/lock 及 /glusterfs/smartstore/share 上, 這二個目錄就是最終要掛載至 samba 上去使用的目錄,透過 glusterd 處理,當文檔異動複製至這二個目錄下,應會自動同步複寫至另一台服務器上的對應目錄下.

也一起將這二個目錄分別設定掛載至 /etc/fstab 自動掛載.

GLUSTER_CTDB_SAMBA_20181026-9

GLUSTER_CTDB_SAMBA_20181026-10

 

檢查一下目錄掛載情形

GLUSTER_CTDB_SAMBA_20181026-11

GLUSTER_CTDB_SAMBA_20181026-12

架構示意如下圖

GLUSTER_CTDB_SAMBA_20181026-13

Gluster 至此已安裝設定完成.

可透過 gluster volume status 檢查目錄及狀態

GLUSTER_CTDB_SAMBA_20181026-14

安裝設置 CTDB+SAMBA

安裝 ctdb/samba 及啟用服務

# for i in 1 2 ;do ssh root@smartshop-file0${i} "yum install ctdb* samba* cis-util* -y";done
# for i in 1 2 ;do ssh root@smartshop-file0${i} "systemctl disable smb";done
# for i in 1 2 ;do ssh root@smartshop-file0${i} "systemctl disable nmb";done
# for i in 1 2 ;do ssh root@smartshop-file0${i} "systemctl enable ctdb";done

因為 smb/nmb 服務透過 ctdb 管理,所以要將他服務變更為disable 不要讓他自行啟動.

# vi /etc/ctdb/ctdbd.conf
CTDB_RECOVERY_LOCK=/glusterfs/smartstore/lock/lockfile
CTDB_NODES=/etc/ctdb/nodes
CTDB_PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
CTDB_MANAGES_SAMBA=yes
CTDB_MANAGES_WINBIND=no
CTDB_MANAGES_NFS=no
CTDB_DEBUGLEVEL=WARN

在第一台的 ctdbd.conf 中加入下面設定,因為這邊只會用到 samba 所以我只有啟用 samba, 前三個記得都是沒有默認值,所以加上去後再建立 nodes 及 public_addresses 二個檔案.

GLUSTER_CTDB_SAMBA_20181026-15

然後將這三個檔案(ctdbd.conf/public_addresses/nodes)搬移到你的共享目錄(/glusterfs/smartstore/lock/)下然後在集群中的每個節點各自建立符號指到對應目錄下.

@Smartshop-file1
# mv /etc/ctdb/ctdbd.conf /glusterfs/smartstore/lock/
# mv /etc/ctdb/public_addresses /glusterfs/smartstore/lock/
# mv /etc/ctdb/nodes /glusterfs/smartstore/lock/
# ln -fs /glusterfs/smartstore/lock/ctdbd.conf /etc/ctdb/ctdbd.conf
# ln -fs /glusterfs/smartstore/lock/public_addresses /etc/ctdb/public_addresses
# ln -fs /glusterfs/smartstore/lock/nodes /etc/ctdb/nodes

@Smartshop-file2
# ln -fs /glusterfs/smartstore/lock/ctdbd.conf /etc/ctdb/ctdbd.conf
# ln -fs /glusterfs/smartstore/lock/public_addresses /etc/ctdb/public_addresses
# ln -fs /glusterfs/smartstore/lock/nodes /etc/ctdb/nodes

 
然後就可以啟動 ctdb 服務

@Smartshop-file1/@Smartshop-file2 (ctdb status 可檢查服務及目錄狀況)
# systemctl start ctdb
# ctdb status

GLUSTER_CTDB_SAMBA_20181026-16

除錯及檢查可以查看 ctdb 日誌檔 ( /var/log/log.ctdb)

GLUSTER_CTDB_SAMBA_20181026-17

 

設置samba

加入下方全域及共享段加入藍色部份的設定

# cat /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.[global]
       workgroup = SAMBA
       security = user
       passdb backend = tdbsam
       printing = cups
       printcap name = cups
       load printers = yes
       cups options = raw

       clustering = yes
       idmap backend = tdb2
       ea support = yes
…..
… <省略>
…..
 [public]
        comment = CTDB NAS
        path = /glusterfs/smartstore/share
        public = yes
        writable = yes
        write list = @smbadmin
        valid users = jerryw tony
        read only = no
        guest ok = yes

[gluster-ctdb$]
        comment = For samba share of volume ctdb
        path = /glusterfs/smartstore/lock
        read only = no
        guest ok = yes
        public = yes
        writable = yes
        valid users = jerryw tony

然後將這smb.conf檔案搬移到你的共享目錄(/glusterfs/smartstore/lock/)下然後在集群中的每個節點各自建立符號指到對應目錄下.

 

然後就可以重新啟動 ctdb 服務, 及檢查日誌即可.

@Smartshop-file1
# mv /etc/samba/smb.conf /glusterfs/smartstore/lock
# ln -fs /glusterfs/smartstore/lock/smb.conf /etc/samba/smb.conf

@Smartshop-file2
# ln -fs /glusterfs/smartstore/lock/smb.conf /etc/samba/smb.conf
  1. 在二台服務器都必須建立帳號及密碼才能透過samba 存取目錄.

可透過 smbpasswd -a <USER_NAME> 去添加用戶名及密碼, 建立 smb用戶, 帳戶必須在本機上己存在.

 

 

Author: jerryw1974

learning and focus on computer science, cloud infrastructure, virtualization and information security, technical, networking,platform system and cyber-security related topic.