NFS หรือ Network File System เป็น Protocol ที่ช้สำหรับการรับส่งไฟล์ระหว่างเครื่อง Client และ Server ซึ่งเครื่อง Client สามารถมองเห็นพื้นที่ใน Server เป็นพื้นที่ของตัวเองได้โดยการตั้งค่า Mount Point
เริ่มติดตั้ง NFS Server บนเครื่อง Server ด้วยคำสั่ง
sudo yum install nfs-utils
ทำการสร้างไดเร็กทอรี่เพื่อเป็นพื้นที่ในการใช้งานร่วมกันและกำหนดสิทธิ์การเข้าถึงด้วยคำสั่ง
sudo mkdir /var/nfsshare
sudo chmod -R 777 /var/nfsshare/
ตั้งค่าให้ NFS ทำงานทุกครั้งเมื่อเปิดเครื่องและสั่งให้ NFS ทำงานด้วยคำสั่ง
sudo systemctl enable rpcbind
sudo systemctl enable nfs-server
sudo systemctl enable nfs-lock
sudo systemctl enable nfs-idmap
sudo systemctl start rpcbind
sudo systemctl start nfs-server
sudo systemctl start nfs-lock
sudo systemctl start nfs-idmap
ตั้งค่าพื้นที่ที่จะใช้งานร่วมกันในกรณีนี้ต้องการใช้งาน /home ด้วย โดยทำการแก้ไขไฟล์ /etc/exports ด้วยคำสั่ง
sudo nano /etc/exports
ทำการเพิ่มเนื้อหาดังนี้
/var/nfsshare [IP_Address](rw,sync,no_root_squash,no_all_squash) /home [IP_Address](rw,sync,no_root_squash,no_all_squash)
โดยเปลี่ยนค่า [IP_Address] เป็น IP Address ของเครื่อง Server ตัวอย่างเช่น
/var/nfsshare 172.21.14.165(rw,sync,no_root_squash,no_all_squash) /home 172.21.14.165(rw,sync,no_root_squash,no_all_squash)
หลังจากตั้งค่าเรียบร้อยแล้วให้ทำการ Restart NFS Service ด้วยคำสั่ง
sudo systemctl restart nfs-server
ตั้งค่า Firewall ด้วยคำสั่ง
sudo firewall-cmd --permanent --zone=public --add-service=nfs
sudo firewall-cmd –reload
เสร็จสิ้นขั้นตอนในส่วนของ Server มาทำในส่วนของ Client กันต่อใน How-To ครั้งนี้ในส่วนของ Client นั้นเป็น CentOS 7 เช่นกัน
ติดตั้ง NFS ด้วยคำสั่ง
sudoyum install nfs-utils
สร้างไดเร็กทอรี่ของ NFS และเพื่อ Mount Point ด้วยคำสั่ง
sudo mkdir -p /mnt/nfs/home
sudo mkdir -p /mnt/nfs/var/nfsshare
ตั้งค่าให้ NFS ทำงานทุกครั้งเมื่อเปิดเครื่องและสั่งให้ NFS ทำงานด้วยคำสั่ง
sudo systemctl enable rpcbind
sudo systemctl enable nfs-server
sudo systemctl enable nfs-lock
sudo systemctl enable nfs-idmap
sudo systemctl start rpcbind
sudo systemctl start nfs-server
sudo systemctl start nfs-lock
sudo systemctl start nfs-idmap
ทำ Mount Point โดยการแก้ไขไฟล์ /etc/fstab ด้วยคำสั่ง
sudo nano /etc/fstab
ทำการเพิ่มเนื้อหาดังนี้
[IP_Address]:/home /mnt/nfs/home nfs defaults 0 0 [IP_Address]:/var/nfsshare /mnt/nfs/var/nfsshare nfs defaults 0 0
โดยเปลี่ยนค่า [IP_Address] เป็น IP Address ของเครื่อง Server ตัวอย่างเช่น
172.21.14.165:/home /mnt/nfs/home nfs defaults 0 0 172.21.14.165:/var/nfsshare /mnt/nfs/var/nfsshare nfs defaults 0 0