TAIGA 部署

来源:互联网 发布:win10 php 编辑:程序博客网 时间:2024/04/27 16:56

TAIGA 部署


题记

我叫陈冷耀,来自福建福州,很高兴大家可以看到这篇文章,是我的荣幸,我的QQ是22700801。微信号是15060080040,欢迎加我,赞我。
之前有使用过trello,想找个替代的,然后就百度发现了taiga,于是就打算搭建一个环境。
偶然发现一个很不错的新选择:Taiga,于是就试着将其部署下来,发现绝对是一个好东西,对于实践 Scrum 项目管理方法的,更是不可多得的利器!
产品官网:https://taiga.io/
GITHUB:https://github.com/taigaio
安装指南:http://taigaio.github.io/taiga-doc/dist/setup-production.html

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. 主机名,我们用的是 cly.com,注意把后面的 cly.com 换成我们自己的即可。
  3. 用户 taiga,这个我们需要事先创建好,并且赋予其 sudo 权限。
  4. system ram 请无视。
现在创建 taiga 用户:
adduser taiga
然后赋予其 sudo 权限:
sudo visudo# User privilege specificationroot    ALL=(ALL:ALL) ALL # 在这行后面加上 taiga    ALL=(ALL:ALL) ALLtaiga    ALL=(ALL:ALL) ALLsudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
安装python3.4:
sudo apt-get install python3.4
设置默认pyhotn版本:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
修改host文件:
1、修改hostssudo gedit /etc/hosts2、添加解析记录127.0.0.1  cly.com  #你自己的域名3、保存后重启网络sudo /etc/init.d/networking restart

3. 后台安装:

3.1. 安装依赖项

sudo apt-get install -y build-essential binutils-doc autoconf flex bison libjpeg-devsudo apt-get install -y libfreetype6-dev zlib1g-dev libzmq3-dev libgdbm-dev libncurses5-devsudo 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.3sudo apt-get install -y postgresql-doc-9.3 postgresql-server-dev-9.3# 创建数据库sudo -u postgres createuser taigasudo -u postgres createdb taiga -O taiga

3.3. 安装 python 环境

sudo apt-get install -y python3 python3-pip python-dev python3-dev python-pip virtualenvwrappersudo 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-backcd taiga-backgit checkout stable

创建 virtualenv taiga

mkvirtualenv -p /usr/bin/python3.4 taiga

安装 PyPI 依赖项

pip install -r requirements.txt
如果失败,可以尝试多试几次,我就遇到这种情况。
注意!在实际操作中这里的依赖项不全,因此如果跑步起来需要看日志看一下少了哪个库。

映射数据库和载入初始数据

python manage.py migrate --noinputpython manage.py loaddata initial_userpython manage.py loaddata initial_project_templatespython manage.py loaddata initial_rolepython 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 = FalseTEMPLATE_DEBUG = FalsePUBLIC_REGISTER_ENABLED = TrueDEFAULT_FROM_EMAIL = "22700801@qq.com"#SERVER_EMAIL = DEFAULT_FROM_EMAIL# Uncomment and populate with proper connection parameters# for enable email sending. EMAIL_HOST_USER should end by @domain.tldEMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"EMAIL_USE_TLS = TrueEMAIL_HOST = "smtp.qq.com"EMAIL_HOST_USER = "22700801@qq.com"EMAIL_HOST_PASSWORD = "xiafnkbhib"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 taigapython manage.py runserver 
好了之后,可以通过 http://localhost:8000/api/v1/ 访问接口


4. 前端部署

由于是静态页面,部署比较简单,基本无意外。

下载代码

cd ~git clone https://github.com/taigaio/taiga-front-dist.git taiga-front-distcd taiga-front-distgit 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. 最终章(HTTP 和 WSGI 部署)

我们使用 Circus 做进程守护,Gunicorn 做 WSGI 容器,然后通过 Nginx 对外提供 HTTP 服务。

5.1. Circus 和 Gunicorn

安装部件,注意 Circus 需要使用 pip2 安装。
sudo pip2 install circus

Circus 基础配置 ~/circus.ini

按照原版配置基本无需修改
[circus]check_delay = 5endpoint = tcp://127.0.0.1:5555pubsub_endpoint = tcp://127.0.0.1:5556statsd = true[watcher:taiga]working_dir = /home/taiga/taiga-backcmd = gunicornargs = -w 3 -t 60 --pythonpath=. -b 127.0.0.1:8001 taiga.wsgiuid = taiganumprocesses = 1autostart = truesend_hup = truestdout_stream.class = FileStreamstdout_stream.filename = /home/taiga/logs/gunicorn.stdout.logstdout_stream.max_bytes = 10485760stdout_stream.backup_count = 4stderr_stream.class = FileStreamstderr_stream.filename = /home/taiga/logs/gunicorn.stderr.logstderr_stream.max_bytes = 10485760stderr_stream.backup_count = 4[env:taiga]PATH = /home/taiga/.virtualenvs/taiga/bin:$PATHTERM=rxvt-256colorSHELL=/bin/bashUSER=taigaLANG=en_US.UTF-8HOME=/home/taigaPYTHONPATH=/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=lostop on runlevel [016]respawnexec /usr/local/bin/circusd /home/taiga/circus.ini
注意 circus.ini 的路径如果不在这个地方需要对应修改。
然后就可以启动服务了。

5.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;    }}
禁用默认的Nginx的网站(虚拟主机)
sudo rm /etc/nginx/sites-enabled/default
使用新建立的Nginx的网站(虚拟主机)

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

sudo nginx -t
启动nginx服务

sudo service nginx restart
运行属于你自己的taiga

浏览器打开 http://cly.com/
加入简体中文
设置gravatar地址,修改taiga-back/taiga/users/gravatar.py,将GRAVATAR_BASE_URL = "//www.gravatar.com/avatar/{}?{}"改为GRAVATAR_BASE_URL = "https://secure.gravatar.com/avatar/{}?{}"然后汉化前端:将taiga-back/settings/common.py的154行取消注释将locale-zh-hans.json 拷贝到 taiga-front-dist/dist/v-1463480691365/locales/taiga/目录下
(完)



1 0
原创粉丝点击