下載系統各類依賴javascript
nano /etc/apt/sources.listcss
在Debian中使用apt-get安裝軟件包時常常會提示讓你插入netinst的光盤:html
Media change: please insert the disc labeledjava
把下面這一行註釋掉python
deb cdrom:[Debian GNU/Linux 8.2.0 _Jessie_ - Official amd64 CD Binary-1 20150$mysql
apt-get updatenginx
apt-get install python-setuptools python-dev python-pip python-virtualenv redis-server mysql-server mysql-client git -ygit
把項目拉到服務器redis
cd ~sql
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
把公鑰粘貼到碼雲上
此處應以碼雲上的地址爲準
pip安裝各類包
cd ~/serve/
EnvironmentError:mysql config not found
apt-get install libmysqld-dev
網上有人解釋說使用apt-get安裝的MySQL是沒有mysql_config這個文件的
pip install -r requirements.txt
配置celery
cd /etc/systemd/system/
nano celery.service
內容以下:
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
#User=celery
#Group=celery
EnvironmentFile=-/etc/conf.d/celery
WorkingDirectory=/root/serve
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
--pidfile=${CELERYD_PID_FILE}'
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
[Install]
WantedBy=multi-user.target
mkdir conf.d
cd conf.d/
nano celery
內容以下:
CELERYD_NODES="w1 w2 w3"
CELERY_BIN="/usr/local/bin/celery"
CELERY_APP="serve"
CELERYD_MULTI="multi"
CELERYD_PID_FILE="/etc/celery/%n.pid"
CELERYD_LOG_FILE="/etc/celery/%n%I.log"
CELERYD_LOG_LEVEL=「INFO」
啓動celery
systemctl daemon-reload
systemctl start celery
ps -ef|grep celery
systemctl enable celery
systemctl stop celery
安裝配置uwsgi
pip install uwsgi
cd /root/
nano serve.ini
內容以下:
[Install]
WantedBy=multi-user.target
root@Aaron:/etc/apt# nano /etc/conf.d/celery
root@Aaron:/etc/apt# cat /root/serve.ini
[uwsgi]
chdir=/root/serve
socket=/var/run/serve.sock
chmod-socket=666
module=serve.wsgi:application
master=True
pidfile=/tmp/serve.pid
vacuum=True
max-requests=5000
processes = 4
daemonize=/var/log/uwsgi/serve.log
測試uwsgi是否正常
uwsgi -i /root/serve.ini
ps -ef |grep uwsgi
pkill -9 uwsgi
安裝配置nginx
apt-get install nginx
cd /etc/nginx/sites-enabled/
nano court
注意要把server_name的ip地址改了
內容以下:
server {
listen 80;
server_name 172.16.146.133;
client_max_body_size 10m;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript;
location / {
uwsgi_pass unix:///var/run/serve.sock;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
}
location /static/ {
alias /root/serve/static/;
index index.html index.htm;
}
location /static/admin/ {
alias /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin$
index index.html index.htm;
}
charset utf-8;
}
systemctl restart nginx
ps -ef|grep nginx
卸載nginx(if necessary)
dpkg --get-selections|grep nginx
apt-get --purge remove nginx
apt-get --purge remove nginx-common
apt-get --purge remove nginx-core
find / -name "*nginx*"|rm -fr
數據庫相關操做
service mysql start
mysql -u root -p
create database serve;
create user ‘serve'@'localhost' identified by ‘serve';
grant all privileges ON serve.* to ‘serve'@'localhost';
flush privileges;
exit;
在django生成數據庫相關表
cd ~/serve/
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
啓動服務
systemctl start celery
uwsgi -i /root/serve.ini
可能出現的問題
輸入ip地址以後,可能樣式會丟失,網上解決辦法:
chmod -R 755 /root
這個方法我的以爲是有危險的,可是是最快解決問題的,沒辦法,誰叫你把項目放在root的家目錄下