NFS介绍
1.NFS不监听任何端口,rpcbind监听111端口
2.NFS服务需要借助于rpc协议
NFS服务端安装配置
1.服务端安装两个服务:
[[email protected] ~]# yum install -y nfs-utils rpcbind
2.客户端安装一个服务:
[[email protected] ~]# yum install -y nfs-utils
3.服务端编辑配置文件:
[[email protected] ~]# vi /etc/exports
/home/nfstestdir 192.168.127.0/24(rw,all_squash,anonuid=1000,anongid=1000)
4.创建共享的文件目录,并修改权限:
[[email protected] ~]# mkdir /home/nfstestdir
[[email protected] ~]# chmod 777 /home/nfstestdir
5.查看监听端口:
[[email protected] ~]# 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 1/systemd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 903/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1141/master
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 903/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1141/master
tcp6 0 0 :::3306 :::* LISTEN 1105/mysqld
6.启动服务:
[[email protected] ~]# ps aux |grep rpc
root 1433 0.0 0.0 112676 984 pts/0 S+ 15:34 0:00 grep --color=auto rpc
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# ps aux |grep rpc
rpc 1442 0.6 0.1 64956 1040 ? Ss 15:35 0:00 /sbin/rpcbind -w
root 1444 0.0 0.0 112676 984 pts/0 S+ 15:35 0:00 grep --color=auto rpc
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# ps aux |grep nfs
root 1496 0.0 0.0 0 0 ? S< 15:35 0:00 [nfsd4_callbacks]
root 1502 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1503 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1504 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1505 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1506 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1507 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1508 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1509 0.0 0.0 0 0 ? S 15:35 0:00 [nfsd]
root 1513 0.0 0.0 112676 984 pts/0 S+ 15:36 0:00 grep --color=auto nfs
[[email protected] ~]# ps aux |grep rpc
rpc 1442 0.0 0.1 64956 1412 ? Ss 15:35 0:00 /sbin/rpcbind -w
rpcuser 1463 0.0 0.1 42376 1748 ? Ss 15:35 0:00 /usr/sbin/rpc.statd
root 1469 0.0 0.0 0 0 ? S< 15:35 0:00 [rpciod]
root 1475 0.0 0.0 42564 948 ? Ss 15:35 0:00 /usr/sbin/rpc.mountd
root 1486 0.0 0.0 43816 540 ? Ss 15:35 0:00 /usr/sbin/rpc.idmapd
root 1515 0.0 0.0 112676 984 pts/0 R+ 15:37 0:00 grep --color=auto rpc
7.设置开机启动:
[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
NFS挂载选项
1.尝试挂载:
[[email protected] ~]# showmount -e 192.168.188.130
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
失败,原因是防火墙开启,关闭后继续
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# showmount -e 192.168.188.130
Export list for 192.168.188.130:
/home/nfstestdir 192.168.188.0/24
2.进行挂载:
[[email protected] ~]# mount -t nfs 192.168.188.130:/home/nfstestdir /mnt/
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.4G 27G 5% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.8M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 197M 97M 100M 50% /boot
tmpfs 98M 0 98M 0% /run/user/0
192.168.188.130:/home/nfstestdir 28G 7.0G 21G 25% /mnt
3.创建文件进行测试:
客户端创建
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# ls
[[email protected] mnt]# touch weixing.111
ls [[email protected] mnt]# ls -l
总用量 0
-rw-r--r-- 1 weixing01 weixing01 0 3月 26 21:04 weixing.111
检测服务端
[[email protected] ~]# ls -l /home/nfstestdir/
总用量 0
-rw-r--r-- 1 weixing01 weixing01 0 3月 26 21:04 weixing.111
[[email protected] ~]# id weixing01
uid=1000(weixing01) gid=1000(weixing01) 组=1000(weixing01),1002(grp2),1006(user5)
原文地址:http://blog.51cto.com/13517254/2091358
时间: 2024-10-09 06:17:21