Any way to access a NFS from Bluemix runtime?

牧云@^-^@ 提交于 2019-12-13 06:38:37

问题


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

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.

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.

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.

Thanks!


回答1:


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

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

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 

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

cf push myappname -s cflinuxfs2.

Update:

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

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.- Include into the app the private key and the known_hosts files.

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

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.



来源:https://stackoverflow.com/questions/30460736/any-way-to-access-a-nfs-from-bluemix-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!