14.1 NFS介紹
14.2 NFS服務端安裝配置
14.3 NFS配置選項mysql
NFS是Network File System的縮寫;這個文件系統是基於網路層面,經過網絡層面實現數據同步sql
NFS最先由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,目前最新爲4.1版本——>4.1版本是2010年出來還沒更新過vim
NFS數據傳輸基於RPC協議,RPC爲Remote Procedure Call的簡寫,意思爲 遠程過程調用centos
NFS應用場景是:A,B,C三臺機器上須要保證被訪問到的文件是同樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致緩存
NFS架構服務器
/home/nfstestdir 192.168.180.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
[root@yong-01 ~]# yum install -y nfs-utils rpcbind
[root@yong-02 ~]# yum install -y nfs-utils
[root@yong-01 ~]# vim /etc/exports /home/nfstestdir 192.168.180.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
[root@yong-01 ~]# mkdir /home/nfstestdir [root@yong-01 ~]# chmod 777 /home/nfstestdir/
[root@yong-01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3428/rpcbind tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1110/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1467/master tcp6 0 0 :::111 :::* LISTEN 3428/rpcbind tcp6 0 0 :::22 :::* LISTEN 1110/sshd tcp6 0 0 ::1:25 :::* LISTEN 1467/master tcp6 0 0 :::3306 :::* LISTEN 1423/mysqld [root@yong-01 ~]# ps aux |grep rpc rpc 3428 0.0 0.0 64956 1044 ? Ss 22:42 0:00 /sbin/rpcbind -w root 3431 0.0 0.0 112676 980 pts/0 R+ 22:43 0:00 grep --color=auto rpc
[root@yong-02 mysql]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2755/rpcbind tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 996/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1215/master tcp6 0 0 :::111 :::* LISTEN 2755/rpcbind tcp6 0 0 :::22 :::* LISTEN 996/sshd tcp6 0 0 ::1:25 :::* LISTEN 1215/master tcp6 0 0 :::3306 :::* LISTEN 2360/mysqld [root@yong-02 mysql]# ps aux |grep rpc rpc 2755 0.0 0.0 64956 1044 ? Ss 22:42 0:00 /sbin/rpcbind -w root 2789 0.0 0.0 112676 980 pts/0 R+ 22:45 0:00 grep --color=auto rpc
[root@yong-01 ~]# systemctl start nfs [root@yong-01 ~]# ps aux |grep nfs root 3479 0.0 0.0 0 0 ? S< 22:46 0:00 [nfsd4_callbacks] root 3485 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3486 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3487 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3488 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3489 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3490 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3491 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3492 0.0 0.0 0 0 ? S 22:46 0:00 [nfsd] root 3496 0.0 0.0 112676 976 pts/0 R+ 22:46 0:00 grep --color=auto nfs
[root@yong-01 ~]# ps aux |grep rpc rpc 3428 0.0 0.0 64956 1424 ? Ss 22:42 0:00 /sbin/rpcbind -w rpcuser 3449 0.0 0.0 42376 1756 ? Ss 22:46 0:00 /usr/sbin/rpc.statd root 3451 0.0 0.0 0 0 ? S< 22:46 0:00 [rpciod] root 3468 0.0 0.0 42564 948 ? Ss 22:46 0:00 /usr/sbin/rpc.mountd root 3469 0.0 0.0 43816 544 ? Ss 22:46 0:00 /usr/sbin/rpc.idmapd root 3499 0.0 0.0 112676 980 pts/0 R+ 22:47 0:00 grep --color=auto rpc
[root@yong-01 ~]# systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@yong-02 mysql]# showmount -e 192.168.180.134 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
[root@yong-02 ~]# showmount -e 192.168.180.134 Export list for 192.168.180.134: /home/nfstestdir 192.168.180.0/24
[root@yong-02 ~]# mount -t nfs 192.168.180.134:/home/nfstestdir /mnt/ [root@yong-02 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/mapper/centos-root 18G 5.6G 13G 32% / devtmpfs 905M 0 905M 0% /dev tmpfs 916M 0 916M 0% /dev/shm tmpfs 916M 8.6M 908M 1% /run tmpfs 916M 0 916M 0% /sys/fs/cgroup /dev/sda1 197M 121M 77M 62% /boot tmpfs 184M 0 184M 0% /run/user/0 192.168.180.134:/home/nfstestdir 18G 8.1G 9.8G 46% /mnt
[root@yong-02 ~]# cd /mnt/ [root@yong-02 mnt]# ls [root@yong-02 mnt]# touch yueyong.txt [root@yong-02 mnt]# ll 總用量 0 -rw-r--r-- 1 user1 user1 0 6月 21 23:15 yueyong.txt [root@yong-02 mnt]# id user1 uid=1000(user1) gid=1000(user1) 組=1000(user1)
[root@yong-01 ~]# ll /home/nfstestdir/ 總用量 0 -rw-r--r-- 1 yyl yyl 0 6月 21 23:15 yueyong.txt [root@yong-01 ~]# id yyl uid=1000(yyl) gid=1000(yyl) 組=1000(yyl)