知识共享许可协议
本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议进行许可。

Redmine & GitLab On Debian

安装基础软件
  • 更新源

    vim /etc/apt/sources.list
    修改成 http://mirrors.sohu.org 的源
    
  • 增加 Passenger 的源

    vim  /etc/apt/sources.list.d/passenger.list
    deb https://oss-binaries.phusionpassenger.com/apt/passenger wheezy main
    
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
    
  • 安装 apt-transport-https

    apt-get install apt-transport-https
    
  • 更新

    apt-get update
    apt-get upgrade
    
  • 安装软件

    apt-get install sudo curl wget build-essential libcurl4-openssl-dev cmake vim zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libicu-dev logrotate libmagickwand-dev
    
安装Ruby
  • 安装rvm

    curl -L https://get.rvm.io | bash -s stable
    source /etc/profile.d/rvm.sh
    rvm -v
    
  • 安装Ruby

    rvm install 2.1.1
    rvm 2.1.1 --default
    ruby -v
    gem -v
    gem source -r https://rubygems.org/
    gem source -a http://ruby.taobao.org
    
  • 安装bunlder

    gem install bundler
    
  • 安装 Rails

    gem install rails
    rails -v
    
安装Node.js
  • 下载解压

    wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz
    tar zxvf node-v0.10.28.tar.gz
    cd node-v0.10.28
    
  • 配置编译安装

    ./configure
    make
    make install
    
安装Nginx & Passenger
  • 移除旧的nginx

    apt-get remove nginx nginx-full nginx-light nginx-naxsi nginx-common
    
  • 安装Passenger

    apt-get install nginx-extras passenger
    
  • 安装模块

    passenger-install-nginx-module
    
配置nginx
  • 配置 /etc/nginx/nginx.conf

    vim /etc/nginx/nginx.conf
    
    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby;
    
  • 配置 /etc/nginx/sites-enabled/default

    vim /etc/nginx/sites-enabled/default
    
    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        server_name _;
        return 444;
    }
    
安装MySQL
  • 下载解压

    wget http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/tarball/percona-server-5.6.17-65.0.tar.gz
    tar zxvf percona-server-5.6.17-65.0.tar.gz
    cd percona-server-5.6.17-65.0
    
  • 系统用户设置

    groupadd mysql && useradd -g mysql mysql && mkdir -p /opt/mysql && mkdir -p /data1/mysql && chown -R mysql:mysql /data1/mysql
    
  • cmake

    cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \
    -DMYSQL_UNIX_ADDR=/data1/mysql/mysql.sock \
    -DDEFAULT_CHARSET=gbk \
    -DDEFAULT_COLLATION=gbk_chinese_ci \
    -DWITH_EXTRA_CHARSETS:STRING=armscii8,ascii,big5,cp1250,cp1251,cp1256,cp1257,cp850,cp852,cp866,cp932,dec8,eucjpms,euckr,gb2312,gbk,geostd8,greek,hebrew,hp8,keybcs2,koi8r,koi8u,latin1,latin2,latin5,latin7,macce,macroman,sjis,swe7,tis620,ucs2,ujis,utf8 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_MEMORY_STORAGE_ENGINE=1 \
    -DWITH_READLINE=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DMYSQL_DATADIR=/data1/mysql \
    -DMYSQL_USER=mysql \
    -DMYSQL_TCP_PORT=3306   
    
  • 编译安装

    make && make install    
    
  • 安装开发包

    apt-get install libmysqlclient-dev libmysql-ruby
    
  • 设置启动脚本

    cp ./support-files/mysql.server /etc/init.d/mysqld && chmod 755 /etc/init.d/mysqld
    
  • 设置开机自动启动

    vim /etc/rc.local
    /etc/init.d/mysqld start
    
  • 生成配置信息

    https://tools.percona.com/wizard
    
  • 更新配置文件

    vim /etc/mysql/my.cnf
    
  • 初始化数据库

    chmod 755 ./scripts/mysql_install_db && ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/data1/mysql
    
  • 增加软链接

    ln -s /opt/mysql/bin/mysql /usr/bin/mysql
    
  • 启动

    service mysqld start
    
  • 修改密码

    /opt/mysql/bin/mysqladmin -u root password '123123'
    
  • 重启

    service mysqld restart
    
