如何在Windows上运行Django并应对没有守护进程模式的Apache?

发布于 2024-08-10 06:26:38 字数 1401 浏览 6 评论 0原文

这个问题的演变

这开始是为了寻找在 Linux 上运行 Django、通过 Django-PyODBC 访问 SQL Server 以及像在 Windows 上运行 Django 的安装一样支持 Unicode 的其他建议。

在未能为 Linux 中的 ODBC 驱动程序提供一个良好的解决方案来实现与 Windows ODBC 驱动程序相同级别的 Unicode 支持之后;这个问题变成了如何应对 Windows 中没有 Apache 守护进程模式的负面影响。

问题

如果您在 Windows 上运行 Apache+mod_wsgi,则每次部署新的 Django 代码时都需要重新启动 Apache 服务器。请参阅 Graham 的回答详细说明原因。

当您可能需要重新启动 Apache 并拒绝服务直到其完全重新启动时,如何运行一组可靠的应用程序和服务?

问题

我们使用 SQL Server 2005,需要支持 unicode 字符和某些字符(例如 smart-quotes) 在 Microsoft Office 应用程序中生成。

在 SQL Server 2005 上运行 Django 需要我们使用 Django-PyODBC。它在 Windows/Linux/Mac OS X 上运行良好;但如果您需要 unicode 支持,那么您在 Linux / Mac OS X 上就不那么幸运了 - Unix 中 SQL Server 的 ODBC 驱动程序处于不同的 unicode 合规性阶段。如果您指定客户端字符编码为 UTF-8 ( *);但不支持所有字符。

在我们的测试中,在 Windows 2003 上运行 Django 并使用 Microsoft ODBC 驱动程序使我们能够正确插入/更新/选择多种不同语言的任何字符以及 Office 应用程序中的 Microsoft 智能字符。

但在 Windows 上运行意味着每次部署新代码时都需要反弹 Apache - 这意味着几秒钟没有服务。


(*) 坦率地说,我们设法达到 FreeTDS 接受某些字符的唯一方法是向 freetds.conf 添加一个 client charset 条目:

[a_db_server]
    host = a_db_server
    port = 1433
    tds version = 8.0
    client charset  = UTF-8

Evolution of this question

This started as an attempt to find other recommendations for running Django on Linux, accessing SQL Server via Django-PyODBC, and supporting Unicode as competently as in installations running Django on Windows.

After failing to materialize with a good solution for ODBC drivers in Linux that would provide the same level of support for Unicode as the Windows ODBC driver; the question morphed into coping with the negative side-effect of not having an Apache daemon mode in Windows.

The question

If you run Apache+mod_wsgi on Windows, every time you deploy new Django code you are required to restart the Apache server. See Graham's answer for details on why.

How to run a dependable set of applications and services when you might be required to restart Apache, denying service until it completely restarts?

The issue

We use SQL Server 2005 and we need to support unicode characters and certain characters (like smart-quotes) generated in Microsoft Office applications.

Running Django atop SQL Server 2005 requires us to use Django-PyODBC. It works great on Windows/Linux/Mac OS X; but if you require unicode support, you are out of luck on Linux / Mac OS X - the ODBC drivers for SQL Server in Unix are in varied stage of unicode compliance. FreeTDS, the open source driver, works for some characters if you specify a client character encoding of UTF-8 (*); but doesn't support all characters.

In our tests, running Django on Windows 2003 and using the Microsoft ODBC driver allowed us to properly insert/update/select any character in several different languages, and the Microsoft smart characters from Office applications.

But running on Windows means that every time we deploy new code we are required to bounce Apache - which means a few seconds without service.


(*) The only way we managed to get to the point where some characters would be accepted with FreeTDS, frankly, was to add a client charset entry to freetds.conf:

[a_db_server]
    host = a_db_server
    port = 1433
    tds version = 8.0
    client charset  = UTF-8

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难以启齿的温柔 2024-08-17 06:26:38

关于使用 Apache/mod_wsgi 时在 Windows 上重新加载,请阅读我的回复:

Django live/staging 的服务器软件选择

In relation to reloading on Windows when using Apache/mod_wsgi, read my response to:

Server software choice for Django live/staging

青丝拂面 2024-08-17 06:26:38

接受自己的答案可能是不好的形式,但它适合我们的情况,并且可能对其他人有帮助...


首先也是最重要的:我们放弃了寻找一个可以与 PyODBC 正常工作并像 Microsoft 一样支持 unicode 的 ODBC 驱动程序的尝试本机 ODBC 驱动程序。 FreeTDS 只能部分运行,而且一些商业驱动程序在我们的测试中并没有发挥作用。我们考虑过 ODBC-JDBC 桥接器,但从未真正测试过它。

我们还考虑过使用 ODBC 路由器,但考虑到多用户解决方案的价格,我们的 Django 应用程序更加复杂和低负载场景;我们决定继续在 Windows 上运行 Django,并尝试满足每次部署任何 Django 应用程序的新版本时重新启动 Apache 服务器的要求。

我们为应对 Apache 重启并仍然提供服务可用性所做的工作:

  • 我们部署了 Apache 服务器作为代理/负载平衡器到(目前)在 Windows 上运行的两个 Apache 服务器的集群
  • 在集群中的每个 Windows Apache 服务器上,我们都运行着所有 Django 应用程序
  • 当新代码必须部署到服务器我们:
    • 通过 Apache 的平衡器管理器界面禁用集群中的一台服务器
    • 应用更新并在已禁用的服务器中安装所有新的 Django 应用
    • 在已禁用的服务器中测试修改
    • 通过 Apache 的平衡器管理器界面重新启用集群中的服务器
    • 对第二个服务器执行相同的步骤

只要集群中的一台服务器启用并运行,应用程序和服务就可供我们的用户使用 - 不会出现中断。同时,我们获得了一些负载平衡(在我们的例子中,我们此时确实不需要它)。

代理 Apache 服务器重写所有重定向和 cookie 响应标头,因此只要人们通过代理访问服务,就不需要对 Django 代码进行任何修改。

Might be bad form to accept one's own answer, but it suited our case and it may help others...


First and foremost: we gave up trying to find an ODBC driver that would work properly with PyODBC and support unicode as competently as the Microsoft native ODBC driver. FreeTDS works partially, and some of the commercial drivers out there just didn't cut it in our tests. We considered a ODBC-JDBC bridge, but never really tested it.

We also thought about using an ODBC router, but given the price for a multi-user solution, the potential for more complexity, and the low load scenario for our Django apps; we decided to just stick with running Django on Windows and try to cope with the requirement of restarting the Apache server every time a new version of any of the Django apps is deployed.

What we did to cope with the Apache restart and still provide service availability:

  • We deployed an Apache server as a proxy/load-balancer to a cluster of (at the moment) two Apache servers running on Windows
  • On each of the Windows Apache servers in the cluster we have all our Django apps running
  • When new code must be deployed to the servers we:
    • Disable one of the servers in the cluster via Apache's balancer-manager interface
    • Apply the updates and install any new Django apps in the disabled server
    • Test the modifications in the disabled server
    • Reenable the the server in the cluster via Apache's balancer-manager interface
    • Perform the same steps for the second server

As long as one of the servers in the cluster is enabled and running, the applications and services are available to our users - no interruption. At the same time we gained some load-balancing (in our case we really don't need it at this point).

The proxy Apache servers rewrites all the redirects and cookie response headers, so as long as people are accessing the services through the proxy, there are no modifications needed in the Django code whatsoever.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文