存储
NFS
NFS:配置NFS Server
将NFS服务器配置为共享网络上的目录。
这个例子基于以下环境。
[1] 配置 NFS 服务器。
[root@dlp ~]# dnf -y install nfs-utils
[root@dlp ~]# vi /etc/idmapd.conf
# line 5 : uncomment and change to your domain name
Domain = srv.world
[root@dlp ~]# vi /etc/exports
# create new
# for example, set [/home/nfsshare] as NFS share
/home/nfsshare 10.0.0.0/24(rw,no_root_squash)
[root@dlp ~]# mkdir /home/nfsshare
[root@dlp ~]# systemctl enable --now rpcbind nfs-server
[2] 如果 Firewalld 正在运行,请允许 NFS 服务。
[root@dlp ~]# firewall-cmd --add-service=nfs
success
# if use NFSv3, allow follows, too
[root@dlp ~]# firewall-cmd --add-service={nfs3,mountd,rpc-bind}
success
[root@dlp ~]# firewall-cmd --runtime-to-permanent
success
出口的基本选择
选项 | 描述 |
读写 | 允许 NFS 卷上的读取和写入请求。 |
罗 | 仅允许 NFS 卷上的读取请求。 |
同步 | 仅在将更改提交到稳定存储后才回复请求。(默认) |
异步 | 此选项允许 NFS 服务器违反 NFS 协议并在请求所做的任何更改提交到稳定存储之前回复请求。 |
安全的 | 此选项要求请求源自小于 IPPORT_RESERVED (1024) 的 Internet 端口。(默认) |
不安全 | 此选项接受所有端口。 |
延迟 | 如果怀疑另一个相关的写入请求可能正在进行中或可能很快到达,则稍微延迟将写入请求提交到磁盘。(默认) |
no_wdelay | 如果还设置了异步,则此选项无效。如果 NFS 服务器怀疑另一个相关的写入请求可能正在进行中或可能很快到达,它通常会稍微延迟向磁盘提交写入请求。这允许通过一个可以提高性能的操作将多个写入请求提交到磁盘。如果 NFS 服务器主要接收小的无关请求,则此行为实际上会降低性能,因此可以使用 no_wdelay 将其关闭。 |
子树检查 | 此选项启用子树检查。(默认) |
no_subtree_check | 此选项禁用子树检查,这具有轻微的安全隐患,但在某些情况下可以提高可靠性。 |
root_squash | 将请求从 uid/gid 0 映射到匿名 uid/gid。请注意,这不适用于可能同样敏感的任何其他 uid 或 gid,例如用户 bin 或组人员。 |
no_root_squash | 关闭根挤压。此选项主要用于无磁盘客户端。 |
all_squash | 将所有 uid 和 gid 映射到匿名用户。对于 NFS 导出的公共 FTP 目录、新闻假脱机目录等很有用。 |
no_all_squash | 关闭所有挤压。(默认) |
anonuid=UID | 这些选项显式设置匿名帐户的 uid 和 gid。此选项主要用于 PC/NFS 客户端,您可能希望所有请求都来自一个用户。例如,考虑下面示例部分中 /home/joe 的导出条目,它将所有请求映射到 uid 150。 |
anongid=GID | 阅读上文(annuid=UID) |
NFS:配置 NFS 客户端配置
NFS 客户端以在 NFS 客户端上挂载 NFS 共享。
此示例基于如下环境。
+------------------------+ | +------------------------+
| [NFS 服务器] |10.0.0.30 | 10.0.0.51| [NFS 客户端] |
| dlp.srv.world +----------+----------+ node01.srv.world |
| | | |
+----------+ +----------+
[1] 配置 NFS 客户端。
[root@node01 ~]# dnf -y install nfs-utils
[root@node01 ~]# vi /etc/idmapd.conf
# line 5 : uncomment and change to your domain name
Domain = srv.world
[root@node01 ~]# mount -t nfs dlp.srv.world:/home/nfsshare /mnt
[root@node01 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 783M 968K 782M 1% /run
/dev/mapper/fedora_fedora-root xfs 15G 1.6G 14G 11% /
tmpfs tmpfs 2.0G 4.0K 2.0G 1% /tmp
/dev/vda1 xfs 1014M 195M 820M 20% /boot
tmpfs tmpfs 392M 0 392M 0% /run/user/0
dlp.srv.world:/home/nfsshare nfs4 15G 1.6G 14G 11% /mnt
# NFS share is mounted
# if mount with NFSv3, add [-o vers=3] option
[root@node01 ~]# mount -t nfs -o vers=3 dlp.srv.world:/home/nfsshare /mnt
[root@node01 ~]# df -hT /mnt
Filesystem Type Size Used Avail Use% Mounted on
dlp.srv.world:/home/nfsshare nfs 15G 1.5G 14G 10% /mnt
[2] 要在系统启动时自动挂载,请在 [/etc/fstab] 中配置设置。
[root@node01 ~]# vi /etc/fstab
/dev/mapper/fedora_fedora-root / xfs defaults 0 0
UUID=7a32c4aa-4536-4a53-9098-d8fce81050e6 /boot xfs defaults 0 0
# add to the end : set NFS share
dlp.srv.world:/home/nfsshare /mnt nfs defaults 0 0
[3] 要在任何人访问 NFS 共享时动态挂载,请配置 AutoFS。
[root@node01 ~]# dnf -y install autofs
[root@node01 ~]# vi /etc/auto.master
# add to the end
/- /etc/auto.mount
[root@node01 ~]# vi /etc/auto.mount
# create new : [mount point] [option] [location]
/mnt -fstype=nfs,rw dlp.srv.world:/home/nfsshare
[root@node01 ~]# systemctl enable --now autofs
# move to the mount point to verify mounting
[root@node01 ~]# cd /mnt
[root@node01 mnt]# ll
total 4
drwxr-xr-x. 2 root root 6 Nov 9 14:13 testdir
-rw-r--r--. 1 root root 10 Nov 9 14:13 testfile.txt
[root@node01 mnt]# grep /mnt /proc/mounts
/etc/auto.mount /mnt autofs rw,relatime,fd=17,pgrp=24684,timeout=300,minproto=5,maxproto=5,direct,pipe_ino=50098 0 0
dlp.srv.world:/home/nfsshare /mnt nfs4 rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.51,local_lock=none,addr=10.0.0.30 0 0
NFS:NFS 4 ACL 工具
可以在 NFS(v4) 文件系统上设置 ACL 以安装 NFS 4 ACL 工具。
POSIX ACL Tool 的用法基本相同。
[1] 在使用 NFSv4 安装 NFS 共享的 NFS 客户端上安装 NFS 4 ACL 工具。
[root@node01 ~]# dnf -y install nfs4-acl-tools
[2] 在此示例中,它显示了环境中的使用示例,如下所示。
[root@node01 ~]# df -hT /mnt
Filesystem Type Size Used Avail Use% Mounted on
dlp.srv.world:/home/nfsshare nfs4 15G 1.6G 14G 11% /mnt
[root@node01 ~]# ll /mnt
total 4
drwx------. 2 root root 6 Nov 9 17:45 testdir
-rw-------. 1 root root 10 Nov 9 17:44 testfile.txt
[3] 在 NFSv4 文件系统上显示文件或目录的 ACL。
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
[root@node01 ~]# nfs4_getfacl /mnt/testdir
# file: /mnt/testdir
A::OWNER@:rwaDxtTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
# each entry means like follows
# ACE = Access Control Entry
# (ACE Type):(ACE Flags):(ACE Principal):(ACE Permissions)
描述
王牌类型 | |
一种 | A = Allow :表示允许访问。 |
D | D = Deny :表示拒绝访问。 |
王牌标志 | |
d | Directory-Inherit :新的子目录继承相同的 ACE。 |
F | File-Inherit :新文件继承相同的 ACE 但不继承继承标志。 |
n | No-Propogate-Inherit :新的子目录继承相同的 ACE 但不继承继承标志。 |
一世 | Inherit-Only :新文件/子目录继承相同的 ACE,但该目录没有 ACE。 |
王牌校长 | |
(USER)@(NFSD 域) | 普通用户 对于 [NFSDomain],它只是为 [idmapd.conf] 中的 [Domain] 值指定的域名。 |
(GROUP)@(NFSD 域) | 公共组 对于组,像这样指定 [g] 标志 ⇒ A:g:GROUP@NFSDomain:rxtncy |
所有者@ | 特别负责人:业主 |
团体@ | 特别负责人:集团 |
每个人@ | 特约校长:大家 |
ACE 权限 | |
r | 读取文件数据/列出目录中的文件 |
w | 将数据写入文件/在目录中创建新文件 |
一种 | 将数据附加到文件/创建新的子目录 |
X | 执行文件/更改目录 |
d | 删除文件或目录 |
D | 删除目录下的文件或子目录 |
吨 | 读取文件或目录的属性 |
吨 | 将属性写入文件或目录 |
n | 读取文件或目录的命名属性 |
ñ | 写入文件或目录的命名属性 |
C | 读取文件或目录的 ACL |
C | 写入文件或目录的 ACL |
○ | 更改文件或目录的所有权 |
ACE 权限别名 | 对于使用 nfs4_setfacl,可以为 ACE 权限使用别名 |
R | R = rntcy:通用读取 |
W | W = watTNcCy :通用写入 |
X | X = xtcy:通用执行 |
[4] 添加或删除 ACE。
[root@node01 ~]# ll /mnt
total 4
drwx------. 2 root root 6 Nov 9 17:45 testdir
-rw-------. 1 root root 10 Nov 9 17:44 testfile.txt
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
# add generic read/execute for [fedora] user to [/mnt/testfile.txt] file
[root@node01 ~]# nfs4_setfacl -a A::fedora@srv.world:rxtncy /mnt/testfile.txt
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
D::OWNER@:x
A::OWNER@:rwatTcCy
A::1000:rxtcy
A::GROUP@:tcy
A::EVERYONE@:tcy
# verify with [fedora] user
[fedora@node01 ~]$ ll /mnt
total 4
drwx------. 2 root root 6 Nov 9 17:45 testdir
-rw-r-x---. 1 root root 10 Nov 9 17:44 testfile.txt
[fedora@node01 ~]$ cat /mnt/testfile.txt
test file
# delete generic read/execute for [fedora] user from [/mnt/testfile.txt] file
[root@node01 ~]# nfs4_setfacl -x A::1000:rxtcy /mnt/testfile.txt
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
[5] 直接编辑 ACL。
[root@node01 ~]# nfs4_setfacl -e /mnt/testfile.txt
# $EDITOR is run and enter to ACL editing
# default $EDITOR on Fedora 34 is [nano], if $EDITOR=null, default is set to [vi]
## Editing NFSv4 ACL for file: /mnt/testfile.txt
A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
[6] 从文件中添加 ACE。
# create ACL list
[root@node01 ~]# vi acl.txt
A::fedora@srv.world:RX
A::redhat@srv.world:RWX
# add ACL from the file
[root@node01 ~]# nfs4_setfacl -A acl.txt /mnt/testfile.txt
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
D::OWNER@:x
A::OWNER@:rwatTcCy
A::1000:rxtcy
A::1001:rwaxtcy
A::GROUP@:tcy
A::EVERYONE@:tcy
[7] 将当前的 ACE 替换为新的 ACE。
# create ACL list
[root@node01 ~]# vi acl.txt
A::OWNER@:rwaxtTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
# replace ACL from the file
[root@node01 ~]# nfs4_setfacl -S acl.txt /mnt/testfile.txt
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
A::OWNER@:rwaxtTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
[8] 将特定的 ACE 替换为新的 ACE。
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
A::OWNER@:rwaxtTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy
# replace EVERYONE's ACE to read/execute
[root@node01 ~]# nfs4_setfacl -m A::EVERYONE@:tcy A::EVERYONE@:RX /mnt/testfile.txt
[root@node01 ~]# nfs4_getfacl /mnt/testfile.txt
# file: /mnt/testfile.txt
A::OWNER@:rwaxtTcCy
A::GROUP@:rxtcy
A::EVERYONE@:rxtcy
iSCSI
iSCSI:配置目标(Targetcli)
使用 iSCSI 配置存储服务器。
网络上带有 iSCSI 的存储服务器称为 iSCSI Target,连接到 iSCSI Target 的 Client Host 称为 iSCSI Initiator。此示例基于如下环境。
+------------------------+ | +------------------------+
| [iSCSI 目标] |10.0.0.30 | 10.0.0.51| [iSCSI 启动器] |
| dlp.srv.world +----------+----------+ node01.srv.world |
| | | |
+----------+ +----------+
[1] 安装管理工具。
[root@dlp ~]# dnf -y install targetcli
[2] 配置 iSCSI 目标。
例如,在 [/var/lib/iscsi_disks] 目录下创建一个磁盘映像,并将其设置为 SCSI 设备。
# create a directory
[root@dlp ~]# mkdir /var/lib/iscsi_disks
# enter the admin console
[root@dlp ~]# targetcli
targetcli shell version 2.1.54
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> cd backstores/fileio
# create a disk-image with the name [disk01] on [/var/lib/iscsi_disks/disk01.img] with 10G
/backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 10G
Created fileio disk01 with size 10737418240
/backstores/fileio> cd /iscsi
# create a target
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
/iscsi> create iqn.2021-11.world.srv:dlp.target01
Created target iqn.2021-11.world.srv:dlp.target01.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2021-11.world.srv:dlp.target01/tpg1/luns
# set LUN
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk01
Created LUN 0.
/iscsi/iqn.20...t01/tpg1/luns> cd ../acls
# set ACL (it's the IQN of an initiator you permit to connect)
/iscsi/iqn.20...t01/tpg1/acls> create iqn.2021-11.world.srv:node01.initiator01
Created Node ACL for iqn.2021-11.world.srv:node01.initiator01
Created mapped LUN 0.
/iscsi/iqn.20...t01/tpg1/acls> cd iqn.2021-11.world.srv:node01.initiator01
# set UserID and Password for authentication
/iscsi/iqn.20...w.initiator01> set auth userid=username
Parameter userid is now 'username'.
/iscsi/iqn.20...w.initiator01> set auth password=password
Parameter password is now 'password'.
/iscsi/iqn.20...w.initiator01> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
# after configuration above, the target enters in listening like follows
[root@dlp ~]# ss -napt | grep 3260
LISTEN 0 256 0.0.0.0:3260 0.0.0.0:*
[root@dlp ~]# systemctl enable target
[3] 如果 Firewalld 正在运行,请允许 iSCSI Target 服务。
[root@dlp ~]# firewall-cmd --add-service=iscsi-target
success
[root@dlp ~]# firewall-cmd --runtime-to-permanent
success
iSCSI:配置目标 (tgt)
使用 iSCSI 配置存储服务器。
这是使用 scsi-target-utils 配置 iSCSI Target 的示例。(tgt)
网络上带有 iSCSI 的存储服务器称为 iSCSI Target,连接到 iSCSI Target 的 Client Host 称为 iSCSI Initiator。
此示例基于如下环境。
+------------------------+ | +------------------------+
| [iSCSI 目标] |10.0.0.30 | 10.0.0.51| [iSCSI 启动器] |
| dlp.srv.world +----------+----------+ node01.srv.world |
| | | |
+----------+ +----------+
[1] 安装管理工具。
[root@dlp ~]# dnf -y install scsi-target-utils
[2] 配置 iSCSI 目标。
例如,在 [/var/lib/iscsi_disks] 目录下创建一个磁盘映像,并将其设置为 SCSI 设备。
[root@dlp ~]# systemctl enable --now tgtd
# show status
[root@dlp ~]# tgtadm --mode target --op show
Target 1: iqn.2021-11.world.srv:dlp.target01
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 10737 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /var/lib/iscsi_disks/disk01.img
Backing store flags:
Account information:
username
ACL information:
ALL
iqn.2021-11.world.srv:node01.initiator01
# create a disk image
[root@dlp ~]# mkdir /var/lib/iscsi_disks
[root@dlp ~]# dd if=/dev/zero of=/var/lib/iscsi_disks/disk01.img count=0 bs=1 seek=10G
[root@dlp ~]# vi /etc/tgt/conf.d/target01.conf
# create new
# if you set some devices, add <target>-</target> and set the same way with follows
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
<target iqn.2021-11.world.srv:dlp.target01>
# provided device as a iSCSI target
backing-store /var/lib/iscsi_disks/disk01.img
# iSCSI Initiator's IQN you allow to connect
initiator-name iqn.2021-11.world.srv:node01.initiator01
# authentication info ( set anyone you like for "username", "password" )
incominguser username password
</target>
[3] 如果 SELinux 已启用,请更改 SELinux 上下文。
[root@dlp ~]# dnf -y install policycoreutils-python-utils
[root@dlp ~]# chcon -R -t tgtd_var_lib_t /var/lib/iscsi_disks
[root@dlp ~]# semanage fcontext -a -t tgtd_var_lib_t /var/lib/iscsi_disks
[4] 如果 Firewalld 正在运行,请允许 iSCSI Target 服务。
[root@dlp ~]# firewall-cmd --add-service=iscsi-target
success
[root@dlp ~]# firewall-cmd --runtime-to-permanent
success
[5] 启动 tgtd 并验证状态。
[root@dlp ~]# systemctl enable --now tgtd
# show status
[root@dlp ~]# tgtadm --mode target --op show
Target 1: iqn.2021-11.world.srv:dlp.target01
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 10737 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /var/lib/iscsi_disks/disk01.img
Backing store flags:
Account information:
username
ACL information:
ALL
iqn.2021-11.world.srv:node01.initiator01
iSCSI:配置启动器配置
iSCSI 发起程序。
此示例基于如下环境。
+------------------------+ | +------------------------+
| [iSCSI 目标] |10.0.0.30 | 10.0.0.51| [iSCSI 启动器] |
| dlp.srv.world +----------+----------+ node01.srv.world |
| | | |
+----------+ +----------+
[1] 配置 iSCSI Initiator 以连接到 iSCSI Target。
[root@node01 ~]# dnf -y install iscsi-initiator-utils
[root@node01 ~]# vi /etc/iscsi/initiatorname.iscsi
# change to the same IQN you set on the iSCSI target server
InitiatorName=iqn.2021-11.world.srv:node01.initiator01
[root@node01 ~]# vi /etc/iscsi/iscsid.conf
# line 58 : uncomment
node.session.auth.authmethod = CHAP
# line 69,70 : uncomment and specify the username and password you set on the iSCSI target server
node.session.auth.username = username
node.session.auth.password = password
# discover target
[root@node01 ~]# iscsiadm -m discovery -t sendtargets -p 10.0.0.30
10.0.0.30:3260,1 iqn.2021-11.world.srv:dlp.target01
# confirm status after discovery
[root@node01 ~]# iscsiadm -m node -o show
# BEGIN RECORD 2.1.4
node.name = iqn.2021-11.world.srv:dlp.target01
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.iscsi_ifacename = default
.....
.....
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.DataDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD
# login to the target # if logout ⇒ iscsiadm --mode node --logoutall=all
[root@node01 ~]# iscsiadm -m node --login
Logging in to [iface: default, target: iqn.2021-11.world.srv:dlp.target01, portal: 10.0.0.30,3260]
Login to [iface: default, target: iqn.2021-11.world.srv:dlp.target01, portal: 10.0.0.30,3260] successful.
# confirm the established session
[root@node01 ~]# iscsiadm -m session -o show
tcp: [1] 10.0.0.30:3260,1 iqn.2021-11.world.srv:dlp.target01 (non-flash)
# confirm the partitions
[root@node01 ~]# cat /proc/partitions
major minor #blocks name
11 0 1048575 sr0
252 0 31457280 sda
252 1 1048576 sda1
252 2 30407680 sda2
253 0 15728640 dm-0
251 0 4007936 zram0
8 0 10485760 sdb
# added new device provided from the target server as [sdb]
[2] 设置 iSCSI 设备后,在 Initiator 上进行配置以像下面一样使用它。
# create label
[root@node01 ~]# parted --script /dev/sdb "mklabel gpt"
# create partiton
[root@node01 ~]# parted --script /dev/sdb "mkpart primary 0% 100%"
# format with XFS
[root@node01 ~]# mkfs.xfs -i size=1024 -s size=4096 /dev/sdb1
meta-data=/dev/sdb1 isize=1024 agcount=4, agsize=654336 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0
data = bsize=4096 blocks=2617344, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@node01 ~]# mount /dev/sdb1 /mnt
[root@node01 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 786M 1.0M 785M 1% /run
/dev/mapper/fedora_fedora-root xfs 15G 1.6G 14G 11% /
tmpfs tmpfs 2.0G 4.0K 2.0G 1% /tmp
/dev/sda1 xfs 1014M 186M 829M 19% /boot
tmpfs tmpfs 393M 0 393M 0% /run/user/0
/dev/sdb1 xfs 10G 99M 9.9G 1% /mnt
GlusterFS 9
GlusterFS 9:安装
安装 GlusterFS 以配置存储集群。
强烈建议为 GlusterFS 卷使用不同于 / 分区的分区。
在此示例中,它显示了所有节点都具有 [sdb1] 的环境的设置并将其挂载到 [/glusterfs]。
[1] 在集群中的所有节点上安装 GlusterFS 服务器。
[root@node01 ~]# dnf -y install glusterfs-server
[root@node01 ~]# systemctl enable --now glusterd
[root@node01 ~]# gluster --version
glusterfs 9.4
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
[2] 如果 Firewalld 正在运行,请允许所有节点上的 GlusterFS 服务。
[root@node01 ~]# firewall-cmd --add-service=glusterfs
success
[root@node01 ~]# firewall-cmd --runtime-to-permanent
success
GlusterFS 9:分布式配置
使用 GlusterFS 配置存储集群。
例如,创建具有 2 个节点的分布式卷。
此示例显示使用 2 个节点,但也可以使用 3 个以上的节点。
|
+------------------------+ | +------------------------+
| [GlusterFS 服务器#1] |10.0.0.51 | 10.0.0.52| [GlusterFS 服务器#2] |
| node01.srv.world +----------+----------+ node02.srv.world |
| | | |
+----------+ +----------+
⇑ ⇑
文件 1,文件 3 ... 文件 2,文件 4 ...
强烈建议为 GlusterFS 卷使用不同于 / 分区的分区。
在此示例中,它显示了所有节点都具有 [sdb1] 的环境的设置并将其挂载到 [/glusterfs]。
[1] 在所有节点上安装 GlusterFS 服务器。
[2] 在所有节点上为 GlusterFS 卷创建目录。
[root@node01 ~]# mkdir -p /glusterfs/distributed
[3] 在节点上配置集群,如下所示。(在任何节点上都可以)
# probe nodes
[root@node01 ~]# gluster peer probe node02
peer probe: success.
# confirm status
[root@node01 ~]# gluster peer status
Number of Peers: 1
Hostname: node02
Uuid: 447dedcb-fe9b-4743-851c-a7c2adef0043
State: Peer in Cluster (Connected)
# create volume
[root@node01 ~]# gluster volume create vol_distributed transport tcp \
node01:/glusterfs/distributed \
node02:/glusterfs/distributed
volume create: vol_distributed: success: please start the volume to access data
# start volume
[root@node01 ~]# gluster volume start vol_distributed
volume start: vol_distributed: success
# confirm volume info
[root@node01 ~]# gluster volume info
Volume Name: vol_distributed
Type: Distribute
Volume ID: 3a671a01-2a6c-4c4d-858c-4c8e401bc23c
Status: Started
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node01:/glusterfs/distributed
Brick2: node02:/glusterfs/distributed
Options Reconfigured:
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
GlusterFS 9:GlusterFS + NFS-Ganesha
NFS-Ganesha 支持的 NFS 协议有 v3、v4.0、v4.1、pNFS。
Gluster 中的 NFS 功能已正式弃用。
此外,如果 NFS 服务器正在运行,请停止并禁用它。
# OK if [nfs.disable: on] (default setting)
[root@node01 ~]# gluster volume get vol_distributed nfs.disable
Option Value
------ -----
nfs.disable on
# if [nfs.disable: off], turn to disable
[root@node01 ~]# gluster volume set vol_distributed nfs.disable on
volume set: success
# if NFS server is running, disable it
[root@node01 ~]# systemctl disable --now nfs-server
[root@node01 ~]# dnf -y install nfs-ganesha-gluster
[root@node01 ~]# mv /etc/ganesha/ganesha.conf /etc/ganesha/ganesha.conf.org
[root@node01 ~]# vi /etc/ganesha/ganesha.conf
# create new
NFS_CORE_PARAM {
# possible to mount with NFSv3 to NFSv4 Pseudo path
mount_path_pseudo = true;
# NFS protocol
Protocols = 3,4;
}
EXPORT_DEFAULTS {
# default access mode
Access_Type = RW;
}
EXPORT {
# uniq ID
Export_Id = 101;
# mount path of Gluster Volume
Path = "/vol_distributed";
FSAL {
# any name
name = GLUSTER;
# hostname or IP address of this Node
hostname="10.0.0.51";
# Gluster volume name
volume="vol_distributed";
}
# config for root Squash
Squash="No_root_squash";
# NFSv4 Pseudo path
Pseudo="/vfs_distributed";
# allowed security options
SecType = "sys";
}
LOG {
# default log level
Default_Log_Level = WARN;
}
[root@node01 ~]# systemctl enable --now nfs-ganesha
# verify mount
[root@node01 ~]# showmount -e localhost
Export list for localhost:
/vfs_distributed (everyone)
[root@node01 ~]# firewall-cmd --add-service=nfs
success
[root@node01 ~]# firewall-cmd --runtime-to-permanent
success
[root@client ~]# dnf -y install nfs-utils
# specify Pseudo path set on [Pseudo=***] in ganesha.conf
[root@client ~]# mount -t nfs4 node01.srv.world:/vfs_distributed /mnt
[root@client ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 783M 996K 782M 1% /run
/dev/mapper/fedora_fedora-root xfs 15G 1.6G 14G 11% /
tmpfs tmpfs 2.0G 4.0K 2.0G 1% /tmp
/dev/vda1 xfs 1014M 195M 820M 20% /boot
tmpfs tmpfs 392M 0 392M 0% /run/user/0
node01.srv.world:/vfs_distributed nfs4 30G 3.5G 27G 12% /mnt
# verify reading and writing
[root@client ~]# echo "Gluster NFS write test" > /mnt/testfile.txt
[root@client ~]# cat /mnt/testfile.txt
Gluster NFS write test
GlusterFS 9:GlusterFS + SMB
配置 GlusterFS 卷以启用 SMB 协议。
[1] 配置 GlusterFS 以在 GlusterFS 集群中的节点上启用 SMB 设置。
[root@node01 ~]# dnf -y install samba ctdb samba-vfs-glusterfs
# stop the target Gluster volume and change settings
[root@node01 ~]# gluster volume stop vol_distributed
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: vol_distributed: success
[root@node01 ~]# gluster volume set vol_distributed user.smb enable
volume set: success
[root@node01 ~]# gluster volume set vol_distributed performance.write-behind off
volume set: success
[root@node01 ~]# gluster volume set vol_distributed group samba
volume set: success
[root@node01 ~]# vi /var/lib/glusterd/hooks/1/start/post/S29CTDBsetup.sh
# line 25 : change to the target Gluster volume name
META="vol_distributed"
[root@node01 ~]# vi /var/lib/glusterd/hooks/1/stop/pre/S29CTDB-teardown.sh
# line 13 : change to the target Gluster volume name
META="vol_distributed"
# start Gluster volume
[root@node01 ~]# gluster volume start vol_distributed
volume start: vol_distributed: success
# with the settings above, follwing mounting is done automatically
[root@node01 ~]# df -h /gluster/lock
Filesystem Size Used Avail Use% Mounted on
node01.srv.world:/vol_distributed.tcp 30G 3.5G 27G 12% /gluster/lock
[root@node01 ~]# tail -1 /etc/fstab
node01.srv.world:/vol_distributed /gluster/lock glusterfs _netdev,transport=tcp,xlator-option=*client*.ping-timeout=10 0 0
[root@node01 ~]# vi /etc/ctdb/nodes
# create new
# write all Nodes that configure target Gluster volume
10.0.0.51
10.0.0.52
[root@node01 ~]# vi /etc/ctdb/public_addresses
# create new
# set virtual IP address for SMB access
# [enp1s0] means network interface name ⇒ replace to your environment
10.0.0.59/24 enp1s0
[root@node01 ~]# systemctl enable --now ctdb
# confirm status
[root@node01 ~]# ctdb status
Number of nodes:2
pnn:0 10.0.0.51 OK (THIS NODE)
pnn:1 10.0.0.52 DISCONNECTED|UNHEALTHY|INACTIVE
Generation:1113695787
Size:1
hash:0 lmaster:0
Recovery mode:NORMAL (0)
Recovery master:0
[root@node01 ~]# ctdb ip
Public IPs on node 0
10.0.0.59 0
[2] 配置 Samba。
例如,创建一个共享文件夹,[smbgroup] 组中的用户只能访问共享文件夹 [smbshare],并且他们需要用户身份验证。
# mount Gluster volume with GlusterFS Native and create a shared folder for SMB access
[root@node01 ~]# mount -t glusterfs node01.srv.world:/vol_distributed /mnt
[root@node01 ~]# mkdir /mnt/smbshare
[root@node01 ~]# groupadd smbgroup
[root@node01 ~]# chgrp smbgroup /mnt/smbshare
[root@node01 ~]# chmod 770 /mnt/smbshare
[root@node01 ~]# umount /mnt
[root@node01 ~]# vi /etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
# add follows
clustering = yes
kernel share modes = no
kernel oplocks = no
map archive = no
map hidden = no
map read only = no
map system = no
store dos attributes = yes
# follwoing 9 lines are configred automatically
[gluster-vol_distributed]
comment = For samba share of volume vol_distributed
vfs objects = glusterfs
glusterfs:volume = vol_distributed
glusterfs:logfile = /var/log/samba/glusterfs-vol_distributed.%M.log
glusterfs:loglevel = 7
path = /
read only = no
kernel share modes = no
# add follows
writable = yes
valid users = @smbgroup
force create mode = 777
force directory mode = 777
inherit permissions = yes
[root@node01 ~]# systemctl enable --now smb
# add Samba user
[root@node01 ~]# useradd fedora
[root@node01 ~]# smbpasswd -a fedora
New SMB password: # set any SMB password
Retype new SMB password:
Added user fedora.
[root@node01 ~]# usermod -aG smbgroup fedora
[3] 如果启用了 SELinux,请更改策略。
[root@node01 ~]# setsebool -P use_fusefs_home_dirs on
[root@node01 ~]# setsebool -P samba_load_libgfapi on
[root@node01 ~]# setsebool -P domain_kernel_load_modules on
[4] 如果 Firewalld 正在运行,则允许服务。
[root@node01 ~]# firewall-cmd --add-service={samba,ctdb}
success
[root@node01 ~]# firewall-cmd --runtime-to-permanent
success
[5] 验证它可以从任何 Linux 客户端计算机通过 SMB 访问目标共享。
下面的示例是在 Linux 客户端上的,但可以通过普通方式从 Windows 客户端访问。
# verify with [smbclient]
[root@client ~]# smbclient //node01.srv.world/gluster-vol_distributed -U fedora
Enter SAMBA\fedora's password:
Try "help" to get a list of possible commands.
# verify witable to move to shared folder
smb: \> cd smbshare
smb: \smbshare\> mkdir testdir
smb: \smbshare\> ls
. D 0 Tue Nov 9 15:13:16 2021
.. D 0 Tue Nov 9 15:09:06 2021
anaconda-ks.cfg A 872 Tue Nov 9 15:13:17 2021
testdir D 0 Tue Nov 9 15:12:38 2021
31436800 blocks of size 1024. 27701820 blocks available
smb: \smbshare\> exit