項目管理系統 TAIGA 部署


題記

使用了 MantisBT 一段時間,覺得功能太少,只局限在錯誤跟蹤,而且操作體驗比較差,界面很糟糕,很早就想將其換掉。

偶然發現一個很不錯的新選擇:Taiga,於是就試着將其部署下來,發現絕對是一個好東西,對於實踐 Scrum 項目管理方法的,更是不可多得的利器!

產品官網:https://taiga.io/

GITHUB:https://github.com/taigaio

安裝指南:http://taigaio.github.io/taiga-doc/dist/setup-production.html

由於這個項目是用 Django(1.7) 開發的,因此個人情感非常認同,並且在部署的過程中,也順手牽羊 GET 到了關於 Django 部署的一些技能。

1. 部署概要

首先,項目是使用 RESTFUL 模式開發的,也就是說,后台跟前台完全獨立。

前台部分,使用的是 AngularJS (也非常對我的口味),因此單純使用 nginx 靜態部署,不存在太大的問題。

關鍵是后端,使用 Django + REST Framework,因此部署起來總是有那么點困惑,下面重點需要解決的是后端部署的問題。

不過好在前面給出的安裝指南鏈接上面給出了詳盡可用嘆為觀止的部署流程,雖然步驟較多,但是也是一步一步搞下來就可以使用了,下面就根據這個流程過一遍,並且對未盡部分,一些可能卡住的情況進行一下說明,兼做記錄。

其實按照指南裝下來基本沒什么障礙,主要問題在於,有些 PyPI 的包其實在 requirements.txt 里面是沒有的,因此需要看日志發現問題,然后手動補上這些包。


2. 環境准備

http://taigaio.github.io/taiga-doc/dist/setup-production.html#_before_starting

首先,我們的環境基本跟指引里面的一致,使用 Ubuntu14.04,對一下其他條件:

  1. IP 沒什么好說的
  2. 主機名,我們用的是 taiga.easecloud.cn,注意把后面的 example.com 換成我們自己的即可。
  3. 用戶 taiga,這個我們需要事先創建好,並且賦予其 sudo 權限。
  4. system ram 請無視。

現在創建 taiga 用戶:

adduser taiga

然后賦予其 sudo 權限:

visudo
# User privilege specification root ALL=(ALL:ALL) ALL # 在這行后面加上: taiga ALL=(ALL:ALL) ALL 

3. 后台安裝:

3.1. 安裝依賴項

sudo apt-get install -y build-essential binutils-doc autoconf flex bison libjpeg-dev sudo apt-get install -y libfreetype6-dev zlib1g-dev libzmq3-dev libgdbm-dev libncurses5-dev sudo apt-get install -y automake libtool libffi-dev curl git tmux 

3.2. 安裝 postgresql

sudo apt-get install -y postgresql-9.3 postgresql-contrib-9.3 sudo apt-get install -y postgresql-doc-9.3 postgresql-server-dev-9.3 # 創建數據庫 sudo -u postgres createuser taiga sudo -u postgres createdb taiga -O taiga 

3.3. 安裝 python 環境

sudo apt-get install -y python3 python3-pip python-dev python3-dev python-pip virtualenvwrapper sudo apt-get install libxml2-dev libxslt-dev 

這里安裝了 Python3.4 作為主要的 python 環境,也就是說 python, pip 這兩個命令日后在系統里面對應 3.4 版本,而 python2 和 pip2 對應舊版的 2.7 版本。

另有值得注意的是 virtualenv 的安裝,后面用到這個配置相當重要,具體邏輯在過程中進行了學習,參考:

http://www.huangwenchao.com.cn/2015/05/python-virtualenv.html

下載源碼
cd ~ git clone https://github.com/taigaio/taiga-back.git taiga-back cd taiga-back git checkout stable 
創建 virtualenv taiga
mkvirtualenv -p /usr/bin/python3.4 taiga 
安裝 PyPI 依賴項
pip install -r requirements.txt 

注意!在實際操作中這里的依賴項不全,因此如果跑步起來需要看日志看一下少了哪個庫。

映射數據庫和載入初始數據
python manage.py migrate --noinput python manage.py loaddata initial_user python manage.py loaddata initial_project_templates python manage.py loaddata initial_role python manage.py collectstatic --noinput 

注意第一步很容易卡住,原因是缺少 PyPI 庫的問題,關注日志。

填寫 Python 配置文件
from .common import *

MEDIA_URL = "http://example.com/media/" STATIC_URL = "http://example.com/static/" ADMIN_MEDIA_PREFIX = "http://example.com/static/admin/" SITES["front"]["scheme"] = "http" SITES["front"]["domain"] = "example.com" SECRET_KEY = "theveryultratopsecretkey" DEBUG = False TEMPLATE_DEBUG = False PUBLIC_REGISTER_ENABLED = True DEFAULT_FROM_EMAIL = "no-reply@example.com" SERVER_EMAIL = DEFAULT_FROM_EMAIL # Uncomment and populate with proper connection parameters # for enable email sending. #EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" #EMAIL_USE_TLS = False #EMAIL_HOST = "localhost" #EMAIL_HOST_USER = "" #EMAIL_HOST_PASSWORD = "" #EMAIL_PORT = 25 # Uncomment and populate with proper connection parameters # for enable github login/singin. #GITHUB_API_CLIENT_ID = "yourgithubclientid" #GITHUB_API_CLIENT_SECRET = "yourgithubclientsecret" 