安装 Redmine
  • 下载解压

    wget http://www.redmine.org/releases/redmine-2.5.1.tar.gz
    mkdir -p /data0
    tar zxvf redmine-2.5.1.tar.gz -C /data0
    cd /data0/redmine-2.5.1
    
  • 创建数据库

    mysql -uroot -p
    create database redmine character set utf8;
    
  • 配置

    cp config/database.yml.example config/database.yml
    vim config/database.yml
    
    production:
      adapter: mysql2
      database: redmine
      host: localhost
      username: redmine
      password: 123123
      encoding: utf8
    
  • 安装gems

    bundle install --without development test
    
  • 生成token

    rake generate_secret_token
    
  • 设置 RAILS_ENV

    export RAILS_ENV=production 
    
  • 生成数据库信息

    rake db:migrate
    
  • 配置Nginx

    cd /etc/nginx/sites-enabled
    touch redmine.conf
    vim redmine.conf
    
    server {
        listen  8080;
        server_name _;
        root /data0/redmine-2.5.1/public;
        passenger_enabled on;
        client_max_body_size      10m; 
    }
    
  • 默认管理员账号密码

    user: admin
    password: admin
    
安装 Git
  • 安装

    apt-get install -y git-core
    
  • 检查版本是不是 1.7 以上

    git --version 
    
增加系统用户
    adduser --disabled-login --gecos 'GitLab' git
GitLab 数据库设置
  • 创建

    mysql -uroot -p
    
    CREATE USER 'git'@'localhost' IDENTIFIED BY '123123';
    SET storage_engine=INNODB;
    CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
    GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
    \q
    
  • 测试

    mysql -u git -p -D gitlabhq_production
    
安装GitLab
  • 复制源码

    cd /home/git
    git clone https://gitlab.com/gitlab-org/gitlab-ce.git
    mv ./gitlab-ce ./gitlab     
    
  • 配置

    cd /home/git/gitlab
    cp config/gitlab.yml.example config/gitlab.yml
    
    vim config/gitlab.yml
    bin_path: /usr/bin/git
    host: 10.211.55.35
    port: 8081
    https: false
    user: root
    
    chown -R git log/
    chown -R git tmp/
    chmod -R u+rwX log/
    chmod -R u+rwX tmp/
    
    mkdir /home/git/gitlab-satellites
    chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
    chmod -R u+rwX tmp/pids/
    chmod -R u+rwX tmp/sockets/
    chmod -R u+rwX  public/uploads
    
    cp config/unicorn.rb.example config/unicorn.rb
    vim config/unicorn.rb
    worker_processes 3
    
    cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
    
    git config --global user.name "nate"
    git config --global user.email "nate@yhz.me"
    git config --global core.autocrlf input
    
  • 数据库配置修改

    cp config/database.yml.mysql config/database.yml
    vim config/database.yml
    
    production:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: gitlabhq_production
      pool: 10
      username: git
      password: "123123"
    
    chmod o-rwx config/database.yml
    
  • 安装Gems

    bundle install --deployment --without development test postgres aws
    
  • 安装 GitLab shell

    cd /home/git/gitlab
    bundle exec rake gitlab:shell:install[v1.9.4] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
    vim /home/git/gitlab-shell/config.yml
    
  • 安装 Init Script

    cp lib/support/init.d/gitlab /etc/init.d/gitlab
    cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
    
  • 初始化数据

    bundle exec rake gitlab:setup RAILS_ENV=production
    
  • 设置开机启动

    update-rc.d gitlab defaults 21
    
  • 设置 logrotate

    cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
    
  • 检查状态

    bundle exec rake gitlab:env:info RAILS_ENV=production
    
  • 编译 assets

    bundle exec rake assets:precompile RAILS_ENV=production
    
  • 启动

    service gitlab start
    
  • 配置nginx

    cp *    编译 assets
    
    bundle exec rake assets:precompile RAIL
    ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
    vim /etc/nginx/sites-available/gitlab
    
  • 重启nginx

    service nginx restart
    
  • 初始化用户名和密码

    user: root
    password: 5iveL!fe
    
相关错误及解决办法
  • Can't install RMagick 2.13.2. Can't find Magick-config

    apt-get install libmagickwand-dev
    
  • Rails Error: Unable to access log file. Please ensure that /home/git/gitlab/log/production.log exists and is chmod 0666

    chmod 0666 /home/git/gitlab/log/production.log
    
  • Permission denied @ rb_sysopen - /home/git/gitlab/config/database.yml

    chmod -R 777 /home/git/gitlab
    
  • Permission denied @ rb_sysopen - /home/git/gitlab-shell/gitlab-shell.log

    chmod -R 777 /home/git/gitlab-shell
    
  • Permission denied @ dir_s_mkdir - /home/git/repositories/root (Errno::EACCES)

    chmod -R 777 /home/git/repositories
    
  • Could not find rake-10.3.1 in any of the sources (Bundler::GemNotFound)