1.NFS
描述
NFS,全稱為Network File System,即網絡文件系統,是一種分布式文件系統協議,允許一個系統在網絡上與他人共享目錄和文件。通過NFS,用戶和程序可以像訪問本地文件一樣訪問遠端系統上的文件。以下是NFS的一些主要特點:
- 透明性:對用戶而言,遠程文件的訪問就像訪問本地文件一樣。
- 簡單性和易用性:設置和配置相對簡單,適用于小型網絡。
- 可擴展性:能夠根據需要添加更多的存儲或客戶端。
2.NFS
環境介紹
IP | 主機名 | 操作系統 | 說明 |
---|---|---|---|
192.168.100.7 | nfs-server | Rocky Linux 10.0 | NFS服務器 |
192.168.100.8 | nfs-client | Rocky Linux 10.0 | 測試客戶端 |
3.主機配置
3.1IP配置
配置nfs-server節點IP地址
cat > /etc/NetworkManager/system-connections/ens160.nmconnection <<EOF
[connection]
id=ens160
type=ethernet
autoconnect-priority=-999
interface-name=ens160[ethernet][ipv4]
address1=192.168.100.7/24
dns=114.114.114.114;8.8.8.8;
gateway=192.168.100.254
may-fail=false
method=manual[ipv6]
addr-gen-mode=eui64
method=ignore[proxy]
EOF
配置nfs-client節點IP地址
cat > /etc/NetworkManager/system-connections/ens160.nmconnection <<EOF
[connection]
id=ens160
type=ethernet
autoconnect-priority=-999
interface-name=ens160[ethernet][ipv4]
address1=192.168.100.8/24
dns=114.114.114.114;8.8.8.8;
gateway=192.168.100.254
may-fail=false
method=manual[ipv6]
addr-gen-mode=eui64
method=ignore[proxy]
EOF
3.2修改主機名
nfs-server上執行
hostnamectl set-hostname nfs-server
nfs-client上執行
hostnamectl set-hostname nfs-client
3.3關閉防火墻
2個節點均需要執行
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
3.4關閉SELINUX
2個節點均需要執行
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
3.5DNF
源配置
2個節點均需要執行
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' -i.bak /etc/yum.repos.d/rocky-*.repo
3.6時間同步配置
2個節點均需要執行
dnf install -y chrony
sed -i 's|pool[[:space:]]*2\.rocky\.pool\.ntp\.org[[:space:]]*iburst|server ntp.aliyun.com iburst|' /etc/chrony.conf
systemctl restart chronyd
chronyc sources
4.安裝nfs
服務
nfs-server節點上執行
yum install -y nfs-utils
5.創建共享目錄
nfs-server節點上執行
mkdir -p /nfs/share
設置權限
chown nobody:nobody /nfs/share
chmod 755 /nfs/share
6.修改配置文件
nfs-server節點上執行
cat > /etc/exports <<EOF
/nfs/share 192.168.100.0/24(rw,sync,no_subtree_check)
EOF
/nfs/share
共享的目錄192.168.100.0/24
允許訪問共享目錄的客戶端范圍(rw,sync,no_subtree_check)
表示讀寫權限、同步寫入、不檢查子樹
7.啟用NFS
服務
nfs-server節點上執行
systemctl start nfs-server
systemctl enable nfs-server
systemctl status nfs-server
8.客戶端配置
nfs-client節點上執行
yum install -y nfs-utils
mkdir -p /data/nfs_share
mount -t nfs 192.168.100.7:/nfs/share /data/nfs_share
showmount -e 192.168.100.7
9.驗證
nfs-server節點上執行
touch /nfs/share/test.txt
nfs-client節點上執行
ll /data/nfs_share