如何在Windows上运行Django并应对没有守护进程模式的Apache?
这个问题的演变
这开始是为了寻找在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于使用 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
接受自己的答案可能是不好的形式,但它适合我们的情况,并且可能对其他人有帮助...
首先也是最重要的:我们放弃了寻找一个可以与 PyODBC 正常工作并像 Microsoft 一样支持 unicode 的 ODBC 驱动程序的尝试本机 ODBC 驱动程序。 FreeTDS 只能部分运行,而且一些商业驱动程序在我们的测试中并没有发挥作用。我们考虑过 ODBC-JDBC 桥接器,但从未真正测试过它。
我们还考虑过使用 ODBC 路由器,但考虑到多用户解决方案的价格,我们的 Django 应用程序更加复杂和低负载场景;我们决定继续在 Windows 上运行 Django,并尝试满足每次部署任何 Django 应用程序的新版本时重新启动 Apache 服务器的要求。
我们为应对 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:
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.