【问题标题】:Installing Django, PostgreSQL on Google Compute Engine Debian 7 Instance在 Google Compute Engine Debian 7 实例上安装 Django、PostgreSQL
【发布时间】:2014-07-24 15:44:23
【问题描述】:

我正在尝试在 Google Compute Engine 上部署 Django 应用程序。我正在使用 Debian 7 映像并希望使用 Nginx、Gunicorn、virtualenv、supervisor 和 PostgreSQL 设置 Django。我的开发机器运行 Ubuntu 14.04,安装了 Django,PostgreSQL 作为后端,一切运行良好。

我正在使用位于http://datacommunitydc.org/blog/2013/12/a-tutorial-for-deploying-a-django-application-that-uses-numpy-and-scipy-to-google-compute-engine-using-apache2-and-modwsgi/ 的教程。我还在使用位于http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ 的教程,因为它特定于我在我的开发机器上使用的 virtualenv 和 PostgreSQL。我已经设置了我的 GCE 实例,安装并更新了 aptitude。我已经安装了 PostgreSQL,但是当我尝试为应用程序创建一个数据库用户和一个新数据库时,我收到一个错误,并且没有创建任何内容。

按照我运行的教程:

$ sudo su - postgres postgres@django:~$ createuser -P Enter name of role to add: hello_django Enter password for new role: Enter it again: Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n

当它尝试创建新用户角色时,我收到以下错误:

createuser: could not connect to database postgres: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行 shell 脚本 ls /etc/init.d 时,它说 postgresql 正在运行,但我仍然无法添加新角色。谁能告诉我我做错了什么?

问候。

【问题讨论】:

  • 你找到解决方案了吗,因为我和你有同样的问题。

标签: django postgresql debian google-compute-engine


【解决方案1】:

不久前我遇到了类似的问题。只需几个简单的步骤即可解决:

  1. 作为 postgres 用户运行:initdb --locale en_US.UTF-8 -E UTF8 -D 'var/lib/postgres/data'。注意根据发行版中的 postgres 命令可以是 pgsql。您可以使用 ls 命令轻松检查目录是否存在。
  2. systemctl start postgresql(如果你有 systemd)或者只是 /etc/init.d/postgresql start 应该可以。这些命令必须以超级用户身份 rub。

这一切都来自ArchWiki

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。

    这很可能是因为 postgres 集群尚未初始化。 而它没有自动安装的原因是因为你已经设置了盒子的语言环境。这也是必须在 Amazon EC2 实例上完成的事情。

    你需要运行:

    sudo apt-get install locales
    

    然后:

    sudo dpkg-reconfigure locales
    

    我必须选择要设置的语言环境,我选择了 en_AU UTF-8。

    在此之后我重新启动,然后我可以运行它来初始化集群:

    sudo pg_createcluster 9.1 main --start
    

    这会启动服务并创建 pg_hba.conf 文件等。

    【讨论】:

      【解决方案3】:

      我无法重现该问题,但这似乎是 PostgreSQL 及其依赖项的问题。您可以尝试删除所有已安装的 PostgreSQL 组件和依赖项,然后重新安装 PostgreSQL:

      sudo apt-get remove --purge postgresql-9.1*
      sudo apt-get install postgresql-9.1
      

      如果仍然无法连接到数据库,则问题可能源于您的$PATH,在这种情况下,您需要将其指向/usr/local/bin/psql

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-09
        • 2020-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-31
        • 2014-12-13
        • 1970-01-01
        相关资源
        最近更新 更多