Ibm cloud 尝试在Bluemix上使用FUSE的问题

Ibm cloud 尝试在Bluemix上使用FUSE的问题,ibm-cloud,sshfs,Ibm Cloud,Sshfs,我正在寻找一种方法,将一个远程文件系统添加到Bluemix中。在本文中,我被告知使用最新版本的CloudFoundry支持的cflinuxfs2堆栈 我能够从Java应用程序中为挂载点执行mkdir命令,并执行sshfs命令,但最后一个命令失败:“读取:由对等方重置连接” 关键是,在家里的Linux设备中使用的相同命令可以很好地工作,因此我理解该命令、ssh密钥和已知主机文件都可以 这是在Bluemix中部署到Liberty运行时的Java EE代码片段: String s = null; Pr

我正在寻找一种方法,将一个远程文件系统添加到Bluemix中。在本文中,我被告知使用最新版本的CloudFoundry支持的cflinuxfs2堆栈

我能够从Java应用程序中为挂载点执行mkdir命令,并执行sshfs命令,但最后一个命令失败:“读取:由对等方重置连接”

关键是,在家里的Linux设备中使用的相同命令可以很好地工作,因此我理解该命令、ssh密钥和已知主机文件都可以

这是在Bluemix中部署到Liberty运行时的Java EE代码片段:

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("sshfs ibmcloud@129.41.133.34:/ /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.getErrorStream()));
    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();
}
catch(IOException ex)
{
    ex.printStackTrace();
}
catch(InterruptedException ex)
{
    ex.printStackTrace();
}
finally
{
    try 
    {
        if(br != null)
            br.close();
    }
    catch(IOException ex) 
    {
        ex.printStackTrace();
    }
}
命令中的引用文件包含在EAR文件中,并作为应用程序的一部分推送。我可以看到他们和他们的内容浏览文件系统从Bluemix仪表板

在浏览网页时,我发现了大量关于错误消息的帖子:“read:Connection reset by peer”,但似乎它们不适用于我的情况,或者它们与防火墙和配置文件有关,我在Bluemix中没有访问权限。正如我所说的,在家里的linux设备中执行的两个相同的命令都可以正常工作

有什么想法或建议让它工作吗?以前有人在Bluemix中测试过这个想法吗


谢谢

好的,在团队同事的帮助下,我终于找到了问题的原因。问题在于私有ssh密钥的权限。它必须是600,在
cf推送之后默认为644

因此,这里是最后的代码(快速和肮脏)的工作,只是以防万一,它可以对其他人有用

  • 将私钥和已知的_主机文件包含到应用程序中

  • 推送应用程序添加
    -s cflinuxfs2
    参数

  • 在运行时启动时执行以下代码:

    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();
        }
    }
    
    此代码段应创建一个文件夹,将远程文件系统装入该文件夹,并列出远程文件系统的内容


  • 使用
    printStackTrace()
    没有打印出任何内容?没有,因为没有Java错误。从Java的角度来看,该命令是“正确”执行的,它返回退出代码1。仅此而已。我刚刚发现了p.getErrorStream()来获取控制台错误,而不仅仅是常规控制台输出。问题似乎是:fusermount:option allow_other仅在/etc/fuse.conf中设置了“user_allow_other”时才允许,因此我有了一个新的调查领域。我会发回调查结果。用最近的调查结果更新问题。。。