• 项目管理系统 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 部署手札】

  • 相关阅读:
    datagrid与webAPI的数据交互(ef mvc )
    ASP.Net MVC数据传递
    dagride实现模糊查询
    MVC三层架构搭建
    web实现下拉列表多选加搜索
    php入门
    mysql实现简单的增删改查,放入xmapp自带数据库中
    ghithub中PHPOffice/PHPWord的学习
    移动端一像素问题
    点击按钮返回顶部
  • 原文地址:https://www.cnblogs.com/KyleLi/p/7402619.html
Copyright © 2020-2023  润新知