ドッカーデプロイジャンゴ+ uWSGI + nginxの
-
手順は以下のとおり:
-
作成CentOSにコンテナを
-
インストールのPython とピップを
-
インストールMySQLを
-
ジャンゴへの接続のMySQL
-
ファイル名を指定して実行uWSGIのサーバー
-
実行nginxののサーバー
作成CentOSにコンテナを
インストールのドッキングウィンドウのソフトウェア
yum install docker
-
作成のCentOS コンテナを
docker run -d --name deploy1 --network host centos tail -f /dev/null
-
-d :それはバックグラウンドで実行してみましょう。
-
Deploy1は-name :セットの名前を。
-
ホスト-network :それはネットワークホストコンピュータに参加し、外部ネットワークに接続することができます。
-
CentOSのは:ミラーを実行します。ドッキングウィンドウは自動的に公式ミラーから引っ張ってくるの最新バージョン。
-
-f尾を/ dev / null :コンテナは、コマンドを実行する必要がありましょう、そう何のタスクを自動的出口はありません。
入力CentOSのコンテナ。
docker exec -it deploy1 bash
-
Djangoのプロジェクトは、宿主からソースコードをコピーするのCentOS 容器
docker cp /root/django deploy1: /var/www/web_project
インストールのPython とピップを
yum install epel-release # 添加epel软件库
yum install python34 # 安装指定版本的python
その後、使用ピップをインストールDjangoのプロジェクトが必要とするPythonのサードパーティのライブラリを。
プロジェクトのディレクトリが存在する場合requirements.txtは、あなたが使用することができます pip3.4は-r requirements.txtをインストール
インストールMySQLを
Yum install mariadb
実行Mysql_secure_installtionは初期化のためのパスワードを設定する123456
ジャンゴへの接続のMySQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 数据库引擎,不用改
'NAME': 'blog', # database名,需要在mysql中已存在
'USER': 'root',
'PASSWORD': '******',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
ファイル名を指定して実行uWSGIのサーバー
-
依存ライブラリ:yumのビルドエッセンシャルのPython-develのインストール
-
インストールuWSGI :PIPはuwsgiをインストール
-
Djangoのプロジェクトディレクトリ、実行します。mkdir uwsgi 、作成uwsgiのフォルダを。そして、実行VI uwsgi / uwsgi.ini その下に作成され、uwsgi.iniを設定ファイルとして、。これは次のように読み取ります。
[uwsgi]
chdir = /var/www/web_project
socket= 127.0.0.1:3301
http = 0.0.0.0:8001
module = web_project.wsgi
#home = /var/www/vitual/
master = true
processes = 5
vacuum = true
daemonize=/var/log/uwsgi.log
開始するには、設定ファイルを使用してuWSGIのサーバー(バックグラウンドでのデフォルトの実行を): uwsgi --ini uwsgi / uwsgi.ini
実行nginxののサーバー
インストールnginxのを: YUM nginxのインストール
変更nginxの設定ファイル/etc/nginx/site-enable/mysite_nginx.conf
upstream django {
server 127.0.0.1:3301; # for a web port socket (we'll use this first)
}
server {
# the port your site will be served on
listen 8081;
# the domain name it will serve for
server_name _; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media{
alias /var/www/web_project/media/; # your oDjango project's media files - amend as required
}
location /static {
alias /var/www/web_project/allstatic/; # your Django project's static files - amend as required
}
location /admin {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
location /api {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
location /ckeditor/upload/ {
proxy_method POST;
proxy_pass http://127.0.0.1:8001$request_uri;
}
location / {
root /var/www/html/dist;
index index.html;
#try_files $uri $uri/ /index.html;
}
}
まず、スタートuWSGIのサーバーは、 nginxの起動nginxの(デーモンとしてデフォルトのランを)サーバーを
-
永続データ
docker run -d -p 80:8081 -p 10000:8001 --restart=always --privileged=true -v /usr/docker_dat/mysql/data:/var/lib/mysql --name newblog5 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root webblog_4
ローカルディレクトリのマッピング容器の内部の/ var / libに/ msyql
-
最初のデータベースを変更する権限が報告されませんMySQLのデータベース権限を
chown -R mysql /var/lib/mysql