Centos7搭建NFS伺服器

2021-09-25 11:36:43 字數 2545 閱讀 4251

現在有3臺伺服器 s1(主),s2(從), s3(從)需要實現檔案實時同步,我們可以安裝nfs服務端和客戶端來實現!

一、安裝 nfs 伺服器所需的軟體包:

yum install -y nfs-utils

二、編輯exports檔案,新增從機

vim /etc/exports

/home/nfs/ 192.168.248.0/24(rw,sync,fsid=0)

同192.168.248.0/24乙個網路號的主機可以掛載nfs伺服器上的/home/nfs/目錄到自己的檔案系統中

rw表示可讀寫;sync表示同步寫,fsid=0表示將/data找個目錄包裝成根目錄

三、啟動nfs服務

先為rpcbind和nfs做開機啟動:(必須先啟動rpcbind服務)

systemctl enable rpcbind.service

systemctl enable nfs-server.service

然後分別啟動rpcbind和nfs服務:

systemctl start rpcbind.service

systemctl start nfs-server.service

確認nfs伺服器啟動成功:

rpcinfo -p

檢查 nfs 伺服器是否掛載我們想共享的目錄 /home/nfs/:

exportfs -r

#使配置生效

exportfs

#可以檢視到已經ok

/home/nfs 192.168.248.0/24

四、在從機上安裝nfs 客戶端

首先是安裝nfs,同上,然後啟動rpcbind服務

先為rpcbind做開機啟動:

systemctl enable rpcbind.service

然後啟動rpcbind服務:

systemctl start rpcbind.service

注意:客戶端不需要啟動nfs服務

檢查 nfs 伺服器端是否有目錄共享:showmount -e nfs伺服器的ip

showmount -e 192.168.248.208

export list for 192.168.248.208:

/home/nfs 192.168.248.0/24

在從機上使用 mount 掛載伺服器端的目錄/home/nfs到客戶端某個目錄下:

cd /home && mkdir /nfs

mount -t nfs 192.168.248.208:/home/nfs /home/nfs

df -h 檢視是否掛載成功。

[root@localhost ~]# showmount -e 172.19.162.102

program vers proto port service

1 udp 20048 mountd

1 tcp 20048 mountd

2 udp 20048 mountd

2 tcp 20048 mountd

3 udp 20048 mountd

3 tcp 20048 mountd

3 tcp 2049 nfs

4 tcp 2049 nfs

3 tcp 2049 nfs_acl

3 udp 2049 nfs

4 udp 2049 nfs

3 udp 2049 nfs_acl

1 udp 31206 nlockmgr

3 udp 31206 nlockmgr

4 udp 31206 nlockmgr

1 tcp 31241 nlockmgr

3 tcp 31241 nlockmgr

4 tcp 31241 nlockmgr

iptables -i input -p tcp -s 172.19.162.100 --dport 111 -j accept

iptables -i input -p udp -s 172.19.162.100 --dport 111 -j accept

iptables -i input -p tcp -s 172.19.162.100 --dport 2049 -j accept

iptables -i input -p udp -s 172.19.162.100 --dport 2049 -j accept

iptables -i input -p tcp -s 172.19.162.100 --dport 20048 -j accept

iptables -i input -p udp -s 172.19.162.100 --dport 20048 -j accept

iptables -i input -p tcp -s 172.19.162.100 --dport 31206 -j accept

iptables -i input -p udp -s 172.19.162.100 --dport 31206 -j accept

CentOs7搭建NFS伺服器

環境 nps 192.168.42.171 服務端 client 192.168.42.67 客戶端 一.關閉系統防火牆和selinux root linuxidc systemctl status firewalld firewalld.service firewalld dynamic fire...

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...