Rakesh Jain
Rakesh Jain

@devops_tech

37 ุชุบุฑูŠุฏุฉ 2 ู‚ุฑุงุกุฉ Jul 28, 2023
Twitter
๐Ÿง๐Ÿ“๐Ÿ”— Mastering NFS! ๐Ÿ”—๐Ÿ“๐Ÿง
๐Ÿ”—Installing & Configuring NFS on Ubuntu Server!๐Ÿ”—
๐Ÿ” NFS Troubleshooting Examples! ๐Ÿ”
A Thread explaining everything ๐Ÿ‘‡
What is NFS?
๐Ÿš€ NFS stands for Network File System - a vital protocol for file sharing in Linux/UNIX systems.
๐ŸŒ It lets you access files over a network as if they were on your local machine! ๐Ÿ–ฅ๏ธ
Ready for installing & configuring NFS?
Let's dive in! ๐ŸŠโ€โ™‚๏ธ
1/6 ๐Ÿš€ First, let's install NFS server and utilities:
sudo apt update && sudo apt install nfs-kernel-server nfs-common
๐Ÿ”„ This gets you the required packages to set up and manage NFS! ๐ŸŒŸ #UbuntuServer #NFS #Installation
2/6 โš™๏ธ Next, configure NFS server:
Edit /etc/exports file:
sudo nano /etc/exports
๐Ÿ“ Add a line to share /example_dir with client_ip:
/example_dir client_ip(rw,sync,no_subtree_check)
๐Ÿ”ง Save & exit! ๐Ÿ—’๏ธ #NFS #LinuxConfig #FileSharing
3/6 ๐Ÿ”’ Secure NFS with firewall:
Allow NFS traffic:
sudo ufw allow nfs
๐Ÿ›ก๏ธ If using NFSv4, also allow:
sudo ufw allow nfs4
๐Ÿ”ฅ Reload firewall:
sudo ufw reload
๐Ÿ”ซ Now, NFS ports are accessible! ๐Ÿ”“ #UbuntuServer #NFS #Security
4/6 ๐ŸŒ Start NFS server & related services:
sudo systemctl start nfs-server ๐Ÿš€
sudo systemctl enable nfs-server ๐ŸŒŸ
Check status:
sudo systemctl status nfs-server
๐Ÿ”„ It should be active & running! ๐Ÿ’ป
#NFS #LinuxCommands #Ubuntu
5/6 ๐Ÿ”„ Export shared directory:
Apply the changes:
sudo exportfs -ra
๐Ÿ”„ This exports directories listed in /etc/exports ๐Ÿ“‚
Make sure your clients have proper permissions to access! ๐Ÿ”‘ #NFS #LinuxConfig #FileSharing
6/6 ๐ŸŽ‰ NFS installation & configuration done! ๐ŸŽ‰ Now you can mount the shared directories on client machines ๐Ÿš€ Remember to update /etc/fstab for automounting during boot! ๐ŸŒ„ #UbuntuServer #NFS #LinuxTips
Ready for NFS examples? Let's explore some! ๐ŸŠโ€โ™‚๏ธ
๐Ÿ“‚ Example 1: Mount Remote Directory ๐Ÿ”๏ธ
You can mount a remote directory from a server to your local machine using NFS.
sudo mount -t nfs server_ip:/remote_dir /local_dir ๐Ÿ“ฅ
Now, /local_dir is linked to the remote directory! ๐ŸŒŸ #NFS #Linux #FileSharing
๐Ÿ“„ Example 2: List Remote Directory ๐Ÿ“œ
With NFS, you can list files in a remote directory! ๐Ÿ“‘ Just use:
ls /local_dir ๐Ÿ“‚
It will show the files from the remote server's directory! ๐ŸŒ #NFS #FileSharing #LinuxTricks
๐Ÿ“ Example 3: Read/Write Operations ๐Ÿ“
NFS allows you to read/write files on a remote server! โœ๏ธ For instance:
Read:
cat /local_dir/file.txt ๐Ÿ“–
Write:
echo "Hello, NFS!" > /local_dir/file.txt ๐Ÿ“
Changes are synced with the remote server! ๐Ÿ’พ #NFS #Linux #FileAccess
โš™๏ธ Example 4: Check NFS Status โš™๏ธ
Want to see the NFS status? Use:
showmount -e server_ip ๐Ÿ•ต๏ธโ€โ™‚๏ธ
It will display the shared directories from the specified server! ๐Ÿ—‚๏ธ #NFS #LinuxCommands #FileSharing
๐Ÿ”„ Example 5: Automounting ๐Ÿ”„
You can automount NFS shares during boot! ๐Ÿš€
Add an entry in /etc/fstab:
server_ip:/remote_dir /local_dir nfs defaults 0 0
๐Ÿ”ง Now, the remote share will be available on boot! ๐ŸŒŸ #NFS #LinuxTricks #Automation
๐Ÿ“ Example 6: Export Directory ๐Ÿ“
To share your local directory with remote clients:
Add in /etc/exports:
/local_dir client_ip(rw,sync)
๐Ÿค Now, client_ip can mount and read/write to your shared directory! ๐Ÿค #NFS #FileSharing #Linux
๐Ÿ”’ Example 7: Restrict Access ๐Ÿ”’
Secure your NFS shares by allowing specific IPs:
/local_dir client_ip(rw) client2_ip(ro) ๐Ÿ”
Here, client_ip has read/write, while client2_ip has only read access! ๐Ÿ›ก๏ธ #NFS #LinuxSecurity
๐Ÿ“‚ Example 8: NFSv4 ACLs ๐Ÿ“‚
NFSv4 supports Access Control Lists (ACLs).
๐Ÿšฆ Set ACL for a file:
setfacl -m u:user:permissions /local_dir/file.txt
๐Ÿ” It grants specific user permissions on the file! ๐Ÿ•ต๏ธโ€โ™€๏ธ #NFS #Linux #ACLs
๐Ÿ’ผ Example 9: User Mapping ๐Ÿ’ผ
NFS maps local users to remote users using "usermap" file.
๐Ÿ—บ๏ธ Configure in /etc/idmapd.conf:
echo "localuser remoteuser" >> /etc/idmapd.conf
๐Ÿ”„ Now, localuser is recognized as remoteuser on NFS share! ๐Ÿ—‚๏ธ #NFS #LinuxTricks
๐Ÿš€ Example 10: NFS Performance ๐Ÿš€
Boost NFS performance by tuning parameters!
For example, increase the read buffer size:
sudo sysctl -w sunrpc.tcp_slot_table_entries=128
๐Ÿ”ง Test the settings and adjust for your system! โš™๏ธ #NFS #LinuxPerformance
๐ŸŒ Example 11: Cross-Mounting ๐ŸŒ
NFS allows cross-mounting, where server1 shares dir1 and server2 shares dir2. ๐Ÿค
server1: /dir1 client2_ip(rw)
server2: /dir2 client1_ip(rw)
Now, client1_ip can access dir1 from server1 and vice versa! ๐Ÿ”„ #NFS #Linux #FileSharing
๐Ÿ“ˆ Example 12: Monitoring NFS ๐Ÿ“ˆ
Monitor NFS performance using tools like nfsstat and nfsiostat. ๐Ÿ“Š
nfsstat -s ๐Ÿ“‰
nfsiostat ๐Ÿ“ˆ
Keep an eye on usage and diagnose any issues! ๐Ÿšจ #NFS #LinuxMonitoring
๐Ÿ—‘๏ธ Example 13: NFS Cleanup ๐Ÿ—‘๏ธ
To unmount a NFS share:
sudo umount /local_dir
๐Ÿšซ And to stop sharing a directory:
Remove entry from /etc/exports
๐Ÿ” Keep your system tidy! ๐Ÿงน #NFS #LinuxTricks
๐ŸŽ‰ Example 14: Backup with NFS ๐ŸŽ‰
Use NFS for remote backups!
๐Ÿ—„๏ธ Mount the backup directory and copy files:
sudo mount -t nfs backup_server:/backup_dir /mnt cp -r /local_dir /mnt
๐Ÿ”„ Safe backups off-site! ๐Ÿ’พ
#NFS #LinuxBackup #DataSafety
Hope these NFS examples helped you master the Network File System! ๐ŸŒŸ
Happy file sharing across the network! ๐Ÿค๐Ÿš€ #NFS #LinuxTips #FileSharing
๐Ÿง๐Ÿ” NFS Troubleshooting Examples! ๐Ÿ”๐Ÿง
1/ ๐Ÿ”„ Issue: NFS Mount Fails ๐Ÿšซ
If NFS mount fails on the client, check server's export list:
showmount -e server_ip
๐Ÿ•ต๏ธโ€โ™‚๏ธ Ensure the shared directory is listed and accessible by the client IP! ๐Ÿ“‚ #NFSTroubleshooting #Linux
2/ ๐Ÿšง Issue: Stale File Handle ๐Ÿšง
Encountering "Stale file handle" error? ๐Ÿ˜“
Try remounting the NFS share with:
sudo umount /local_dir sudo mount -a
๐Ÿ”„ This should resolve the stale file handle issue! ๐Ÿ’ก #NFS #LinuxErrors
3/ โš™๏ธ Issue: Incorrect NFS Version โš™๏ธ
If you face compatibility issues, specify NFS version during mount:
sudo mount -t nfs -o vers=3 server_ip:/remote_dir /local_dir
๐Ÿ› ๏ธ Adjust the version as needed! ๐Ÿ”„ #NFSTroubleshooting #LinuxTips
4/ ๐Ÿšฆ Issue: NFS Slow Performance ๐Ÿšฆ
Experiencing slow NFS? Check network connectivity & latency.
๐Ÿ“‰ Also, try mounting with different options:
sudo mount -o rsize=8192,wsize=8192 server_ip:/remote_dir /local_dir
๐Ÿš€ Tune to enhance performance! โš™๏ธ #NFS #LinuxPerformance
5/ ๐Ÿšจ Issue: NFS Firewall Blocking ๐Ÿšจ
If NFS clients can't connect, verify firewall settings: Allow NFS traffic:
sudo ufw allow nfs
๐Ÿ›ก๏ธ Reload:
sudo ufw reload
๐Ÿ”ฅ Ensure NFS ports are open & accessible! ๐Ÿ”“ #NFSTroubleshooting #LinuxSecurity
6/ ๐Ÿ“‚ Issue: Incorrect Mount Options ๐Ÿ“‚
If you encounter permission errors, check mount options.
๐Ÿšซ Ensure you have the correct options,
e.g. for read-write access:
sudo mount -o rw server_ip:/remote_dir /local_dir
๐Ÿ”„ Verify & adjust options as needed! โš™๏ธ#LinuxErrors
7/ ๐Ÿ”„ Issue: NFS Share Not Updating ๐Ÿ”„
If changes made on the server aren't reflecting on clients, try:
sudo exportfs -rav
๐Ÿ”„ This refreshes NFS exports and updates clients with the latest changes! ๐Ÿš€ #NFSTroubleshooting #LinuxTips
8/ ๐Ÿšจ Issue: NFS Service Not Starting ๐Ÿšจ
If NFS server fails to start, check the service status: sudo systemctl status nfs-server
๐Ÿ’ป Review logs in /var/log/syslog for clues on why it's not starting! ๐Ÿ“œ #NFS #LinuxErrors
9/ ๐Ÿ“ฆ Issue: Insufficient Disk Space ๐Ÿ“ฆ
Running out of disk space on NFS server? Clean up unused files or expand storage!
๐Ÿ—‘๏ธ๐Ÿ’พ Ensure clients have enough space too, to prevent write failures! ๐Ÿ’ก #NFS #DiskSpace #Linux
10/ ๐Ÿ”’ Issue: NFS Access Denied ๐Ÿ”’
Facing "Permission denied" error? Check server's export options:
cat /etc/exports
๐Ÿ•ต๏ธโ€โ™‚๏ธ Ensure client IP is allowed with proper permissions!
๐Ÿ”‘ Then, remount on the client to apply changes. ๐Ÿ”„ #NFS #LinuxSecurity
Troubleshooting NFS can be a puzzle, but these examples should help you tackle more challenges! ๐Ÿ› ๏ธ๐ŸŒŸ #Linux #NFS #Troubleshooting
Retweet this mega thread on NFS if you find it useful. Thanks!

ุฌุงุฑูŠ ุชุญู…ูŠู„ ุงู„ุงู‚ุชุฑุงุญุงุช...