gitlab安装手册官方修正版(转)

原文地址:http://www.itzhoulin.com/gitlab/


Installation

Select Version to Install

Make sure you view this installation guide from the branch (version) of GitLab you would like to install. In most cases this should be the highest numbered stable branch (example shown below).


If the highest number stable branch is unclear please check the GitLab Blog for installation guide links by version.

Overview

The GitLab installation consists of setting up the following components:

  1. Packages / Dependencies
  2. Ruby
  3. System Users
  4. Database
  5. GitLab
  6. Nginx


1. Packages / Dependencies

sudo is not installed on Debian by default. Make sure your system is
up-to-date and install it.

# run as root!
    apt-get update -y
    apt-get upgrade -y
    apt-get install sudo -y

# Install vim and set as default editor
    sudo apt-get install -y vim
    sudo update-alternatives --set editor /usr/bin/vim.basic

#Install the required packages (needed to compile Ruby and native extensions to Ruby gems):

sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils


#Make sure you have the right version of Git installed

# Install Git
    sudo apt-get install -y git-core

    # Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 2.0.0
    git --version
Is the system packaged Git too old? Remove it and compile from source.


 # Remove packaged Git
    sudo apt-get remove git-core

    # Install dependencies
    sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

    # Download and compile from source
    cd /tmp
    curl --progress https://www.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz | tar xz
    cd git-2.0.0/
    make prefix=/usr/local all

    # Install into /usr/local/bin
    sudo make prefix=/usr/local install

    # When editing config/gitlab.yml (Step 5), change the git bin_path to /usr/local/bin/git

 # Remove packaged Git
    sudo apt-get remove git-core

    # Install dependencies
    sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

    # Download and compile from source
    cd /tmp
    curl --progress https://www.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz | tar xz
    cd git-2.0.0/
    make prefix=/usr/local all

    # Install into /usr/local/bin
    sudo make prefix=/usr/local install

    # When editing config/gitlab.yml (Step 5), change the git bin_path to /usr/local/bin/git


Note: In order to receive mail notifications, make sure to install a mail server. By default, Debian is shipped with exim4 whereas Ubuntu does not ship with one. The recommended mail server is postfix and you can install it with:

    sudo apt-get install -y postfix

Then select ‘Internet Site’ and press enter to confirm the hostname.


2. Ruby

The use of ruby version managers such as RVM, rbenv orchruby with GitLab in production frequently leads to hard to diagnose problems. For example, GitLab Shell is called from OpenSSH and having a version manager can prevent pushing and pulling over SSH. Version managers are not supported and we stronly advise everyone to follow the instructions below to use a system ruby.

Remove the old Ruby 1.8 if present


sudo apt-get remove ruby1.8

Download Ruby and compile it:


    mkdir /tmp/ruby && cd /tmp/ruby
    curl --progress http://ruby.taobao.org/mirrors/ruby/ruby-2.1.2.tar.gz | tar xz
    cd ruby-2.1.2
    ./configure --disable-install-rdoc
    make
    sudo make install

Install the Bundler Gem:

sudo gem install bundler --no-ri --no-rdoc



3. System Users

Create a git user for Gitlab:

    sudo adduser --disabled-login --gecos 'GitLab' git

4. Database

We recommend using a PostgreSQL database. For MySQL check MySQL setup guide. Note: because we need to make use of extensions you need at least pgsql 9.1.



 # Install the database packages
    sudo apt-get install -y postgresql-9.1 postgresql-client libpq-dev

    # Login to PostgreSQL
    sudo -u postgres psql -d template1

    # Create a user for GitLab.
    template1=# CREATE USER git CREATEDB;

    # Create the GitLab production database & grant all privileges on database
    template1=# CREATE DATABASE gitlabhq_production OWNER git;

    # Quit the database session
    template1=# \q

    # Try connecting to the new database with the new user
    sudo -u git -H psql -d gitlabhq_production
    
    #修改git账户的密码,后面连接数据库的时候要用到
    alter user git with password 'new password' ;


5. GitLab

We’ll install GitLab into home directory of the user “git”


 cd /home/git

5.1 Clone the Source

 # Clone GitLab repository
    sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-1-stable gitlab

    # Go to gitlab dir
    cd /home/git/gitlab

 # Clone GitLab repository
    sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-1-stable gitlab

    # Go to gitlab dir
    cd /home/git/gitlab

