简体   繁体   English

使用Postgresql数据库创建Azure Web App(可以吗?)

[英]Creating an Azure Web App with Postgresql database (is that possible?)

I use Heroku to host a Django web app with a postgres back-end. 我使用Heroku托管带有postgres后端的Django Web应用程序。 I'm now looking to migrate this web app to Azure, taking advantage of a great deal Azure recently offered me. 我现在正在利用Azure最近为我提供的大量功能,希望将此Web应用程序迁移到Azure。

But I'm confused about one thing: how can I create a Django website on Azure with postgresql as the database ? 但是我对一件事感到困惑:如何以Azure 作为数据库在Azure上创建Django网站? I successfully created a Django website, connected it to git, but I can't seem to change it's DB to postgresql. 我成功创建了一个Django网站,并将其连接到git,但是我似乎无法将其数据库更改为postgresql。

Hence, when I do git push azure master , I get the error: Command python setup.py egg_info failed with error code 1 in D:\\home\\site\\wwwroot\\env\\build\\psycopg2 It fails on psycopg2 (postgresql). 因此,当我执行git push azure master ,出现错误: 命令python setup.py egg_info在D:\\ home \\ site \\ wwwroot \\ env \\ build \\ psycopg2中失败,错误代码为1,在psycopg2(postgresql)上失败。

Secondly, once I do successfully install postgresql on an Azure Web App, I'd need to tweak its postgresql.conf file to tune the settings (defaults are too low). 其次,一旦我在Azure Web App上成功安装了postgresql,就需要调整其postgresql.conf文件以调整设置(默认值太低)。 How would I do that? 我该怎么做?


The documentation only talks about how to install PG for an Azure VM with Linux, not an Azure Web App: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-postgresql/ 该文档仅讨论如何使用Linux而非Azure Web App为Azure VM安装PG: https : //azure.microsoft.com/zh-cn/documentation/articles/virtual-machines-linux-postgresql/

Azure Web Apps Service is a PaaS which provides several services to host your web site apps. Azure Web Apps Service是一种Pa​​aS,可提供多种服务来承载您的网站应用程序。 And we have limit permission to install PostgreSQL on it. 并且我们具有在其上安装PostgreSQL的有限权限。

Currently, to host PostgreSQL on Azure, you can leverage virtual machines with linux as @theadriangreen mentioned. 当前,要在Azure上托管PostgreSQL,您可以使用@theadriangreen提到的带有Linux的虚拟机。 And you can use SSH command ssh user@VMhost to remote on your linux VM and set your PG configurations. 而且,您可以使用SSH命令ssh user@VMhost在Linux VM上进行远程设置,并设置PG配置。 You may refer to YoLinux Tutorial: The PostgreSQL Database and Linux for more about PG on Linux. 您可以参考YoLinux教程:PostgreSQL数据库和Linux,以获取有关Linux上PG的更多信息。

And additionally, you can create a docker contain with PostgreSQL image in Azure add-on market. 另外,您可以在Azure附加市场中创建包含PostgreSQL映像的docker包含。

Login preview manage portal, click new=>search “postgres” in search bar, you can find the postgres service provided by docker. 登录预览管理门户,在搜索栏中单击“新建=>搜索”“ postgres”,即可找到docker提供的postgres服务。

在此处输入图片说明

You also can remote to this VM via SSH to set your PG configurations. 您还可以通过SSH远程到此VM,以设置PG配置。

If you want a direct tcp connection to the PG server, you need to add 5432 port in the Inbound security rules. 如果要直接与PG服务器建立TCP连接,则需要在入站安全规则中添加5432端口。

In “All settings” of the VM server you created above, click “Network interfaces”=>click the interface in use=>click the network security group name in use, you can find the Inbound security rules in the settings page. 在上面创建的VM服务器的“所有设置”中,单击“网络接口” =>单击正在使用的接口=>单击正在使用的网络安全组名称,您可以在设置页面中找到入站安全规则。

在此处输入图片说明

Then you can test the connection of your PG service: 然后,您可以测试PG服务的连接:

import psycopg2

try:
    conn = psycopg2.connect(database="postgres", user="postgres", password="{password}", host="{host_ip}", port="5432")
    print "Opened database successfully"

    cur = conn.cursor()

    cur.execute("SELECT ARRAY[1.1,2.1,3.1]::int[] = ARRAY[1,2,3]");
    rows = cur.fetchall()
    print(rows)

    conn.commit()
    print "Records created successfully";
    conn.close()
except Exception, e:
    print "I am unable to connect to the database"

Azure Web Apps only offers web apps, since the database is provided by another service. 由于数据库是由另一项服务提供的,因此Azure Web Apps仅提供Web应用程序。 Typically this is either Azure SQL, which provides a SQL Server database as a service, or ClearDB, which provides MySQL. 通常,这可以是提供SQL Server数据库即服务的Azure SQL,也可以是提供MySQL的ClearDB。

Thus to get your Django app up and running with Postgres, you're going to need to deploy the Postgres DB somewhere. 因此,要使Django应用程序与Postgres一起启动并运行,您将需要在某个地方部署Postgres DB。 Initially you could try with your settings.py pointed at your Heroku Postgres DB, however you might run into some firewall settings on the DB side. 最初,您可以尝试将settings.py指向Heroku Postgres DB,但是您可能会在DB端遇到一些防火墙设置。

If you were to follow the steps in the link ( https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-postgresql/ ) then you could use that instance as your Postgres DB and adjust your settings.py file to point to that machine. 如果您要按照链接( https://azure.microsoft.com/zh-cn/documentation/articles/virtual-machines-linux-postgresql/ )中的步骤进行操作,则可以将该实例用作Postgres数据库并进行调整您的settings.py文件指向该机器。 You would also be able to change the postgresql.conf since you own the machine. 由于您拥有机器,因此您也可以更改postgresql.conf。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM