Xen环境下搭建NFS实现Domain0与DomainU之间共享文件

来源:互联网 发布:csgo fps优化参数 编辑:程序博客网 时间:2024/05/22 08:15
者最近在玩Xen Hypervisor,总是为如何在Host VM与Guest VMs之间共享数据而烦恼,在网上收到可以用NFS(Network File System)解决这个问题,于是开启了探索NFS之路。

网上大部分文件说法不统一,让人难以理解,因此笔者结合前人们的笔记,总结了一个较为清晰、简单的Xen环境下NFS搭建方法。PS:非Xen环境可以参考本篇笔记。

基础知识
NFS (Network File System) allows you to 'share' a directory located on one networked computer with other computers/devices on that network. (NFS是一个网络文件系统,它允许在一个网络上的多台电脑或者其他设备或者OS共享文件。)
NFS主要包含两个部分:
    #1 Server,server用于存放共享目录,比如说下文将会提到的/export/users。The computer where directory located is called the server and computers or devices connecting to that server are called clients. 
    #2 Clients,clients则是将server的共享目录虚拟加载到自己的文件系统上来(通过映射到本地目录的方式,e.g., /sharedFiles),作为他们自己文件目录。(Clients usually 'mount' the shared directory to make it a part of their own directory structure

简单说来,NFS工作模式是这样的:
    #1 建立一个NFS Server,并且在server上建立一个供clients共享的目录,就像是shared memory。所有clients都可以把该目录作为自己的文件目录使用,并且只要给它加上权限(chmod +777 /export/users),则所有clients可以在本地读写这个目录。
    #2. client 将server上的共享目录映射到自己本地目录中
    #3. client mount共享目录

Step 1(Creating the NFS Server):
    #1. 安装NFS所需的包:apt-get install nfs-kernel-server
  #2. 创建共享目录 /export/usersmkdir -p /export/users, 为了保证所有clients能够自由读写该目录,则给他加上777权限chmod +777 /export/user
    #3. 将实际的用户目录mount到共享目录上: mount --bind /home/users /export/users
    #4. 为了保证系统重启两个目录仍是mount在一起的,则需修改文件/etc/fstab,否则么次重启都需要进行步骤#3一次;/etc/fstab文件修改如下:
        在文件末尾加上:/home/users /export/users none bind 0 0
    #5. 为了使得其他在局域网内的client可以访问,则需要对/etc/export文件进行修改,在文件末尾加上:
        /export 192.168.1.0/24(rw,fsid=0,insecure,no_subtree_check,async)
    /export/users 192.168.1.0/24(rw,nohide,insecure,no_subtree_check,async)
    #6.  restart NFS 服务:service nfs-kernel-server restart
    #7.  改NFS server绑定静态IP,这样做的目的是能够保证server的IP固定,client能够通过IP访问到server:
        a. ifconfig 查看server的inet addr,Bcast, mask 
        b. netstat -rn查看gateway

        c. 利用上麦那两步获取的相关数据,修改/etc/network/interface文件:

 d.重启网卡: /etc/init.d/network restart
                 相关链接:http://www.cnblogs.com/vincedotnet/p/4013099.html    

Step 2(Configuring the Client Computers):
    #1. 安装NFS依赖的包:sudo apt-get install portmap nfs-common
    #2. 创建一个目录用于存放共享资源:mkdir /sharedFiles
    #3. 修改/etc/fstab 文件,将server的共享目录/export/users 映射到本地/sharedFiles目录上,这样client就可以通过访问笨的/sharedFiles直接访问server上的共享目录。在/etc/fstab后面添加:
        192.168.1.111:/export/users /sharedFiles nfs rsize=8192,wsize=8192,timeo=14,intr

Step 3 (Mounting the shared category):
    mount -a




相关链接:
https://help.ubuntu.com/community/SettingUpNFSHowTo
http://www.wikihow.com/Share-Files-Between-Linux-Computers-Using-NFS

0 0
原创粉丝点击