Linux服务器配置NFS

服务器配置NFS
服务器配置:
1.安装两个包(nfs-utils和rpcbind)
先挂载,后配置本地yum源,再安装两个包
[root@ns1 ~]# mount /dev/sr0 /mnt/
[root@ns1 ~]# cd /etc/yum.repos.d/
[root@ns1 yum.repos.d]# ls
CentOS-Base.repo.cat   CentOS-fasttrack.repo  CentOS-Vault.repo
CentOS-Debuginfo.repo  CentOS-Media.repo
[root@ns1 yum.repos.d]# vim CentOS-Media.repo 
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@ns1 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.cat
[root@ns1 Packages]# yum -y install nfs-utils
已加载插件:fastestmirror, security
设置安装进程
Determining fastest mirrors
* c6-media: 
包 1:nfs-utils-1.2.3-75.el6.x86_64 已安装并且是最新版本
无须任何处理
2.编辑配置文件/etc/exports
首先创建目录nfstestdir
[root@ns1 ~]# mkdir /home/nfstestdir
修改配置文件
[root@ns1 ~]# vim /etc/exports 
/home/nfstestdir 172.16.1.19(rw,sync,all_squash,anonuid=1000,anongid=1000)
创建rpcbind服务
[root@nl3 ~]# systemctl start rpcbind
创建NFS服务
[root@nl3 ~]# systemctl start nfs
启动rpcbind服务
[root@nl3 ~]# systemctl enable rpcbind
启动NFS服务
[root@nl3 ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
客户端配置:
4.查看服务器共享的文件
[root@ns1 ~]# showmount -e 172.16.1.20
Export list for 172.16.1.20:
/home/nfstestdir 172.16.1.19
5.挂载NFS
[root@ns2 ~]# mount -t nfs 172.16.1.20:/home/nfstestdir /mnt/
[root@ns2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  2.1G   15G  13% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             488M   33M  430M   8% /boot
172.16.1.20:/home/nfstestdir
  18G  1.2G   16G   8% /mnt
6.再服务器上修改/home/nfstestdir目录的权限
[root@nl3 ~]# chmod 777 /home/nfstestdir/
7.创建文件
[root@ns2 ~]# cd /mnt/
[root@ns2 mnt]# touch aminglinux.txt
[root@ns2 mnt]# ls -l
总用量 0
-rw-r--r-- 1 1000 1000 0 4月  24 18:18 aminglinux.txt

5.服务器:修改配置文件
[root@nl3 ~]# vim /etc/exports
/home/nfstestdir 172.16.1.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
/tmp/ 172.16.1.0/24(rw,sync,no_root_squash)
备注:因为服务器设置的为no_root_squash所以不会限制root用户,root用户创建文件时和客户端本机上创建一样。
查看:
[root@nl3 ~]# exportfs -arv
exporting 172.16.1.0/24:/tmp
exporting 172.16.1.0/24:/home/nfstestdir
6.客户端:挂载
方式1:
[root@ns2 ~]# mkdir /aminglinux
[root@ns2 ~]# mount -t nfs -o nolock 172.16.1.20:/tmp /aminglinux
[root@ns2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  2.1G   15G  13% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             488M   33M  430M   8% /boot
172.16.1.20:/home/nfstestdir
  18G  1.2G   16G   8% /mnt
172.16.1.20:/tmp       18G  1.2G   16G   8% /aminglinux
方式2:以后开机会自动挂载
在/etc/fstab文件里增加一行
[root@ns2 ~]# vim /etc/fstab 
172.16.1.20:/tmp        /aminglinux              nfs     defaults,nolock 0 0
刚才挂载过,先卸载
[root@ns2 ~]# umount /aminglinux/
重新挂载
[root@ns2 ~]# mount -a
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值