无法在服务器上创建目录。许可问题? [英] Cannot Create Directory On Server. Permission Issue?

查看:265
本文介绍了无法在服务器上创建目录。许可问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用lucene存储一些数据的索引。以下代码检查/ home / username中目录是否存在,如果找不到,则从头开始构建索引,创建目录等。

I am using lucene to store an index of some data. The following code checks for the existance of a directory in /home/username and if its not found, builds the index from scratch creating the directories etc.

public static final String INDEX_PATH = "/home/username/appname/lucene/index";
private void buildCompleteIndex(int organizationId) {
        synchronized(mutex) {
        File path = new File(INDEX_PATH + "/" + String.valueOf(organizationId));
        if(!path.exists()) {            
            try {
                Utils.deleteDirectory(path);
            } catch (IOException e) {
                throw new LuceneIndexException("Error rebuilding index directory.", e);
            }
            path.mkdirs();
        }

        List<Contact> contactList = contactDAO.findAll(organizationId, true);
        if(contactList != null) {
            for(Contact contact : contactList) {
                add(contact);
            }
        }
    }
}

//Getters
private IndexReader getIndexReader(boolean readOnly, int organizationId) {
    try {
        if(directory == null) {
            File path = getFile(organizationId);
            directory = FSDirectory.open(path);
            if(!IndexReader.indexExists(directory)) {
                buildCompleteIndex(organizationId);
            }
        }
        return IndexReader.open(directory, readOnly);
    } catch (CorruptIndexException e) {
        buildCompleteIndex(organizationId);
    } catch (IOException e) {
        buildCompleteIndex(organizationId);
    }
    return null;
}

当我从虚拟tomcat实例部署时,这一切都在开发中很有用在Eclipse中,但在生产服务器上失败了。

This all works great in development when i'm deploying from a virtual tomcat instance inside of eclipse, but fails on the production server.

为什么我能够以开发模式写入目录,但是当应用程序部署在服务器上时却没有?我没有权限创建目录吗?我正在使用Ubuntu Server 12.10和Tomcat7。

Why would I be able to write to the directory in dev mode, but not when the app is deployed on the server? Do I not have permission to create directories? I'm using Ubuntu Server 12.10 and Tomcat7.

如何在服务器上创建正确的文件夹和文件?

How can I get this creating the proper folders and files on the server?

是否有特定的文件夹我应该允许我的应用程序在服务器上写入?它总是与我的开发盒上的home / user文件夹一起使用,但是在服务器上可能有所不同,因为用户在应用程序运行时实际上没有登录?

Is there a specific folder I am supposed to allow my applications to write to on the server? It always worked with the home/user folder on my dev box, but maybe thats different on the server because the user isn't actually logged in when the application is running?

更新:
我检查了当前设置为700的文件夹的权限。这可能是问题吗?在生产服务器上将此文件夹设置为666或777是否安全?即使未登录/ home / username的用户名,此文件夹是否可写?我知道700意味着所有者拥有完全访问权限,但这包括tomcat应用程序吗?

UPDATE: I checked the permissions of the folder which are currently set to 700. Could that be the problem? Is it safe to set this folder to 666 or 777 on a production server? Is this folder writable even if the username of /home/username is not logged in? I know that 700 means owner has full access, but does that include the tomcat application?

更新:我试图更改/ home /用户名对755的权限和相同的问题仍然存在。

UPDATE: I attempted to change the /home/username's permissions to 755 and the same issue persisted.

显示尝试创建文件夹时生成的错误的堆栈跟踪。

The stacktrace showing the error generated when trying to create the folder.

java.io.IOException: Cannot create directory: /home/ryandlf/thinkbooked.com/lucene/contacts/1
    at org.apache.lucene.store.NativeFSLock.obtain(NativeFSLockFactory.java:171)
    at org.apache.lucene.store.Lock.obtain(Lock.java:72)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:1108)
    at com.thinkbooked.search.LuceneContactSearchEngine.getIndexWriter(LuceneContactSearchEngine.java:321)
    at com.thinkbooked.search.LuceneContactSearchEngine.add(LuceneContactSearchEngine.java:68)
    at com.thinkbooked.search.LuceneContactSearchEngine.buildCompleteIndex(LuceneContactSearchEngine.java:285)
    at com.thinkbooked.search.LuceneContactSearchEngine.getIndexReader(LuceneContactSearchEngine.java:303)
    at com.thinkbooked.search.LuceneContactSearchEngine.find(LuceneContactSearchEngine.java:150)
    at com.thinkbooked.search.LuceneContactSearchEngine.find(LuceneContactSearchEngine.java:145)
    at com.thinkbooked.handlers.ClientListSearchHandler.init(ClientListSearchHandler.java:49)
    at com.thinkbooked.event.EventListener.doPost(EventListener.java:59)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)


推荐答案

根据我在原始问题中发布的问题,在Ubuntu的标准打包版本的tomcat上收到的答案, tomcat在不同的用户名下运行。要找到它,您可以从命令行使用此命令:

According to an answer I received on the question posted in the original question, on Ubuntu's standard packaged version of tomcat, tomcat runs under a different username. To find this you can use this command from the command line:

ps aux | grep catalina

在我的情况下,它告诉我tomcat使用的用户名是tomcat7。

In my case it told me the username tomcat was using is tomcat7.

要编辑默认的tomcat用户名,请在以下位置编辑配置文件:

To edit the default tomcat username, edit the config file in:

/etc/default/tomcat7

第一行应该列出默认的tomcat用户名,然后是组ID在我的情况下是相同的。

The first line should list the default tomcat username and next, the group ID which in my case is the same.

要将文件夹的所有权更改为tomcat以便它可以写入目录,请使用chmod命令。

To change ownership of a folder to tomcat so it can write to the directory, use the chmod command.

sudo chown -R username:group directory

-R表示所有子文件夹和文件也将拥有新的所有权。如果你不想要,请省略。

The -R means all subfolders and files will also have new ownership. Omit this if you don't want that.

这篇关于无法在服务器上创建目录。许可问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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