Cấu Hình NFS Server Client Trên CentOS 7

Bài đăng lúc: 08:57:33 03/11/2021
Chia sẻ
0 0
Network File System
5/5 - (1 vote)

NFS, hay còn gọi là Network File System, là một server-client protocol, dùng để chia sẻ file giữa hai hệ thống linux/unix và unix/linux với nhau. NFS cho phép người dùng mount một ổ đĩa share sang local hoặc public nếu bạn có server và ip public. Sau đó người dùng hoàn toàn có thể truy cập trực tiếp file từ ổ cứng remote share này.

Chuẩn bị :

Để thực hiện bài lab, chúng ta sử dụng 2 máy chạy CentOS 7. Các bước thực hiện đều tương tự với các distro RHEL và Scientific Linux 7.

Các thông số của 2 máy:

  • NFS Server Hostname: nfs01.thuannguyen.prod
  • NFS Server IP Address: 192.168.1.101/24
  • NFS Client Hostname: client.thuannguyen.prod
  • NFS Client IP Address: 192.168.1.102/24

Cấu hình bên phía server:

Cài packages NFS vào máy bằng lệnh:

yum install nfs-utils nfs-utils-lib

Enable auto start service khi start/reboot server:

systemctl enable rpcbind

systemctl enable nfs-server

systemctl enable nfs-lock

systemctl enable nfs-idmap

Start service:

systemctl start rpcbind

systemctl start nfs-server

systemctl start nfs-lock

systemctl start nfs-idmap

Tiếp theo, tạo share folder trên server.

Tạo một share folder tên ‘/mnt/storage’ trên máy server và cho phép client user có thể đọc và ghi lên thư mục này.

mkdir /mnt/storage

chmod 777 /mnt/storage

Export shared directory trên NFS Server:

Edit file /etc/exports,

vi /etc/exports

Thêm những dòng sau :

/mnt/storage 192.168.1.0/24(rw,sync,no_subtree_check)

Trường hợp bạn muốn mount lên các server hosting (Directadmin, Cpanel):

/mnt/storage 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Thông tin thêm:

/mnt/storage – shared directory

192.168.1.0/24 – IP address range of clients

rw – Writable permission to shared folder

sync – Synchronize shared directory

no_root_squash – Enable root privilege

no_all_squash – Enable user’s authority

Restart lại NFS Service:

systemctl restart nfs-server

Cấu hình bên máy Client:

Cài đặt package NFS :

yum install nfs-utils nfs-utils-lib

Enable NFS services :

systemctl enable rpcbind

systemctl enable nfs-server

systemctl enable nfs-lock

systemctl enable nfs-idmap

Start NFS service:

systemctl start rpcbind

systemctl start nfs-server

systemctl start nfs-lock

systemctl start nfs-idmap

Mount NFS share vào máy client :

Tạo một mount point để mount share folder ‘/mnt/storage’ mà chúng ta đã tạo trước đó trên server.

mkdir /mnt/nfs_share

Tạo share từ server vào client như lệnh dưới (lưu ý trên server mở firewall allow cho ip của client):

mount -t nfs 192.168.1.101:/mnt/storage/ /mnt/nfs_share/

Tự động Mount NFS Share :

Để mount tự động thay vì phải mount tay mỗi lần reboot, add thêm các dòng này vào file ‘/etc/fstab’ trong hệ thống của bạn :

vi /etc/fstab

Thêm vào dưới cùng:

192.168.1.101:/mnt/storage  /mnt/nfs_share/  nfs   defaults,timeo=900,retrans=5,_netdev   0 0

Như vậy là NFS đã được mount thành công.

ThuanNguyen.NET