服務端安裝與配置mysql
[root@test-a ~]# yum install -y nfs-utils rpcbind [root@test-a ~]# vim /etc/exports [root@test-a ~]# cat /etc/exports /home/nfstestdir 192.168.77.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) [root@test-a ~]# mkdir /home/nfstestdir [root@test-a ~]# chmod 777 /home/nfstestdir [root@test-a ~]# netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2376/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1714/nginx: master tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1714/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1206/sshd tcp6 0 0 ::1:25 :::* LISTEN 2376/master tcp6 0 0 :::3306 :::* LISTEN 2405/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 1206/sshd [root@test-a ~]# systemctl start nfs # 啓動nfs服務 [root@test-a ~]# ps aux | grep nfs root 9022 0.0 0.0 0 0 ? S< 01:59 0:00 [nfsd4] root 9023 0.0 0.0 0 0 ? S< 01:59 0:00 [nfsd4_callbacks] root 9027 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9028 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9029 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9030 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9031 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9032 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9033 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9034 0.0 0.0 0 0 ? S 01:59 0:00 [nfsd] root 9050 0.0 0.0 112704 972 pts/0 R+ 01:59 0:00 grep --color=auto nfs [root@test-a ~]# systemctl enable nfs # 容許nfs開機啓動
客戶端安裝nginx
[root@centos0 ~]# yum install -y nfs-utils
NFS選項 | 功能描述 |
---|---|
ro | 只讀共享 |
rw | 讀寫 |
sync | 同步模式,內存數據實時寫入磁盤 |
async | 異步模式,即非同步模式 |
no_root_squash | 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大 |
root_squash | 與上面選項相對,客戶端上的root用戶受到約束,被限定成某個普通用戶 |
all_squash | 客戶端上全部用戶在使用NFS共享目錄時都被限定爲一個普通用戶 |
anonuid/anongid | 和上面幾個選項搭配使用,定義被限定用戶的uid和gid |
客戶端sql
[root@centos0 ~]# showmount -e 192.168.77.134 # 看192.168.77.134這臺機器上開啓的nfs服務是否能訪問,提示通訊失敗,同時關閉服務端和客戶端的防火牆和SELinux clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host) [root@centos0 ~]# setenforce 0 [root@centos0 ~]# getenforce Permissive [root@centos0 ~]# systemctl stop firewalld [root@centos0 ~]# showmount -e 192.168.77.134 # 都關閉後再次測試OK showmount -e 192.168.77.134 Export list for 192.168.77.134: /home/nfstestdir 192.168.77.0/24 # 掛載 [root@centos0 ~]# mount -t nfs 192.168.77.134:/home/nfstestdir /mnt/ [root@centos0 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 26G 879M 25G 4% / devtmpfs 489M 0 489M 0% /dev tmpfs 494M 0 494M 0% /dev/shm tmpfs 494M 13M 481M 3% /run tmpfs 494M 0 494M 0% /sys/fs/cgroup /dev/sda1 197M 76M 122M 39% /boot tmpfs 99M 0 99M 0% /run/user/0 192.168.77.134:/home/nfstestdir 26G 9.4G 17G 37% /mnt [root@centos0 ~]# cd /mnt/ # 進入掛載目錄 [root@centos0 mnt]# ls [root@centos0 mnt]# touch test.aaaa
服務端vim
# 關閉防火牆,SELinux [root@test-a ~]# systemctl stop firewalld [root@test-a ~]# setenforce 0 # 在客戶端touch test.aaaa後查看 [root@test-a ~]# ls /home/nfstestdir/ -l total 0 -rw-r--r--. 1 test03 grouptest01 0 Dec 9 02:45 test.aaaa