VPS CENTOSにpython、mysql、nginx、uwsgi、djangoを配置する方法について詳しく説明します。


本論文の実例は、VPS CENTOS上にpython、mysql、nginx、uwsgi、djangoを配置する方法を説明する。皆さんに参考にしてあげます。具体的には以下の通りです。
昨日VPSを使ってみました。一日で簡単なアプリケーションを展開しました。次の過程でdjangoでプロジェクトを作成するステップを省きました。あなた自身がstartpojectで作成することを忘れました。
下はもとの操作をしながら記録したものです。テキスト編集に慣れています。フォーマットが良くないかもしれません。今はブログに引越しします。
まずGCCをインストールします

yum -y install gcc automake autoconf libtool make

CENTOSに中国語のカバンをインストールします。
CENTOSバージョンのcat/etc/redhat-releaseを確認します。私のは5.7です。公式サイトで5.7を探しています。見つけられませんでした。5.5を使ってください。

yum groupinstall chinese-support
vi /etc/sysconfig/i18n

内容は以下の通りです

LANG="zh_CN.UTF-8"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"

locallコマンドを使ってシステム言語の設定を確認します。
locale
下に5.5の書庫を使いました。

wget http://ftp.dc.volia.com/pub/CentOS/5.5/os/x86_64/CentOS/fonts-chinese-3.02-12.el5.noarch.rpm
wget http://ftp.dc.volia.com/pub/CentOS/5.5/os/x86_64/CentOS/fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm

rpm-ivhインストールは言いません。
インストールが完了したら、reboot
python 2.72をインストールします

wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz

1.

./configure -with-zlib=/usr/include (   zlib.h         whereis zlib.h)
make install

2.ソフト接続の確立

cd /usr/bin
rm -rf python
ln -s /usr/local/bin/python2.7 python

このようにしたら、ユーム命令が使えなくなるかもしれません。ユームを修正する必要があります。

vi /usr/bin/yum

最初の行のpythonパスを変更します。/usr/bin/python 2.4はcentos用のpython 2.4です。
PIL pythonライブラリの設置

wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
python setup.py install

Django 1.3をインストールします

wget http://www.djangoproject.com/download/1.3/tarball/
python setup.py install

setuptoolsをインストールします

wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
sh setuptools-0.6c11-py2.7.egg Cprefix=/usr/local

python-mysqldbをインストールします

wget http://ncu.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
yum install mysql-devel
python setup.py install

MYSQLの設置(CENTOSは5.0付)

yum install mysql-server

MYSQL登録問題:

# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> Update user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <       newpassword>
mysql> grant all privileges on *.* to 'root'@'%' identified by 'newpassword' with grant option;

UWSGIの取り付け

wget http://projects.unbit.it/downloads/uwsgi-1.1.tar.gz

解凍後

make
cp uwsgi /usr/bin

注:インターネットで資料を見る時、python setup.py buildで操作する必要があります。具体的には、uwsgiの公式サイトを調べて説明します。
あなたのdjangoプロジェクトの中でdjangoを作ります。wsgi.pyのファイル、たとえば私のは/opt/www/uplloadfileの下にあります。

cd /opt/www/uploadfile
vi django_wsgi.py
import os
import sys
sys.path.append("/opt/www") #  project    ,      
os.environ['DJANGO_SETTINGS_MODULE'] = 'uploadfile.settings' #    ,      
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

ディレクトリ/home/uwsgiを作成します。

vi uwsig.ini

内容は以下の通りです

[uwsgi]
socket=127.0.0.1:9000
listen=200
master=true
pidfile=/usr/local/nginx/uwsgi.pid
processes=8
pythonpath=/opt/www/uploadfile
pythonpath=/opt/www/
module=django_wsgi
profiler=true
memory-report=true
enable-threads=true
logdate=true
limit-as=6048
daemonize=/opt/www/logs/django.log

実行uwsgi --ini /home/uwsgi/uwsgi.iniインチングをインストール

wget http://nginx.org/download/nginx-1.0.15.tar.gz
yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel

そして

./configure

インストール後のパスが見えます。

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
make install

そして

cp /usr/local/nginx/sbin/nginx /usr/bin

nginxを実行してnginxを開始します。
止めるなら

nginx -s stop

どうやって再開しますかnginx -s  reloadにもreopenがあります。具体的に区別して自分で見に行きましょう。兄は言いません。
続いて、nginxの配置とdjangoの配合です。

cd /usr/local/nginx/conf
vi django_uwsgi.conf

内容は以下の通りです

server {
listen 80;
server_name 216.24.200.212;
location / {
   uwsgi_pass 127.0.0.1:9000;
   include uwsgi_params;
   access_log off;
}
location ^~ /static {
  root /opt/www/uploadfile;
}
location ^~ /admin/ {
   uwsgi_pass 127.0.0.1:9000;
   include uwsgi_params;
   access_log off;
}
location ~* ^.+\.
(mpg|avi|mp3|swf|zip|pdf|jpg|gif|png|bmp|jpeg|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg|js|css)$ {
   root /opt/www/uploadfile/static;
   access_log off;
}
}

その後、nginx.co nf編集を開いて、http{}に次のように追加します。

include django_uwsgi.conf;
client_max_body_size 20m; #              

=========================================================================================
表示プロセス

ps -ef|grep uwsgi|grep -v grep

もしuwsgiが起動していなかったら、次のように操作します。

uwsgi --ini /home/uwsgi/uwsgi.ini

傍受ポート(私のプロファイルで使う9000)

netstat -an|grep 9000
nginx -s reload

ホームページを開けてみましょう。
http://myipaddress
ここで述べたいのですが、Djangoフレームワークに基づくPythonプログラムの設計に役立ちます。