安装NFS ,LINUX - How To Set Up an NFS Mount on CentOS 6

本文详细介绍如何在Linux系统中安装NFS服务,并通过实例演示如何进行NFS目录的共享及客户端的挂载操作。
安装NFS
yum install nfs-utils nfs-utils-lib

开机启动,开启
chkconfig nfs on 
<pre name="code" class="html">chkconfig rpcbind on 
service rpcbind start
service nfs start

如果:service rpcbind start 报错:rpcbind: unrecognized service
则使用:service portmap start
添加允许那个ip对其进行访问那个目录(有点像xp的共享文件)
vi /etc/exports

/home           12.33.44.555(rw,sync,no_root_squash,no_subtree_check)

These settings accomplish several tasks:

  • rw: This option allows the client server to both read and write within the shared directory
  • sync: Sync confirms requests to the shared directory only once the changes have been committed.
  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  • no_root_squash: This phrase allows root to connect to the designated directory

Once you have entered in the settings for each directory, run the following command to export them:

exportfs -a

在另外一个服务器上安装:
yum install nfs-utils nfs-utils-lib

新建文件夹路径,挂载
mkdir -p /mnt/nfs/home

Then go ahead and mount it
mount 12.34.56.789:/home /mnt/nfs/home

另外需要注意的是:开启自动挂载磁盘:

1:把mount 的命令放到/etc/rc.d/rc.local 里面去,vi /etc/rc.d/rc.local ,然后把mount /dev/emcpowerb1 /oracle/oradata这个命令塞进去。保存退出就好了

 

2:修改/etc/fstab文档

      先vi /etc/fstab,

LABEL=/                 /                           ext3    defaults        1 1
LABEL=/boot        /boot                      ext3    defaults        1 2
tmpfs                    /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                 devpts  gid=5,mode=620  0 0
sysfs                    /sys                        sysfs   defaults        0 0
proc                    /proc                        proc    defaults        0 0
LABEL=SWAP-sda2         swap           swap    defaults        0 0

这个就是fstab的内容了,把要挂载的盘信息加到里面吧:

LABEL=/                 /                           ext3    defaults        1 1
LABEL=/boot        /boot                      ext3    defaults        1 2
tmpfs                    /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                 devpts  gid=5,mode=620  0 0
sysfs                    /sys                        sysfs   defaults        0 0
proc                    /proc                        proc    defaults        0 0
LABEL=SWAP-sda2         swap           swap    defaults        0 0

/dev/emcpowerb1     /oracle/oradata    ext3     defaults       0 0

嗯,保存退出,等重启服务器就可以生效了。吼吼

/etc/fstab里面每列大概意思为:

第1列是需要挂载的文件系统或存储设备;第2列是挂载点;第3列指定文件系统或分区的类型;第4列为挂载选项,详细参考man mount.命令,defaults就没有问题,除非你有特殊需求;第5列为dump选项,设置是否让备份程序dump备份文件系统,0为忽略,1为备份; 第6列为fsck选项,告诉fsck程序以什么顺序检查文件系统,0为忽略;

 

希望一些专业人士能够专业一点,就算真不专业也应该勤奋一点。唉。。。



1:把mount 的命令放到/etc/rc.d/rc.local 里面去,vi /etc/rc.d/rc.local ,然后把mount /dev/emcpowerb1 /oracle/oradata这个命令塞进去。保存退出就好了

 

2:修改/etc/fstab文档

      先vi /etc/fstab,

LABEL=/                 /                           ext3    defaults        1 1
LABEL=/boot        /boot                      ext3    defaults        1 2
tmpfs                    /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                 devpts  gid=5,mode=620  0 0
sysfs                    /sys                        sysfs   defaults        0 0
proc                    /proc                        proc    defaults        0 0
LABEL=SWAP-sda2         swap           swap    defaults        0 0

这个就是fstab的内容了,把要挂载的盘信息加到里面吧:

LABEL=/                 /                           ext3    defaults        1 1
LABEL=/boot        /boot                      ext3    defaults        1 2
tmpfs                    /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                 devpts  gid=5,mode=620  0 0
sysfs                    /sys                        sysfs   defaults        0 0
proc                    /proc                        proc    defaults        0 0
LABEL=SWAP-sda2         swap           swap    defaults        0 0

/dev/emcpowerb1     /oracle/oradata    ext3     defaults       0 0

嗯,保存退出,等重启服务器就可以生效了。吼吼

/etc/fstab里面每列大概意思为:

第1列是需要挂载的文件系统或存储设备;第2列是挂载点;第3列指定文件系统或分区的类型;第4列为挂载选项,详细参考man mount.命令,defaults就没有问题,除非你有特殊需求;第5列为dump选项,设置是否让备份程序dump备份文件系统,0为忽略,1为备份; 第6列为fsck选项,告诉fsck程序以什么顺序检查文件系统,0为忽略;

 

希望一些专业人士能够专业一点,就算真不专业也应该勤奋一点。唉。。。










You can use the df -h command to check that the directory has been mounted. You will see it last on the list.
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda               20G  783M   18G   5% /
12.34.56.789:/home       20G  785M   18G   5% /mnt/nfs/home

Additionally, use the mount command to see the entire list of mounted file systems.
mount

Your list should look something like this:
/dev/sda on / type ext4 (rw,errors=remount-ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
12.34.56.789:/home on /mnt/nfs/home type nfs (rw,noatime,nolock,bg,nfsvers=2,intr,tcp,actimeo=1800,addr=12.34.56.789)

Testing the NFS Mount

Once you have successfully mounted your NFS directory, you can test that it works by creating a file on the Client and checking its availability on the Server.

Create a file in the directory to try it out:

touch /mnt/nfs/home/example

You should then be able to find the files on the Server in the /home.
ls /home

You can ensure that the mount is always active by adding the directory to the fstab file on the client. This will ensure that the mount starts up after the server reboots.
vi /etc/fstab
12.34.56.789:/home  /mnt/nfs/home   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

You can learn more about the fstab options by typing in:

man nfs

After any subsequent server reboots, you can use a single command to mount directories specified in the fstab file:

mount -a

You can check the mounted directories with the two earlier commands:

df -h
mount

Removing the NFS Mount

Should you decide to remove a directory, you can unmount it using the umount command:

cd
sudo umount /directory name

You can see that the mounts were removed by then looking at the filesystem again.

df -h

You should find your selected mounted directory gone.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值