有什么方法可以从Bluemix运行时访问NFS? [英] Any way to access a NFS from Bluemix runtime?

查看:75
本文介绍了有什么方法可以从Bluemix运行时访问NFS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将应用程序推送到需要通过NFS访问远程文件系统的Bluemix.

I need to push an application to Bluemix that requires access to a remote file system via NFS.

我还没有找到任何NFS服务.现有的对象存储服务使用Swift API,并且该应用程序需要本机文件系统访问权限,而不是其他类型的API.

I haven't found any NFS service. Existing Object Store services use Swift API and the application requires native file system access, not other kind of APIs.

我尝试从应用程序初始化中执行"mkdir"和"mount"命令,但是运行运行时的用户似乎对此类执行有限制.我得到了表示错误的返回码.

I tried to execute "mkdir" and "mount" commands from app initialization but it seems there are restrictions for such executions from the user that runs the runtime. I got return codes that mean errors.

所以我用尽了所有想法.您有什么建议或想法要探索吗? 我认为Dockers可能是一个选择(如果我可以挂载nfs文件系统,还没有探索过),但是目前它处于Beta版,因此尚无生产准备.

So I run out of ideas. Do you have any suggestion or idea to explore? I think Dockers could be an option (haven't explored yet if I can mount the nfs file system) but currently it is in Beta, so no production ready.

谢谢!

推荐答案

不支持NFS,但是Cloud Foundry现在支持FUSE,这是NFS的非常接近的替代方案.

NFS is not supported, however Cloud Foundry now supports FUSE, which is a pretty close alternative to NFS.

要利用FUSE,您需要使用cflinuxfs2堆栈.

To take advantage of FUSE you need to use the cflinuxfs2 stack.

cflinuxfs2是支持FUSE的新堆栈,请参见下文. Cloud Foundry最近添加了FUSE支持,请参阅此处以获取更多信息.

cflinuxfs2 is a new stack that supports FUSE, see below. Cloud Foundry recently added FUSE support, see here for more info.

name         description   
lucid64      Ubuntu 10.04   
cflinuxfs2   Ubuntu 14.04.2 trusty 

当您推送应用程序时,您需要使用-s选项,例如下面的示例.

When you push your app you need to use the -s option, example below.

cf push myappname -s cflinuxfs2.

更新:

张贴者针对他关于如何执行此操作的另一个问题发布了解决方案.我已将其粘贴在下面...

The poster posted a solution to his another question on how to do this. I have pasted it below...

好的,最后我在团队同事的帮助下找到了问题的原因.问题出在私钥ssh密钥的权限上.它必须为600,默认情况下,在cf推送后为644.

Ok, finally I found the reason of the issue with the help of team colleagues. Problem was with permissions of the private ssh key. It has to be 600 and by default it was 644 after the cf push.

所以这是最后的代码(快速又脏)起作用了,以防万一它对其他人有用...

So here it is the final code (quick and dirty) that worked, just in case it can be useful to others...

1.-在应用程序中包含私钥和known_hosts文件.

1.- Include into the app the private key and the known_hosts files.

2.-推动应用程序添加"-s cflinuxfs2"参数.

2.- Push the app adding "-s cflinuxfs2" parameter.

3.-在运行时启动时执行以下代码:

3.- Execute at runtime startup some code like this:

String s = null;
Process p = null;
BufferedReader br = null;
try 
{
    p = Runtime.getRuntime().exec("mkdir -p /home/vcap/misc");
    br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((s = br.readLine()) != null)
        System.out.println("line: " + s);
    p.waitFor();
    System.out.println ("#### Executing command mkdir with exit: " + p.exitValue());
    p.destroy();
    br.close();

    p = Runtime.getRuntime().exec("chmod 600 /home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key");
    br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((s = br.readLine()) != null)
        System.out.println("line: " + s);
    p.waitFor();
    System.out.println ("#### Executing command chmod with exit: " + p.exitValue());
    p.destroy();
    br.close();

    p = Runtime.getRuntime().exec("chmod 600 /home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts");
    br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((s = br.readLine()) != null)
        System.out.println("line: " + s);
    p.waitFor();
    System.out.println ("#### Executing command chmod with exit: " + p.exitValue());
    p.destroy();
    br.close();

    p = Runtime.getRuntime().exec("sshfs ibmcloud@129.41.133.34:/home/ibmcloud /home/vcap/misc -o IdentityFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts -o idmap=user -o compression=no -o sshfs_debug");
    br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((s = br.readLine()) != null)
        System.out.println("line: " + s);
    p.waitFor();
    System.out.println ("#### Executing command sshfs with exit: " + p.exitValue());
    p.destroy();
    br.close();

    p = Runtime.getRuntime().exec("ls -l /home/vcap/misc");
    br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((s = br.readLine()) != null)
        System.out.println("line: " + s);
    p.waitFor();
    System.out.println ("#### Executing command ls with exit: " + p.exitValue());
    p.destroy();
    br.close();
}
catch(IOException ex)
{
    ex.printStackTrace();
}
catch(InterruptedException ex)
{
    ex.printStackTrace();
}
finally
{
    try 
    {
        if(br != null)
            br.close();
    }
    catch(IOException ex) 
    {
        ex.printStackTrace();
    }
}

此代码段应创建一个文件夹,将远程文件系统安装到该文件夹​​中,并列出远程文件系统的内容.

This snippet should create a folder, mount a remote file system into that folder and list the content of the remote file system.

这篇关于有什么方法可以从Bluemix运行时访问NFS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