如何安装和配置在Ubuntu 14.04 gitlab

0、安装准备

gitlab提供。deb包里面包含gitlab社区版和它的依赖性(Ruby, PostgreSQL, Redis, Nginx, Unicorn and other gems)已经编译。安装此包很简单。但因为它将安装本身的软件包的依赖关系(nginx,PostgreSQL,等)node

系统使用了Ubuntu 14.04,假如的你域名为git.example.com 而且已经安装ruby,git servermysql

本文使用的是非root权限 须要使用sudo 进行管理
nginx

    0.一、更新系统

            

sudo apt-get update
sudo apt-get upgrade

    0.二、为GitLab建立一个git用户

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

    0.三、插入系统依赖的包

sudo apt-get install build-essential cmake 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

    0.四、安装git、postfix(邮件服务器可选)

sudo apt-get install git postfix

    0.五、安装postgresql数据库等工具类、建立gitlab的生产库

sudo apt-get install postgresql postgresql-client libpq-dev
sudo -u postgres createuser --createdb git
sudo -u postgres createdb --owner=git gitlabhq_production

    0.六、检测生产库是否安装

sudo -u git -H psql -d gitlabhq_production -c "SELECT VERSION()

一、安装gitlab(使用源码安装)

    1.一、建立git目录、clone

mkdir /home/git && cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-9-stable gitlab
cd gitlab

    1.二、配置gitlab.conf

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo nano config/gitlab.yml

    1.三、编辑gitlab.yml

vim /home/git/gitlab/config/gitlab.yml
###################################
production: &base
  gitlab:
    host: git.example.com 
    port: 80
    https: false
    ...
    email_from: gitlab@example.com
    ...
    support_email: support@example.com
###################################

    1.四、授予权限给git,建立git存储目录

sudo chown -R git {log,tmp}
sudo chmod -R u+rwX {log,tmp,tmp/pids,tmp/sockets,public/uploads}
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites

    1.五、建立Unicorn, Rack attack, and PostgreSQL的配置文件

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git cp config/database.yml.postgresql config/database.yml
sudo -u git -H chmod o-rwx config/database.yml

    1.六、安装gems、gitlab-shell

sudo gem install bundler
sudo -u git -H bundle install --deployment --without development test mysql aws
sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.4] REDIS_URL=redis://localhost:6379 RAILS_ENV=production

    1.七、配置以下   vim /home/git/gitlab-shell/config.yml

user: git
gitlab_url: http://git.example.com/
http_settings:
  self_signed_cert: false
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
  bin: "/usr/bin/redis-cli"
  host: localhost
  port: 6379
  namespace: resque:gitlab
log_level: INFO
audit_usernames: false

    1.八、数据库初始化

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

    1.九、检测应用状态

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

    显示以下信息 表示系统正常
git

System information
System:Ubuntu 14.04
Current User:git
Using RVM:no
Ruby Version:2.1.2p95
Gem Version:2.2.2
Bundler Version:1.10.6
Rake Version:10.3.1
Sidekiq Version:2.17.0
GitLab information
Version:6.9.2
Revision:e46b644
Directory:/home/git/gitlab
DB Adapter:postgresql
URL:http://git.3nchina.cn
HTTP Clone URL:http://git.3nchina.cn/some-project.git
SSH Clone URL:ssh://git@git.3nchina.cn:2203/some-project.git
Using LDAP:no
Using Omniauth:no
GitLab Shell
Version:1.9.4
Repositories:/home/git/repositories/
Hooks:/home/git/gitlab-shell/hooks/
Git:/usr/bin/git

二、配置生产环境、git用户信息

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@example.com"
sudo -u git -H git config --global core.autocrlf input

三、启动、中止、重启gitlab

sudo service gitlab start
sudo service gitlab stop
sudo service gitlab restart

四、集成nginx 

sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo vim /etc/nginx/sites-available/gitlab

#eg
listen 80;
server_name git.example.com;
server_tokens off; 
root /home/git/gitlab/public;

    4.一、重启nginx 

 sudo rm /etc/nginx/sites-enabled/default
 sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
 sudo service nginx restart

五、检测gitlab是否正常

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

https://www.linode.com/docs/applications/development/how-to-install-and-configure-gitlab-on-ubuntu-14-04-trusty-tahrredis

相关文章
相关标签/搜索