# apt-get install git -y
# git clone git://github.com/ichuan/djblog.git
然后创建数据库,例如 mysql数据库:# mysql -uroot -prootspassword -e 'create database djblog'
拷贝 local_settings.default.py 为 local_settings.py,修改里面的数据库配置。还有其他配置可以改.
执行 python manage.py syncdb 同步数据库.
执行 python manage.py runserver 0.0.0.0:9003 启动临时服务器.
(建议用命令nohup python manage.py runserver 0.0.0.0:9003 > log &)
浏览器访问 http://ur-vps-ip:9003,后台地址是 http://ur-vps-ip:9000/admin/,口令在第 3 步时创建.登录的用户名为root,密码为你自己设置的密码。
(如果忘记登录密码了,可运行命令:进到 /root/djblog 下,执行 python manage.py changepassword root)
在后台的sites里更改默认的example.com为你自己的域名(RSS输出中的链接会使用到).
from https://github.com/ichuan/djblog
demo site:
http://as3.brite.biz:9003,
http://as3.brite.biz:10000/ (类似的程序:youflog(http://code.google.com/p/youflog),它的0.3版我安装成功)
注意: 如果执行 python manage.py syncdb遇到出错提示:No module named MySQLdb,
各种解决办法:
Open Command Prompt
Type "pypm install mysql-python -g"
Read the notes specific to this package.
I think pypm is more powerful and reliable than easy_install?)
或者,你可以去这里 http://www.djangoproject.com/r/python-mysql/ 下载安装 MySQLdb.
(Install MySQL module for Python
There’s a package (Python module) that interfaces a Python Script with a MySQL database back-end. It’s called MySQLdb. For example:
Okay, we know that we have MySQLdb for python2.4 and python2.6, so let’s see where those come from:
Okay, we can, and we were able to upgrade it.
Now for Tempest:
from https://blogs.wellesley.edu/cssysadmin/2012/10/12/install-mysql-module-for-python/)
---------------------------------------------------------------------------
wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd uwsgi-1.9.20
make
编译完毕。
执行文件为~/uwsgi-1.9.20/uwsgi
我是 ubuntu 系统,需要额外装个 libxml2-dev 库:
nginx 的 server 块配置如下:
如果要多加一个网站,只需在 nginx 配置中新加个 server 块,改变下
如果要让 uwsgi 重新载入,可以执行:
示例: http://dj.brite.biz:81/ ,http://yl.brite.biz:81/
以上的 wsgi.py文件如果不行的话,可改为:
import os,sys
if not os.path.dirname(__file__) in sys.path[:1]:
sys.path.insert(0, os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
参考自http://ichuan.net/post/6/using-uwsgi-instead-of-fastcgi-for-django-app/#disqus_thread
# git clone git://github.com/ichuan/djblog.git
然后创建数据库,例如 mysql数据库:# mysql -uroot -prootspassword -e 'create database djblog'
拷贝 local_settings.default.py 为 local_settings.py,修改里面的数据库配置。还有其他配置可以改.
执行 python manage.py syncdb 同步数据库.
执行 python manage.py runserver 0.0.0.0:9003 启动临时服务器.
(建议用命令nohup python manage.py runserver 0.0.0.0:9003 > log &)
浏览器访问 http://ur-vps-ip:9003,后台地址是 http://ur-vps-ip:9000/admin/,口令在第 3 步时创建.登录的用户名为root,密码为你自己设置的密码。
(如果忘记登录密码了,可运行命令:进到 /root/djblog 下,执行 python manage.py changepassword root)
在后台的sites里更改默认的example.com为你自己的域名(RSS输出中的链接会使用到).
from https://github.com/ichuan/djblog
demo site:
http://as3.brite.biz:9003,
http://as3.brite.biz:10000/ (类似的程序:youflog(http://code.google.com/p/youflog),它的0.3版我安装成功)
注意: 如果执行 python manage.py syncdb遇到出错提示:No module named MySQLdb,
各种解决办法:
- easy_install mysql-python (mix os)
- pip install mysql-python (mix os)
- 自行编译:
mysqldb
is a module for Python that doesn't come pre-installed or with Django. You can downloadmysqldb
here. http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python, http://mysql-python.sourceforge.net/FAQ.html - apt-get install python-mysqldb (Ubuntu, ...)
- cd /usr/ports/databases/py-MySQLdb && make install clean (FreeBSD)
- yum install MySQL-python (Fedora, CentOS ...)
- (7.If you are running on Vista, you may want to check out the Bitnami Django stack. It is an all-in-one stack of Apache, Python, MySQL, etc. packaged with Bitrock crossplatform installers to make it really easy to get started. It runs on Windows, Mac and Linux. Oh, and is completely free.)
(Download and install ActivePython-http://www.activestate.com/activepython/downloads#Open Command Prompt
Type "pypm install mysql-python -g"
Read the notes specific to this package.
I think pypm is more powerful and reliable than easy_install?)
或者,你可以去这里 http://www.djangoproject.com/r/python-mysql/ 下载安装 MySQLdb.
(Install MySQL module for Python
There’s a package (Python module) that interfaces a Python Script with a MySQL database back-end. It’s called MySQLdb. For example:
[root@puma ~] python2.4 Python 2.4.3 (#1, Jun 18 2012, 08:55:23) >>> import MySQLdb >>> [root@puma ~] python2.6 Python 2.6.5 (r265:79063, Jun 8 2010, 15:27:41) >>> import MySQLdb >>> [root@puma ~] python2.7 Python 2.7 (r27:82500, Aug 29 2012, 15:28:26) >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named MySQLdb >>> [root@puma ~]Oops. So, that last one is a bit of a problem. No problem, thought I. That’s what pip is for:
[root@puma ~] pip-2.7 install MySQLdb Downloading/unpacking MySQLdb Real name of requirement MySQLdb is MySQLdb Could not find any downloads that satisfy the requirement MySQLdb No distributions at all found for MySQLdb Storing complete log in /root/.pip/pip.log [root@puma ~]Hmm. Not as easy as I hoped. Okay, so, what is the module actually called?
[root@puma ~] pip-2.7 search MySQLdb jaraco.mysql - MySQLDB-compatible MySQL wrapper by Jason R. Coombs mysqldbda - MySQL Database adapter raisin.mysqldb - UNKNOWN sqlShort - A tiny wrapper for the Python modules MySQLdb and Sqlite sqlwitch - sqlwitch offers idiomatic SQL generation on top of MySQLdb. torndb - A lightweight wrapper around MySQLdb. Originally part of the Tornado framework.Hmm. I’m still not sure. None of those look quite right, though many of them look interesting.
Okay, we know that we have MySQLdb for python2.4 and python2.6, so let’s see where those come from:
[root@puma ~] locate MySQLdb /usr/lib64/python2.4/site-packages/MySQLdb /usr/lib64/python2.4/site-packages/MySQLdb/__init__.py /usr/lib64/python2.4/site-packages/MySQLdb/__init__.pyc /usr/lib64/python2.4/site-packages/MySQLdb/__init__.pyo /usr/lib64/python2.4/site-packages/MySQLdb/connections.py ... /usr/lib64/python2.4/site-packages/MySQLdb/constants/__init__.pyc /usr/lib64/python2.4/site-packages/MySQLdb/constants/__init__.pyo /usr/share/doc/MySQL-python-1.2.3/MySQLdb.txt [root@puma ~]Grrr. That’s distressing. So there’s no file/directory called MySQLdb except for Python2.4 So, where is the one for Python2.6? Back to the drawing board:
[cs304@puma ps2] python2.6 Python 2.6.5 (r265:79063, Jun 8 2010, 15:27:41) >>> import sys >>> sys.path ['', '/usr/local/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg', '/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg', '/usr/local/lib/python2.6/site-packages/Theano-0.3.0-py2.6.egg', ..., '/usr/local/lib/python2.6/site-packages'] >>> import MySQLdb >>> [cs304@puma ps2] cd /usr/local/lib/python2.6/site-packages/ [cs304@puma site-packages] file MySQL_python-1.2.3-py2.6-linux-x86_64.egg MySQL_python-1.2.3-py2.6-linux-x86_64.egg: Zip archive data, at least v2.0 to extract [cs304@puma site-packages] zipinfo MySQL_python-1.2.3-py2.6-linux-x86_64.egg Archive: MySQL_python-1.2.3-py2.6-linux-x86_64.egg 107724 37 -rw-rw---- 2.0 unx 524 b- defN 28-Feb-11 13:37 _mysql.pyc -rw-rw---- 2.0 unx 276 b- defN 28-Feb-11 13:37 _mysql.py -rwxrwx--- 2.0 unx 147488 b- defN 28-Feb-11 13:34 _mysql.so -rw-rw---- 2.0 unx 2306 b- defN 17-Jun-10 03:21 _mysql_exceptions.py -rw-rw---- 2.0 unx 4139 b- defN 28-Feb-11 13:37 _mysql_exceptions.pyc -rw-rw---- 2.0 unx 3121 b- defN 17-Jun-10 03:21 MySQLdb/__init__.py -rw-rw---- 2.0 unx 6317 b- defN 28-Feb-11 13:37 MySQLdb/converters.pyc -rw-rw---- 2.0 unx 12338 b- defN 28-Feb-11 13:37 MySQLdb/connections.pyc -rw-rw---- 2.0 unx 4529 b- defN 28-Feb-11 13:37 MySQLdb/times.pyc ... EGG-INFO/native_libs.txt -rw-rw-r-- 2.0 unx 868 b- defN 28-Feb-11 13:37 EGG-INFO/SOURCES.txt -rw-rw---- 2.0 unx 1 b- defN 28-Feb-11 13:37 EGG-INFO/zip-safe -rw-rw-r-- 2.0 unx 1751 b- defN 28-Feb-11 13:37 EGG-INFO/PKG-INFO -rw-rw-r-- 2.0 unx 33 b- defN 28-Feb-11 13:37 EGG-INFO/top_level.txt 37 files, 279214 bytes uncompressed, 103268 bytes compressed: 63.0% scottas-imac91:~ scotta$Wow, that was quite a journey. So, it seems the MySQLdb module is inside an “egg” called MySQL_python. Can we find *that* with pip?
Okay, we can, and we were able to upgrade it.
[root@puma cgi-bin] pip-2.6 search MySQL_python MySQL-python - Python interface to MySQL INSTALLED: 1.2.3 LATEST: 1.2.4b5 [root@puma cgi-bin] pip-2.6 install --upgrade MySQL_python Downloading/unpacking MySQL-python from http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4b5.tar.gz#md5=2d760ee948aff4f50d01afdf8afff48c Downloading MySQL-python-1.2.4b5.tar.gz (82Kb): 82Kb downloaded Running setup.py egg_info for package MySQL-python Downloading Installing collected packages: MySQL-python Found existing installation: MySQL-python 1.2.3 Uninstalling MySQL-python: Successfully uninstalled MySQL-python Running setup.py install for MySQL-python Successfully installed MySQL-python Cleaning up... [root@puma cgi-bin]One quick test:
[root@puma ~] python2.6 Python 2.6.5 (r265:79063, Jun 8 2010, 15:27:41) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> [root@puma ~] su - anderson [anderson@puma ~] python2.6 Python 2.6.5 (r265:79063, Jun 8 2010, 15:27:41) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named MySQLdb >>> [anderson@puma ~] logout [root@puma ~] ls -lt /usr/local/lib/python2.6/site-packages/ total 732 drwxrwx--- 3 root root 4096 Oct 11 21:45 MySQLdb -rw-rw-r-- 1 root root 4305 Oct 11 21:45 _mysql_exceptions.pyc drwxrwxr-x 2 root root 4096 Oct 11 21:45 MySQL_python-1.2.4b5-py2.6.egg-info -rwxrwxr-- 1 root root 148882 Oct 11 21:45 _mysql.so -rw-rw-r-- 1 root root 445 Oct 11 21:45 easy-install.pth -rw-rw-r-- 1 root root 2352 Oct 11 21:45 _mysql_exceptions.py drwxrwxr-x 4 root root 4096 Jul 26 20:57 pip-1.1-py2.6.egg drwxrwxr-x 5 root root 4096 Jun 17 15:00 networkx-1.7rc1-py2.6.egg drwxrwxr-x 4 root root 4096 Jun 17 14:03 Orange-2.5a4-py2.6-linux-x86_64.eggDarn! pip never sets the directory permissions properly, and I always forget. (Oh, and I see that the upgrade has created a MySQLdb directory, instead of hiding the module inside an egg.) A quick fix:
[root@puma ~] opendir /usr/local/lib/python2.6/site-packages/And we’re done:
[anderson@puma ~] python2.6 -c 'import MySQLdb'whew! Now, can we finally install MySQLdb for python2.7?
[root@puma ~] pip-2.7 search MySQL_python MySQL-python - Python interface to MySQL [root@puma ~] pip-2.7 install MySQL_python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.4b5.tar.gz (82Kb): 82Kb downloaded Running setup.py egg_info for package MySQL-python Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz Extracting in /tmp/tmpGemlI5 Now working in /tmp/tmpGemlI5/distribute-0.6.28 Building a Distribute egg in /root/build/MySQL-python /root/build/MySQL-python/distribute-0.6.28-py2.7.egg Installing collected packages: MySQL-python Running setup.py install for MySQL-python building '_mysql' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',5) -D__version__=1.2.4b5 -I/usr/include/mysql -I/usr/local/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_mysql.so Successfully installed MySQL-python Cleaning up... [root@puma ~] ls -lt /usr/local/lib/python2.7/site-packages/ | head total 592 drwxrwx--- 3 root root 4096 Oct 11 22:36 MySQLdb -rw-rw---- 1 root root 4303 Oct 11 22:36 _mysql_exceptions.pyc drwxrwx--- 2 root root 4096 Oct 11 22:36 MySQL_python-1.2.4b5-py2.7.egg-info -rwxrwx--- 1 root root 148898 Oct 11 22:36 _mysql.so -rw-rw---- 1 root root 2352 Oct 11 22:36 _mysql_exceptions.py drwxrwx--- 18 root root 4096 Aug 31 10:27 numpy drwxrwx--- 2 root root 4096 Aug 31 10:27 numpy-1.6.2-py2.7.egg-info drwxrwx--- 2 root root 4096 Aug 31 10:23 simplejson-2.6.1-py2.7.egg-info drwxrwx--- 3 root root 4096 Aug 31 10:23 simplejson [root@puma ~] opendir /usr/local/lib/python2.7/site-packages/ [root@puma ~] su - anderson [anderson@puma ~] python2.7 -c 'import MySQLdb' [anderson@puma ~]Yes, we can! Woo-hoo! (And, as a side-effect, we made numpy and simplejson and other things available in Python2.7.)
Now for Tempest:
[root@tempest ~] pip-2.6 search MySQL_python MySQL-python - Python interface to MySQL [root@tempest ~] pip-2.6 install MySQL_python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.4b5.tar.gz (82Kb): 82Kb downloaded Running setup.py egg_info for package MySQL-python The required version of distribute (>=0.6.28) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U distribute'. (Currently using distribute 0.6.10 (/usr/lib/python2.6/site-packages)) Complete output from command python setup.py egg_info: The required version of distribute (>=0.6.28) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U distribute'. (Currently using distribute 0.6.10 (/usr/lib/python2.6/site-packages)) Command python setup.py egg_info failed with error code 2 Storing complete log in /root/.pip/pip.log [root@tempest ~] easy_install easy_install easy_install-2.6 easy_install-2.7 [root@tempest ~] easy_install-2.6 -U distribute Searching for distribute Reading http://pypi.python.org/simple/distribute/ Reading http://packages.python.org/distribute Best match: distribute 0.6.28 Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz#md5=b400b532e33f78551e6847c1f5965e56 Processing distribute-0.6.28.tar.gz Running distribute-0.6.28/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ScwCrB/distribute-0.6.28/egg-dist-tmp-1aKoLe Before install bootstrap. Scanning installed packages Setuptools installation detected at /usr/lib/python2.6/site-packages Non-egg installation Removing elements out of the way... Already patched. /usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info already patched. After install bootstrap. /usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info already exists Adding distribute 0.6.28 to easy-install.pth file Installing easy_install script to /usr/bin Installing easy_install-2.6 script to /usr/bin Installed /usr/lib/python2.6/site-packages/distribute-0.6.28-py2.6.egg Processing dependencies for distribute Finished processing dependencies for distribute [root@tempest ~] pip-2.6 install MySQL_python Downloading/unpacking MySQL-python Running setup.py egg_info for package MySQL-python Installing collected packages: MySQL-python Running setup.py install for MySQL-python building '_mysql' extension gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,4,'beta',5) -D__version__=1.2.4b5 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX In file included from /usr/include/mysql/my_config.h:14, from _mysql.c:44: /usr/include/mysql/my_config_x86_64.h:1082:1: warning: "HAVE_WCSCOLL" redefined In file included from /usr/include/python2.6/pyconfig.h:6, from /usr/include/python2.6/Python.h:8, from _mysql.c:29: /usr/include/python2.6/pyconfig-64.h:808:1: warning: this is the location of the previous definition gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so Successfully installed MySQL-python Cleaning up... [root@tempest ~]Okay, a bit of a detour in the middle, there, but ultimately successful. Wasn’t it? Let’s check:
[root@tempest ~] python2.6 Python 2.6.6 (r266:84292, Aug 28 2012, 10:55:56) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> MySQLdb.__file__ '/usr/lib64/python2.6/site-packages/MySQLdb/__init__.pyc' >>> [root@tempest ~] ls -lt /usr/lib64/python2.6/site-packages/ | head total 8988 drwxrwx---. 2 root root 4096 Oct 11 22:42 MySQL_python-1.2.4b5-py2.6.egg-info -rw-rw----. 1 root root 4257 Oct 11 22:42 _mysql_exceptions.pyc drwxrwx---. 3 root root 4096 Oct 11 22:42 MySQLdb -rwxrwx---. 1 root root 141945 Oct 11 22:42 _mysql.so -rw-rw----. 1 root root 2352 Oct 11 22:40 _mysql_exceptions.py drwxr-xr-x. 2 root root 4096 Oct 3 23:20 qmf -rwxr-xr-x. 1 root root 46472 Sep 11 10:10 SpiceClientGtk.so -rw-r--r--. 2 root root 11329 Sep 5 04:29 drv_libxml2.pyc -rw-r--r--. 2 root root 11329 Sep 5 04:29 drv_libxml2.pyo [root@tempest ~] opendir /usr/lib64/python2.6/Okay, so the libraries are in /usr/lib64 instead of /usr/local/lib as on Puma. We should check what other library directories python2.6 is on Tempest:
[root@tempest ~] ls -lt /usr/lib/python2.6/site-packages/ | head total 1228 -rw-r--r--. 1 root root 30 Oct 11 22:42 setuptools.pth -rw-rw-r--. 1 root root 457 Oct 11 22:42 easy-install.pth drwxrwx---. 4 root root 4096 Oct 11 22:42 distribute-0.6.28-py2.6.egg drwxr-xr-x. 2 root root 4096 Oct 3 23:20 mllib drwxr-xr-x. 5 root root 4096 Oct 3 23:20 qpid [root@tempest ~] opendir /usr/lib/python2.6/site-packages/So, we’ve opened that up, too. One last test:
[root@tempest ~] su - anderson [anderson@tempest ~] python2.6 -c 'import MySQLdb'Now to install MySQLdb for python2.7:
[root@tempest ~] pip-2.7 search MySQL_python MySQL-python - Python interface to MySQL [root@tempest ~] pip-2.7 install MySQL_python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.4b5.tar.gz (82Kb): 82Kb downloaded Running setup.py egg_info for package MySQL-python Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz Extracting in /tmp/tmpwuvghL Now working in /tmp/tmpwuvghL/distribute-0.6.28 Building a Distribute egg in /root/build/MySQL-python /root/build/MySQL-python/distribute-0.6.28-py2.7.egg Installing collected packages: MySQL-python Running setup.py install for MySQL-python building '_mysql' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',5) -D__version__=1.2.4b5 -I/usr/include/mysql -I/usr/local/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX In file included from /usr/include/mysql/my_config.h:14, from _mysql.c:44: /usr/include/mysql/my_config_x86_64.h:1082:1: warning: "HAVE_WCSCOLL" redefined In file included from /usr/local/include/python2.7/Python.h:8, from _mysql.c:29: /usr/local/include/python2.7/pyconfig.h:881:1: warning: this is the location of the previous definition gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_mysql.so Successfully installed MySQL-python Cleaning up... [root@tempest ~] opendir /usr/local/lib lib/ lib64/ libexec/ [root@tempest ~] opendir /usr/local/lib/python2.7/ [root@tempest ~] su - anderson [anderson@tempest ~] python2.7 -c 'import MySQLdb' [anderson@tempest ~]Whew! I think we’re good now.
from https://blogs.wellesley.edu/cssysadmin/2012/10/12/install-mysql-module-for-python/)
---------------------------------------------------------------------------
用uWSGI替代fastcgi部署django应用
部署过程
首先下载编译 uwsgi:http://projects.unbit.it/downloads/uwsgi-latest.tar.gzwget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd uwsgi-1.9.20
make
编译完毕。
执行文件为~/uwsgi-1.9.20/uwsgi
我是 ubuntu 系统,需要额外装个 libxml2-dev 库:
sudo apt-get install libxml2-dev
启动 uwsgi:~/uwsgi-1.9.20/uwsgi -s /tmp/uwsgi.sock -C -M -p 4 -t 30 --limit-as 128 -R 10000 --vhost -d /tmp/uwsgi.log --pidfile /tmp/uwsgi.pid --pythonpath /var/
表示用 unix socket 方式执行 uwsgi,-C
表示将 /tmp/uwsgi.sock
文件权限改成 666 以便 nginx 可以读取,-M
表示启动管理进程,-p 4
表示预生成 4 个 worker 子进程,-t 30
是 cgi 程序超时,--limit-as 128
表示限制内存最大 128M,-R 10000
表示每个 worker 处理的最大请求数,--vhost
表示启用虚拟服务器,-d /tmp/uwsgi.log
表示以守护进程方式启动,指定日志文件。/var/为你的网站目录的上一层目录。(我的网站目录为/var/djblog/).如果你的网站目录为/root/xxx/,那么你需把
/var/改为/root/,
再运行一次该命令:
uwsgi -s /tmp/uwsgi.sock -C -M -p 4 -t 30 --limit-as 128 -R 10000 --vhost -d /tmp/uwsgi.log --pidfile /tmp/uwsgi.pid --pythonpath /root/
这个命令可以放入 /etc/rc.local
作为开机自启动。nginx 的 server 块配置如下:
location / {
uwsgi_pass unix:///tmp/uwsgi.sock;
uwsgi_param UWSGI_CHDIR /var/djblog;
uwsgi_param UWSGI_SCRIPT wsgi;
include uwsgi_params;
}
上面的配置的前提是,你的 django工程在 /var/djblog
,并且在该目录下有个 wsgi.py
文件。文件内容如下:import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'djblog.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
如此配置好后,重启 nginx 就可以了。如果要多加一个网站,只需在 nginx 配置中新加个 server 块,改变下
UWSGI_CHDIR
的值为你新网站的根目录即可。如果要让 uwsgi 重新载入,可以执行:
kill -HUP `cat /tmp/uwsgi.pid`
如果要停止 uwsgi,可以给它的 master 进程发送 SIGINT信号:kill -SIGINT `cat /tmp/uwsgi.pid`
uwsgi 的更多配置在此。示例: http://dj.brite.biz:81/ ,http://yl.brite.biz:81/
以上的 wsgi.py文件如果不行的话,可改为:
import os,sys
if not os.path.dirname(__file__) in sys.path[:1]:
sys.path.insert(0, os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
参考自http://ichuan.net/post/6/using-uwsgi-instead-of-fastcgi-for-django-app/#disqus_thread