本文出自:http://www.huxun360.com/view_blog/28python
1、安裝所需工具mysql
yum -y install gcc gcc-c++ rpm-build mysql* libtool-ltdl* libtool automake autoconf libtool make setuptoollinux
2、編譯安裝python2.7.5nginx
1. 下載python2.7.5,保存到 /data/qtongmon/softwarec++
http://www.python.org/ftp/python/web
2. 解壓文件sql
tar xvf Python-2.7.5.tar.bz2django
3. 建立安裝目錄vim
mkdir /usr/local/python27app
4. 安裝python
./configure --prefix=/usr/local/python27 --enable-shared
make
make install
5. 修改老版本的ln指向(注意:這裏修改後,可能會影響yum的使用)
mv /usr/bin/python /usr/bin/python2.4.3
ln -s /usr/local/python27/bin/python /usr/bin/python
6.yum是使用python寫的,升級新版本的python後會致使yum不可用,以下爲運行yum時的錯誤提示:
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
解決方法:
查找yum文件,並編輯此py文件
[root@TC-Boss ~]# which yum
/usr/bin/yum
[root@TC-Boss ~]# vi /usr/bin/yum
將
#!/usr/bin/python
改成:
whereis python出來的結果(老版本的python)
#!/usr/bin/python2.6
而後保存OK.
2、安裝uWSGI
下載uWSGI的最新版
wget http://projects.unbit.it/downloads/
由於我最後採用xml配置django app 的部署,因此編譯 uWSGI 時候須要把libxml編譯進去
yum -y install libxml2-devel
剩下的就簡單了
tar zxvf uwsgi-1.9.17.tar.gz
cd uwsgi-1.9.17
make
cp uwsgi /usr/sbin/uwsgi
若是遇到錯誤:python: error while loading shared libraries: libpython2.7.so.1.0:
cannot open shared object file: No such file
按以下方式解決:
vim /etc/ld.so.conf.d/python2.7.conf
加入如下內容:/usr/local/python27/lib (實際的python安裝路徑下的lib目錄)
保存退出後運行:
ldconfig
便可
至此 uWSGI 就算是安裝完成了,下一步安裝 Nginx
3、Nginx 安裝
參考另外一篇文章:http://galean.blog.51cto.com/7702012/1268352
注意編譯的時候要加上參數:--with-cc-opt='-O3' --with-cpu-opt=opteron
[root@htuidc nginx-1.4.2]# ./configure --with-http_stub_status_module --prefix=/usr/local/nginx --with-cc-opt='-O3' --with-cpu-opt=opteron
4、安裝MySql-python
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
tar zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py install
ImportError: No module named setuptools 解決方案 :
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
/usr/bin/ld: cannot find -lpython2.7錯誤,解決方案 :
cd /usr/lib
ln -s /usr/local/python27/lib/libpython2.7.so libpython2.7.so
ll -a|grep python
lrwxrwxrwx. 1 root root 39 Oct 1 16:39 libpython2.7.so -> /usr/local/python27/lib/libpython2.7.so
drwxr-xr-x. 3 root root 4096 May 3 15:15 python2.6
出錯:error: command 'gcc' failed with exit status 1
處理方法:
yum -y install mysql-devel
安裝完成,到你的python安裝目錄下的site-packages目錄裏檢查如下文件是否存在,若是存在即表明安裝成功了
Linux:MySQL_python-1.2.3c1-py2.6-linux-i686.egg
測試方法
1)運行命令python進入python運行環境
2)輸入如下python代碼進行測試
import MySQLdb
test=MySQLdb.connect(db='mydb',host='localhost',user='root',passwd='p')
cur = test.cursor()
cur.execute('show databases;')
for data in cur.fetchall():
print data
5、安裝Django
wget https://www.djangoproject.com/m/releases/1.5/Django-1.5.4.tar.gz
tar xzvf Django-1.5.4.tar.gz
cd Django-1.5.4
python setup.py install
測試Django安裝
終端中輸入 python,進入python交互模式,輸入以下:
>>>import django
django.VERSION
正常狀況會顯示版本號碼。
6、nginx配置
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name blog.hysia.com;
access_log /var/log/nginx/blog.hysia.com-access.log ;
error_log /var/log/nginx/blog.hysia.com-error.log ;
location / {
uwsgi_pass 127.0.0.1:8630;
include uwsgi_params;
}
}
7、配置Django app
配置很簡單,幾乎不用改動你app的任何文件。
首先在你的app目錄建立個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()
而後在app目錄建立個django.xml文件,做爲uWSGI運行的配置文件,內容以下:
<uwsgi>
<socket>127.0.0.1:8630</socket>
<chdir>/data/web/vpssite</chdir>
<pythonpath>..</pythonpath>
<module>wsgi</module>
</uwsgi>
最後一步,運行 uWSGI 就好了,以下:
uwsgi -x /data/web/vpssite/django.xml
這樣你的Django app 就用 uWSGI hold住了。django.xml的配置遠不止這些好比log文件,內存限制等等,具體的能夠參考 http://projects.unbit.it/uwsgi/wiki/Example