CentOs7搭建NFS伺服器

2021-08-25 08:07:29 字數 4088 閱讀 3946

環境

nps 192.168.42.171(服務端)

client 192.168.42.67(客戶端)

一.關閉系統防火牆和selinux

[root@linuxidc ~]#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon

loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

active: active (running) since sat 2017-06-03 09:38:00 cst; 8s ago

docs: man:firewalld(1)

main pid: 24067 (firewalld)

cgroup: /system.slice/firewalld.service

└─24067 /usr/bin/python -es /usr/sbin/firewalld –nofork –nopid

jun 03 09:37:58 linuxidc systemd[1]: starting firewalld - dynamic firewall daemon…

jun 03 09:38:00 linuxidc systemd[1]: started firewalld - dynamic firewall daemon.

[root@linuxidc ~]#systemctl stop firewalld

[root@linuxidc ~]#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon

loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

active: inactive (dead)

docs: man:firewalld(1)

jun 01 11:33:35 localhost systemd[1]: starting firewalld - dynamic firewall daemon…

jun 01 11:33:44 localhost systemd[1]: started firewalld - dynamic firewall daemon.

jun 03 09:11:32 linuxidc systemd[1]: stopping firewalld - dynamic firewall daemon…

jun 03 09:11:34 linuxidc systemd[1]: stopped firewalld - dynamic firewall daemon.

jun 03 09:37:58 linuxidc systemd[1]: starting firewalld - dynamic firewall daemon…

jun 03 09:38:00 linuxidc systemd[1]: started firewalld - dynamic firewall daemon.

jun 03 09:38:34 linuxidc systemd[1]: stopping firewalld - dynamic firewall daemon…

jun 03 09:38:36 linuxidc systemd[1]: stopped firewalld - dynamic firewall daemon.

[root@linuxidc share]#getenforce

enforcing

[root@linuxidc share]#setenforce 0

[root@linuxidc share]#getenforce

permissive

[root@linuxidc share]#vi /etc/sysconfig/selinux

[root@linuxidc share]#cat /etc/sysconfig/selinux

# this file controls the state of selinux on the system.

# selinux= can take one of these three values:

# enforcing - selinux security policy is enforced.

# permissive - selinux prints warnings instead of enforcing.

# disabled - no selinux policy is loaded.

selinux=disabled

# selinuxtype= can take one of three two values:

# targeted - targeted processes are protected,

# minimum - modification of targeted policy. only selected processes are protected.

# mls - multi level security protection.

selinuxtype=targeted

二、yum 安裝

yum -y install nfs-utils rpcbind

nfs 的配置檔案 /etc/expots

預設為空

vi /etc/exports

/opt/test/ 192.168.42.0/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501)

三、使配置生效

exportfs -r

注:配置檔案說明:

/opt/test 為共享目錄

192.168.42.0/24 可以為乙個網段,乙個ip,也可以是網域名稱,網域名稱支援萬用字元 如: *.qq.com

rw:read-write,可讀寫;

ro:read-only,唯讀;

sync:檔案同時寫入硬碟和記憶體;

async:檔案暫存於記憶體,而不是直接寫入記憶體;

no_root_squash:nfs客戶端連線服務端時如果使用的是root的話,那麼對服務端分享的目錄來說,也擁有root許可權。顯然開啟這項是不安全的。

root_squash:nfs客戶端連線服務端時如果使用的是root的話,那麼對服務端分享的目錄來說,擁有匿名使用者許可權,通常他將使用nobody或nfsnobody身份;

all_squash:不論nfs客戶端連線服務端時使用什麼使用者,對服務端分享的目錄來說都是擁有匿名使用者許可權;

anonuid:匿名使用者的uid值,可以在此處自行設定。

anongid:匿名使用者的gid值。

開機自啟

systemctl enable rpcbind.service

systemctl enable nfs-server.service

四、啟動 nfs

systemctl start rpcbind.service

systemctl start nfs.service

五、客戶端掛載:

showmount -e 192.168.42.171 #檢視可掛載

export list for 192.168.42.171:

/opt/test 192.168.42.0/24

客戶端掛載

mount -t nfs 192.168.42.171:/opt/test /mnt

無提示 既為成功

客戶端在掛載的時候遇到的乙個問題如下,可能是網路不太穩定,nfs預設是用udp協議,換成tcp協議即可:

mount -t nfs 192.168.42.171:/opt/test /mnt -o proto=tcp -o nolock

Centos7搭建NFS伺服器

現在有3臺伺服器 s1 主 s2 從 s3 從 需要實現檔案實時同步,我們可以安裝nfs服務端和客戶端來實現!一 安裝 nfs 伺服器所需的軟體包 yum install y nfs utils 二 編輯exports檔案,新增從機 vim etc exports home nfs 192.168....

CentOS7 搭建 NFS 伺服器

環境 停止並禁用防火牆 systemctl stop firewalld systemctl disable firewalld 若當前啟用了 selinux 則需要臨時設定其當前狀態為 permissive setenforce 0 編輯 etc sysconfig selinux 檔案,以徹底禁...

CentOS7搭建NFS服務

nfs是net file system的簡寫,即網路檔案系統.準備兩個nfs伺服器 192.168.1.100 做為服務端 192.168.1.200 做為客戶端 主要步驟和大概意思 在192.168.1.100上安裝nfs服務端,設定乙個檔案目錄alla資料夾用來共享。然後在192.168.1.2...