This command will install the daemon and tools associated with the kernel NFS server.
sudo fallocate -l 10MB /nfs-share/file1 sudo fallocate -l 10MB /nfs-share/file2 echo "This is a shared text file." | sudo tee /nfs-share/shared-text.txt > /dev/null
Change permissions on the files.
sudo chmod -R 777 /nfs-share
echo "/nfs-share (rw)" | sudo tee -a /etc/exports > /dev/null
sudo firewall-cmd --permanent --zone=public --add-service=nfs sudo firewall-cmd --reload sudo firewall-cmd --list-all
sudo systemctl enable --now nfs-server showmount -e
The showmount command displays the shares available using the NFS server.
sudo exportfs -i -o rw *:/nfs-share2 showmount -e
sudo systemctl restart nfs-server showmount -e
Add the new share to /etc/exports to persist system restarts.
echo "/nfs-share2 *(rw)" | sudo tee -a /etc/exports > /dev/null sudo exportfs -r showmount -e
sudo dnf install -y nfs-utils
This command will install the daemon and tools associated with the kernel NFS server.
sudo mount :/nfs-share /nfs-mount ls -lh /nfs-mount
Where
Enabled by default in Oracle Linux 8, “root squashing” is a share-level configuration option that prevents a remote root user from having root access to the network file system. It is recommended to leave “root squashing” enabled for proper security, but the following steps will show available access when disabled.
sudo chmod 766 /nfs-mount/shared-text.txt
The output shows permission denied even though the command uses sudo .
Disable root_squash on the share using the server instance.
echo "/nfs-share (rw,no_root_squash)" | sudo tee /etc/exports > /dev/null
sudo systemctl restart nfs-server
sudo chmod 766 /nfs-mount/shared-text.txt ls -lh /nfs-mount
The output shows the execute permissions removed from the group and other columns.
To have the mounted share available after a reboot of the client instance, add an entry to the fstab file.
sudo umount /nfs-mount ls -lh /nfs-mount
The ls -lh shows the directory is empty and therefore not mounted.
Update the fstab file.
echo ":/nfs-share /nfs-mount nfs rw 0 0" | sudo tee -a /etc/fstab > /dev/null tail -n5 /etc/fstab
Replace
Mount and verify the share is accessible.
sudo mount -a ls -lh /nfs-mount
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Create an NFS server on Oracle Linux
Copyright © 2021, Oracle and/or its affiliates.
Опубликовано: 28.08.2022
Используемые термины: NFS, Ubuntu. В инструкции мы кратко пробежим по процессу установки и настройки сервера NFS на Ubuntu Server. Также мы рассмотрим пример подключения клиентом к шаре сервера.
Создадим каталог на сервере для нашей шары:
Выполним экспорт данных (перечитаем наш конфигурационный файл /etc/exports, чтобы сервер начал отдавать настроенные шары):
Сервер готов к работе. Состояние службы можно посмотреть командой:
systemctl status nfs-server
Если в нашей системе на сервере используется брандмауэр, нам нужно добавить порты 111 (udp, tcp) и 2049 (udp,tcp):
iptables -I INPUT -p udp —dport 111 -j ACCEPT
iptables -I INPUT -p tcp —dport 111 -j ACCEPT
iptables -I INPUT -p tcp —dport 2049 -j ACCEPT
iptables -I INPUT -p udp —dport 2049 -j ACCEPT
Для сохранения правил используем утилиту netfilter-persistent:
apt install netfilter-persistent
На стороне клиента может понадобиться поставить или обновить клиента NFS. В зависимости от используемого дистририбутива Linux, действия будут немного отличаться:
а) для систем на базе Deb (Ubuntu, Debian, Mint):
б) для систем на базе RPM (Rocky Linux, CentOS):
Клиент будет установлен или обновлен.
Теперь можно попробовать примонтировать нашу шару:
mount -t nfs 192.168.0.15:/data/nfs /mnt
* в нашем примере мы подключимся к серверу с IP-адресом 192.168.0.15; каталог, который мы монтируем /data/nfs (тот, который настроили в файле exports; монтирование будет выполнено в каталог /mnt.
Для того, чтобы монтирование осталось после перезагрузки, открываем файл fstab:
192.168.0.15:/data/nfs /mnt nfs auto 0 0
* где 192.168.0.15 — адрес сервера NFS; /mnt — каталог, куда будет примонтирована шара.
Adblock