5.2 Configure it

 cd /home/git/gitlab

    # Copy the example GitLab config
    sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

    # Make sure to change "localhost" to the fully-qualified domain name of your
    # host serving GitLab where necessary
    #
    # If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details.
    #
    # If you installed Git from source, change the git bin_path to /usr/local/bin/git
    sudo -u git -H editor config/gitlab.yml

    # Make sure GitLab can write to the log/ and tmp/ directories
    sudo chown -R git log/
    sudo chown -R git tmp/
    sudo chmod -R u+rwX log/
    sudo chmod -R u+rwX tmp/

    # Create directory for satellites
    sudo -u git -H mkdir /home/git/gitlab-satellites
    sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

    # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
    sudo chmod -R u+rwX tmp/pids/
    sudo chmod -R u+rwX tmp/sockets/

    # Make sure GitLab can write to the public/uploads/ directory
    sudo chmod -R u+rwX  public/uploads

    # Copy the example Unicorn config
    sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

    # Enable cluster mode if you expect to have a high load instance
    # Ex. change amount of workers to 3 for 2GB RAM server
    sudo -u git -H editor config/unicorn.rb

    # Copy the example Rack attack config
    sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

    # Configure Git global settings for git user, useful when editing via web
    # Edit user.email according to what is set in gitlab.yml
    sudo -u git -H git config --global user.name "GitLab"
    sudo -u git -H git config --global user.email "example@example.com"
    sudo -u git -H git config --global core.autocrlf input

5.3 Configure GitLab DB settings

# PostgreSQL only:
    sudo -u git cp config/database.yml.postgresql config/database.yml

    # MySQL only:
    sudo -u git cp config/database.yml.mysql config/database.yml

    # MySQL and remote PostgreSQL only:
    # Update username/password in config/database.yml.
    # You only need to adapt the production settings (first part).
    # If you followed the database guide then please do as follows:
    # Change 'secure password' with the value you have given to $password
    # You can keep the double quotes around the password
    sudo -u git -H editor config/database.yml

    # PostgreSQL and MySQL:
    # Make config/database.yml readable to git only
    sudo -u git -H chmod o-rwx config/database.yml



5.4 Install Gems

 #首先修改Ruby的源地址到ruby.taobao.org,官方托管再aws上的由于GFW太慢了
    gem source -r https://rubygems.org/
    gem source -a http://ruby.taobao.org/
    
    #安装bundle
    sudo gem install bundler --no-ri --no-rdoc
    #验证bundle的版本是否不小于1.5.2
    bundle --version
        
    #在执行bundle install前依然要修改bundle的源
    #编辑Gemfile,将第一行sources的值修改为http://ruby.taobao.org/
    sudo -u git -H editor Gemfile


    cd /home/git/gitlab

    # For PostgreSQL (note, the option says "without ... mysql")
    sudo -u git -H bundle install --deployment --without development test mysql aws

    # Or if you use MySQL (note, the option says "without ... postgres")
    sudo -u git -H bundle install --deployment --without development test postgres aws


5.5 Install GitLab shell

 # Go to the Gitlab installation folder:
    cd /home/git/
    #下载gitlab-shell源码
    sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git

    cd gitlab-shell

    #选取v1.9.7版本
    sudo git checkout v1.9.7 

     #生成配置文件
    sudo -u git -H cp config.yml.example config.yml

    #修改 gitlab-shell 配置文件:
    sudo -u git -H editor config.yml

    #如果只使用普通 HTTP 方式访问的话,只需设置 Gitlab 站点的 URL 即可:
注意这里的参考值写了端口,务必与后续配置nginx时候的端口(6.2)要一直

gitlab_url: "http://gitlab.yoursite.com/"

    安装 GitLab Shell
    sudo -u git -H ./bin/install

    # By default, the gitlab-shell config is generated from your main gitlab config.
    #
    # Note: When using GitLab with HTTPS please change the following:
    # - Provide paths to the certificates under `ca_file` and `ca_path` options.
    # - The `gitlab_url` option must point to the https endpoint of GitLab.
    # - In case you are using self signed certificate set `self_signed_cert` to `true`.
    # See #using-https for all necessary details.
    #
    # You can review (and modify) the gitlab-shell config as follows:



5.6 Initialize Database and Activate Advanced Features

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

    # Type 'yes' to create the database tables.

    # When done you see 'Administrator account created:'

5.7 Install Init Script

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

And if you are installing with a non-default folder or user copy and edit the defaults file:

sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab

If you installed gitlab in another directory or as a user other than the default you should change these settings in /etc/default/gitlab. Do not edit /etc/init.d/gitlab as it will be changed on upgrade.


Make GitLab start on boot:

sudo update-rc.d gitlab defaults 21


5.8 Set up logrotate

 sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

5.9 Check Application Status

Check if GitLab and its environment are configured correctly:

 sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

5.10 Compile assets

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

5.11 Start Your GitLab Instance

 sudo service gitlab start
    # or
    sudo /etc/init.d/gitlab restart

6. Nginx

Note: Nginx is the officially supported web server for GitLab. If you cannot or do not want to use Nginx as your web server, have a look at the GitLab recipes.


6.1 Installation

 sudo apt-get install -y nginx

6.2 Site Configuration

Copy the example site config:

sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab



Make sure to edit the config file to match your setup:

  # Change YOUR_SERVER_FQDN to the fully-qualified
  # domain name of your host serving GitLab.
  sudo editor /etc/nginx/sites-available/gitlab


Note: If you want to use https, replace the

gitlab

nginx config with

gitlab-ssl


6.3 Restart

sudo service nginx restart


Done!

Double-check Application Status

To make sure you didn’t miss anything run a more thorough check with:

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production


If all items are green, then congratulations on successfully installing GitLab!


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值