注意把上面的域名換掉就差不多了,發送郵件的尚未調試。

3.4. 安裝驗證

在 ~/taiga-back/ 下面執行:

workon taiga
python manage.py runserver 0.0.0.0:8111 

好了之后,可以通過 http://example.com:8111/api/v1/ 訪問接口,用戶名 admin 密碼 123123 登錄正常即說明安裝正確。

3.5. 異步任務

(非必須)跳過

4. 前端部署

由於是靜態頁面,部署比較簡單,基本無意外。

下載代碼
cd ~ git clone https://github.com/taigaio/taiga-front-dist.git taiga-front-dist cd taiga-front-dist git checkout stable 
編輯配置 ~/taiga-front-dist/dist/js/conf.json
{
    "api": "http://example.com/api/v1/", "eventsUrl": "ws://example.com/events", "debug": "true", "publicRegisterEnabled": true, "feedbackEnabled": true, "privacyPolicyUrl": null, "termsOfServiceUrl": null, "maxUploadFileSize": null, "contribPlugins": [] } 

然后把 nginx 的虛擬主機配置到這個目錄下即可運轉。

5. 事件安裝

(非必須)跳過

6. 最終章(HTTP 和 WSGI 部署)

我們使用 Circus 做進程守護,Gunicorn 做 WSGI 容器,然后通過 Nginx 對外提供 HTTP 服務。

6.1. Circus 和 Gunicorn

安裝部件,注意 Circus 需要使用 pip2 安裝。

sudo pip2 install circus 
Circus 基礎配置 ~/circus.ini

按照原版配置基本無需修改,可以將 circus.ini 放到其他目錄,我自己的實踐中放到了 /var/www/circus.ini 中。

[circus]
check_delay = 5 endpoint = tcp://127.0.0.1:5555 pubsub_endpoint = tcp://127.0.0.1:5556 statsd = true [watcher:taiga] working_dir = /home/taiga/taiga-back cmd = gunicorn args = -w 3 -t 60 --pythonpath=. -b 127.0.0.1:8001 taiga.wsgi uid = taiga numprocesses = 1 autostart = true send_hup = true stdout_stream.class = FileStream stdout_stream.filename = /home/taiga/logs/gunicorn.stdout.log stdout_stream.max_bytes = 10485760 stdout_stream.backup_count = 4 stderr_stream.class = FileStream stderr_stream.filename = /home/taiga/logs/gunicorn.stderr.log stderr_stream.max_bytes = 10485760 stderr_stream.backup_count = 4 [env:taiga] PATH = /home/taiga/.virtualenvs/taiga/bin:$PATH TERM=rxvt-256color SHELL=/bin/bash USER=taiga LANG=en_US.UTF-8 HOME=/home/taiga PYTHONPATH=/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages 

注意上面有一點特別容易卡住,就是輸出的日志文件所在目錄 /home/taiga/logs/ 必須存在!否則會啟動失敗,引起需要確保日志目錄事先創建好。

修改 Circus 的啟動設置

配置文件在:/etc/init/circus.conf

start on filesystem and net-device-up IFACE=lo stop on runlevel [016] respawn exec /usr/local/bin/circusd /home/taiga/circus.ini 

注意 circus.ini 的路徑如果不在這個地方需要對應修改。

然后就可以啟動服務了。

sudo service circus start 

6.2. Nginx

安裝 Nginx
sudo apt-get install -y nginx 
添加虛擬主機

創建虛擬主機配置文件:/etc/nginx/sites-available/taiga

server {
    listen 80 default_server; server_name _; large_client_header_buffers 4 32k; client_max_body_size 50M; charset utf-8; access_log /home/taiga/logs/nginx.access.log; error_log /home/taiga/logs/nginx.error.log; # Frontend location / { root /home/taiga/taiga-front-dist/dist/; try_files $uri $uri/ /index.html; } # Backend location /api { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8001/api; proxy_redirect off; } # Django admin access (/admin/) location /admin { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8001$request_uri; proxy_redirect off; } # Static files location /static { alias /home/taiga/taiga-back/static; } # Media files location /media { alias /home/taiga/taiga-back/media; } } 

注意里面的 default_server 和 server_name 如果在需要獨立配置虛擬主機而不是直接占用全站資源,需要根據實際修改(刪除 default-server,把 server_name) 改成自己的。

然后將其啟用:

sudo ln -s /etc/nginx/sites-available/taiga /etc/nginx/sites-enabled/taiga 

6.2.1. 啟用 HTTPS

(非必須)跳過


(完)


【轉載請附】願以此功德,回向 >>

原文鏈接:http://www.huangwenchao.com.cn/2015/05/taiga-deployment.html【項目管理系統 Taiga 部署手札】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM