GitLab 部署

jopen 8年前

GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。 它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

GitLab安装指引包括以下内容:

  1. 包及依赖

  2. Ruby

  3. 系统用户

  4. GitLab shell

  5. 数据库

  6. GitLab

  7. Nginx

 

1  包及依赖

 1.1    确认系统更新到最新

root@debian:~# apt-get -y update  root@debian:~# apt-get -y upgrade  root@debian:~# apt-get install sudo  #后面githab启动脚本需要用到

 1.2   安装相关依赖包

root@debian:~# 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版本,2.5+ (3.0+还没支持)

root@debian:~# python --version  Python 2.7.3


 1.3 确保git版本 1.7.10 + ,如 1.7.12 or 1.8.4

  删除原有git   

root@debian:~# apt-get remove git-core

  安装依赖

root@debian:~# apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

  下载编译源码 1.8.5.2

root@debian:~# cd /tmp  root@debian:tmp# curl --progress https://git-core.googlecode.com/files/git-1.8.5.2.tar.gz | tar xz  root@debian:tmp# cd git-1.8.5.2/  root@debian:git-1.8.5.2# make prefix=/usr/local all  root@debian:git-1.8.5.2# make prefix=/usr/local install  #安装到 /usr/local/bin

       注意:当编辑config/gitlab.yml 时(在步骤6), 修改 git bin_path 为 /usr/local/bin/git


提示: 为了收取通知邮件,您需要安装邮件服务。默认的,Debian已随带exim4服务,但Ubuntu没有。推荐的邮件服务是Postfix,

apt-get install -y postfix,然后,选择'Internet Site',按回车确认主机名。

2. RUBY 

   2.1  如果系统已存在Ruby1.8,删除它:

root@debian:git-1.8.5.2# apt-get remove ruby1.8

   2.2 下载编译ruby

root@debian:tmp# mkdir /tmp/ruby && cd /tmp/ruby  root@debian:tmp# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz  root@debian:tmp# cd ruby-2.0.0-p353  root@debian:tmp# ./configure --disable-install-rdoc  root@debian:tmp# make  root@debian:tmp# make install

  2.3 安装bundler ,一个安装ruby的包系统 ,用bundler管理gem

root@debian:ruby-2.0.0-p353# gem install bundler --no-ri --no-rdoc  Fetching: bundler-1.6.1.gem (100%)  Successfully installed bundler-1.6.1  1 gem installed

  有可能执行卡主,天朝经常哈,   可以参见http://ruby.taobao.org/

3  系统用户

root@debian:~# adduser --disabled-login --gecos 'GitLab' git

4  GitLab shell

root@debian:~# su - git  root@debian:~# cd /home/git  git@debian:~$ git clone https://github.com/gitlabhq/gitlab-shell.git  git@debian:~$ cd gitlab-shell/  git@debian:~/gitlab-shell$ cp config.yml.example config.yml  git@debian:~/gitlab-shell$ vim config.yml  # 更改 gitlab_url: "http://gitlab.test.com/"  git@debian:~/gitlab-shell$ ./bin/install

 5  安装数据库

   设置/etc/mysql/my.cnf 监听本地ip 端口

root@debian:~# apt-get install -y mysql-server mysql-client libmysqlclient-dev    设置数据库  root@debian:~# mysql -uroot -p  mysql> GRANT USAGE ON *.* TO 'gitlab'@'localhost' IDENTIFIED BY 'git';  #创建用户密码  mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;  mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

6  GitLab

  6.1切回git用户

root@debian:~# su - git

  6.2克隆gitlab源码

git@debian:~$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab  git@debian:~$ cd gitlab  git@debian:~/gitlab$ git checkout 6-7-stable  Branch 6-7-stable set up to track remote branch 6-7-stable from origin.  Switched to a new branch '6-7-stable'

  6.3 配置git

git@debian:~$ cd /home/git/gitlab  git@debian:~/gitlab$ cp config/gitlab.yml.example config/gitlab.yml  git@debian:~/gitlab$ vim config/gitlab.yml   #if git source,change the git bin_path to /usr/local/bin/git                       #host 10.1.1.176                       #timeout 600                       #bin_path: /usr/local/bin/git    git@debian:~/gitlab$ chown -R git log/  git@debian:~/gitlab$ chown -R git tmp/  git@debian:~/gitlab$ chmod -R u+rxX log/  git@debian:~/gitlab$ chmod -R u+rxX tmp/  git@debian:~/gitlab$ mkdir /home/git/gitlab-satellites  git@debian:~/gitlab$ mkdir tmp/pids/  git@debian:~/gitlab$ mkdir tmp/sockets/  git@debian:~/gitlab$ chmod -R u+rwX tmp/pids/  git@debian:~/gitlab$ chmod -R u+rwX tmp/sockets/  git@debian:~/gitlab$ mkdir public/uploads  git@debian:~/gitlab$ chmod -R u+rwX public/uploads/  git@debian:~/gitlab$ cp config/unicorn.rb.example config/unicorn.rb  git@debian:~/gitlab$ vim config/unicorn.rb                       listen "10.1.1.176:8080", :tcp_nopush => true  #Configure Git global settings for git user, useful when editing via web  git@debian:~/gitlab$ git config --global user.name "GitLab"  git@debian:~/gitlab$ git config --global user.email "gitlab@localhost"  git@debian:~/gitlab$ git config --global core.autocrlf input  git@debian:~/gitlab$ cp config/database.yml.mysql config/database.yml  git@debian:~/gitlab$ vim config/database.yml  #数据库密码  只需修改production即可                       #  username: gitlab                       #  password: "git"                              #  host: localhost                       git@debian:~/gitlab$ cp config/resque.yml.example config/resque.yml  git@debian:~/gitlab$ vim config/resque.yml                       #  production: redis://10.1.1.176:6379    #更改redis 监听地址                 root@debian:~# vim /etc/redis/redis.conf                  #bind 10.1.1.176  root@debian:~# /etc/init.d/redis-server restart

  确保 gitlab.yml 和 unicorn.rb 配置正确   

 6.3 安装gems

git@debian:~/gitlab$ cd /home/git/gitlab  #更换Gemfile中的ruby源,加快包的安装速度      git@debian:~/gitlab$ vi Gemfile                           #source "http://ruby.taobao.org"                                               #初始化数据库激活高级特性  git@debian:~/gitlab$ bundle exec rake gitlab:setup RAILS_ENV=production  == Seed from /home/git/gitlab/db/fixtures/production/001_admin.rb  2014-04-07T17:30:53Z 9883 TID-oxc268p00 INFO: Sidekiq client with redis options {:url=>"redis://10.1.1.176:6379", :namespace=>"resque:gitlab"}    Administrator account created:    login.........admin@local.host  password......5iveL!fe                #出现以上表示Ok  #也有可能出现以下错误,继续执行.  rake aborted!  Mysql2::Error: Lost connection to MySQL server during query: INSERT INTO `schema_migrations` (version) VALUES ('20121220064453')

 6.4 安装启动脚本

git@debian:~/gitlab$ cd /home/git/gitlab      git@debian:~/gitlab$ cp lib/support/init.d/gitlab /etc/init.d/      git@debian:~/gitlab$ chmod +x /etc/init.d/gitlab    设置gitlab开机启动  root@debian:~# update-rc.d gitlab defaults 21

 6.5 设置logarate

root@debian:~# cd /home/git/gitlab  root@debian:gitlab# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

 6.6检查应用环境

root@debian:gitlab# su - git  git@debian:~$ cd gitlab  git@debian:~/gitlab$ bundle exec rake gitlab:env:info RAILS_ENV=production    System information  System:  Debian 7.4  Current User: git  Using RVM: no  Ruby Version: 2.0.0p353  Gem Version: 2.0.14  Bundler Version:1.6.1  Rake Version: 10.1.1    GitLab information  Version: 6.7.3  Revision: f88d30f  Directory: /home/git/gitlab  DB Adapter: mysql2  URL:  http://10.1.1.39  HTTP Clone URL: http://10.1.1.39/some-project.git  SSH Clone URL: git@10.1.1.39:some-project.git  Using LDAP: no  Using Omniauth: no    GitLab Shell  Version: 1.7.1  Repositories: /home/git/repositories/  Hooks:  /home/git/gitlab-shell/hooks/  Git:  /usr/local/bin/git    启动gitlab  /etc/init.d/gitlab restart  Starting both the GitLab Unicorn and Sidekiq.  The GitLab Unicorn web server with pid 10080 is running.  The GitLab Sidekiq job dispatcher with pid 10088 is running.  GitLab and all its components are up and running.

   6.7编译资源

git@debian:~/gitlab$ bundle exec rake gitlab:check RAILS_ENV=production  Checking Environment ...    Git configured for git user? ... yes    Checking Environment ... Finished    Checking GitLab Shell ...    GitLab Shell version >= 1.9.1 ? ... OK (1.9.3)  Repo base directory exists? ... yes  Repo base directory is a symlink? ... no  Repo base owned by git:git? ... yes  Repo base access is drwxrws---? ... yes  update hook up-to-date? ... yes  update hooks in repos are links: ... can't check, you have no projects  Running /home/git/gitlab-shell/bin/check  Check GitLab API access: /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `initialize': getaddrinfo: No address associated with hostname (SocketError)   from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `open'   from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'   from /usr/local/lib/ruby/2.0.0/timeout.rb:52:in `timeout'   from /usr/local/lib/ruby/2.0.0/net/http.rb:877:in `connect'   from /usr/local/lib/ruby/2.0.0/net/http.rb:862:in `do_start'   from /usr/local/lib/ruby/2.0.0/net/http.rb:851:in `start'   from /home/git/gitlab-shell/lib/gitlab_net.rb:76:in `get'   from /home/git/gitlab-shell/lib/gitlab_net.rb:43:in `check'   from /home/git/gitlab-shell/bin/check:11:in `<main>'  gitlab-shell self-check failed    Try fixing it:    Make sure GitLab is running;    Check the gitlab-shell configuration file:    sudo -u git -H editor /home/git/gitlab-shell/config.yml    Please fix the error above and rerun the checks.    如报以上错误,需要更改主机名/etc/hosts  root@debian:~# cat /etc/hosts  127.0.0.1 10.1.1.176  127.0.1.1       10.1.1.176      重新编译资源  git@debian:~/gitlab$ bundle exec rake gitlab:check RAILS_ENV=production    Checking Environment ...    Git configured for git user? ... yes    Checking Environment ... Finished    Checking GitLab Shell ...    GitLab Shell version >= 1.9.1 ? ... OK (1.9.3)  Repo base directory exists? ... yes  Repo base directory is a symlink? ... no  Repo base owned by git:git? ... yes  Repo base access is drwxrws---? ... yes  update hook up-to-date? ... yes  update hooks in repos are links: ... can't check, you have no projects  Running /home/git/gitlab-shell/bin/check  Check GitLab API access: OK  Check directories and files:    /home/git/repositories: OK   /home/git/.ssh/authorized_keys: OK  Test redis-cli executable: redis-cli 2.4.14  Send ping to redis server: PONG  gitlab-shell self-check successful    Checking GitLab Shell ... Finished    Checking Sidekiq ...    Running? ... yes  Number of Sidekiq processes ... 1    Checking Sidekiq ... Finished    Checking LDAP ...    LDAP is disabled in config/gitlab.yml    Checking LDAP ... Finished    Checking GitLab ...    Database config exists? ... yes  Database is SQLite ... no  All migrations up? ... yes  Database contains orphaned UsersGroups? ... no  GitLab config exists? ... yes  GitLab config outdated? ... no  Log directory writable? ... yes  Tmp directory writable? ... yes  Init script exists? ... yes  Init script up-to-date? ... yes  projects have namespace: ... can't check, you have no projects  Projects have satellites? ... can't check, you have no projects  Redis version >= 2.0.0? ... yes  Your git bin path is "/usr/local/bin/git"  Git version >= 1.7.10 ? ... yes (1.8.5)    Checking GitLab ... Finished

7  Nginx

root@debian:~#apt-get install -y nginx  root@debian:~#cd /home/git/gitlab  root@debian:gitlab# cp lib/support/nginx/gitlab /etc/nginx/sites-available/  root@debian:gitlab# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

   修改域名:

root@debian:gitlab# vim /etc/nginx/sites-enabled/gitlab                          server_name gitlab.test.com

  重启服务

root@debian:gitlab# /etc/init.d/nginx start  Starting nginx: nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32  nginx: configuration file /etc/nginx/nginx.conf test failed

    保存服务器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理器缓存大小的倍数。如果Nginx给出需要增大 hash max size 或 hash bucket size的提示,那么首要的是增大前一个参数的大小.

root@debian:gitlab# vim /etc/nginx/sites-enabled/gitlab   root@debian:gitlab# server_names_hash_bucket_size 64;  root@debian:gitlab# /etc/init.d/nginx restart

8 测试

   绑定域名并输入域名githab.test.com

     GitLab 部署


      GitLab 部署



参考:

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md