CentOS6.5 安裝gitlab以及gitolite遷移gitlab

CentOS6.5 安裝gitlab以及gitolite遷移gitlab

gitlab 的安裝使用以及數據結構

安裝

環境:html

  • CentOS6.5
  • 基於 nignx + unicorn 搭建的應用環境, 若是想要換成passenger,能夠參考網上的文檔
  • ruby環境是基於rbenv搭建的

1: install vim

yum install -y vimjava

2: install git > 1.7.10

  • install git
$ rpm -i 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
$ rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

$ vim /etc/yum.repos.d/rpmforge.repo  
# 將[rpmforge-extras] 下的enabled = 0 => enabled = 1

$ yum install -y git
$ git --version

git version 1.7.12.4

$ yum clean all

reference: http://tecadmin.net/how-to-upgrade-git-version-1-7-10-on-centos-6/#mysql

  • git config
git config --global user.name 'jerry'
git config --global user.email 'jerrery520@gmail.com'
git config --global color.branch 'auto'
git config --global color.diff 'auto'
git config --global color.interactive 'auto'
git config --global color.interactive 'auto'
git config --global core.editor '/usr/bin/vim'

3: install dependent rpm

  • first: replace yum repo
rpm -Uvh http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
  • second: install
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml libyaml-devel libffi libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel git-core libxml libxml-devel libxslt libxslt-devel wget pcre-devel openssl openssl-devel tcl tcl-devel libaio-devel ntpdate libicu-devel

4: install rbenv && Ruby

  • add users: git
adduser --comment 'GitLab' --create-home --home-dir /home/git git
  • use rbenv-installer install rbenv
cd /home/git/

sudo -u git sh -c "curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer > rbenv-installer"

su - git -c '/bin/bash rbenv-installer'

sudo -u git -H echo '
export RBENV_ROOT="${HOME}/.rbenv"

if [ -d "${RBENV_ROOT}" ]; then
  export PATH="${RBENV_ROOT}/bin:${PATH}"
  eval "$(rbenv init -)"
fi
' >> /home/git/.bashrc
  • install Ruby
su - git -c 'rbenv install 2.0.0-p353'
su - git -c 'rbenv global 2.0.0-p353'
  • install bundler
su - git -c 'gem install bundler --no-ri --no-rdoc'

5: install gitlab

  • install gitlab shell
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git

cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml
# 注:將下面的 your_git_domain替換成你的域名
sudo -u git -H sed -i 's/localhost/your_git_domain/g' config.yml
su - git -c '/home/git/gitlab-shell/bin/install'
  • install mysql, redis, nginx

refer: http://blog.58share.com/?p=291linux

  • install gitlab
cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-6-stable gitlab

cd /home/git/gitlab

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
# If you installed Git from source, change the git bin_path to /usr/local/bin/git
# 這裏修改host(域名), email_from: (郵件), support_email(郵件)
sudo -u git -H vim config/gitlab.yml

chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX  tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
chmod -R u+rwX  tmp/pids/
chmod -R u+rwX  tmp/sockets/
sudo -u git -H mkdir public/uploads
chmod -R u+rwX  public/uploads

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# Ex. change amount of workers to 3 for 2GB RAM server
sudo -u git -H vim config/unicorn.rb

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "jerrery520@gmail.com"
sudo -u git -H git config --global core.autocrlf input

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

# 修改配置文件 config/database.yml
  • install gem
su - git
cd /home/git/gitlab

# NOTES: RAM must be > 512M if your mysql on

bundle install --deployment --without development test postgres aws

# 確認數據庫配置正確
# 建立數據庫
bundle exec rake db:create RAILS_ENV=production

# 初始化gitlab數據 NOTES: need redis
bundle exec rake gitlab:setup RAILS_ENV=production
# 這裏會執行清空數據庫的操做,第一次請輸入 yes

# install script

cp lib/support/init.d/gitlab /etc/init.d/gitlab
  • start server
/etc/init.d/gitlab start
  • check env
# 檢測gitlab執行的環境
bundle exec rake gitlab:env:info RAILS_ENV=production

# 檢測gitlab所依賴的東西
bundle exec rake gitlab:check RAILS_ENV=production
  • 編譯靜態文件配置nginx配置
# 編譯靜態文件
bundle exec rake assets:precompile RAILS_ENV=production

# 配置nginx
# 注意: nginx的配置的用戶爲 git 

cp lib/support/nginx/gitlab /usr/local/nginx/conf/conf.d/gitlab.conf
  • 綁定host
vim /etc/hosts

127.0.0.1 your_domain
  • 部署成功
按照上面的部署:最終部署成功後: 訪問域名

# that's all
# username: admin@local.host
# password: 5iveL!fe

# 第一次進入後,須要重設密碼,設置成功後部署成功
  • 安裝文檔refer:

http://www.digitalsanctuary.com/tech-blog/general/installing-gitlab-on-redhat-enterprise-5-rhel-5.htmlnginx

https://gitlab.com/gitlab-org/gitlab-ce/blob/6-6-stable/doc/install/installation.mdc++

將gitolite遷移到gitlab步驟

1. 初始化mysql 配置

bundle exec rake gitlab:setup RAILS_ENV=productiongit

初始化後:便可以登錄超級管理員帳戶:github

username: admin@local.host 
password: 5iveL!fe

2. 將現有的項目導入到gitlab中

bundle exec rake gitlab:import:repos RAILS_ENV=productionredis

3. 獲取root的api密鑰token 並寫如客戶端配置並執行api相關操做

  • 建立用戶並塞入對應的 ssh-key, 新建立的用戶無建立分組的權限。
  • 獲取已經建立的 分組, 並根據分組,將用戶寫入不一樣的分組中
  • 將admin 管理員加入全部的分組中, 手動將對應的用戶設置爲管理員,並容許建立分組
  • 有郵箱的用戶操做,涉及到線上數據庫的更新,線上測試機器的拉取,手動建立虛擬用戶並添加對應的權限
    線下機器是沒有push權限的,設置爲Reporter
  • 合併人員須要設置爲master 針對該項目
  • 管理員帳戶,並修改他們對應的權限控制以及建立的項目數

4. 寫腳本將全部經過api建立的用戶的確認狀態修改成已確認狀態,並在項目下執行操做

$ vim lib/task/gitlab/user.rakesql

namespace :gitlab do
  desc "Update all users'confirmed is true"
  task :update_confirmed => :environment do.
     User.find_each do |user|
       user.confirmation_token = nil
       user.confirmed_at = Time.now
       user.save
     end
  end
end

執行操做

bundle exec rake gitlab:updateconfirmed RAILSENV=production

其餘的相關配置

  • 配置smtp 郵件服務

cd /home/git/gitlab

$ vim config/environments/production.rb

  config.action_mailer.delivery_method       = :smtp
  config.action_mailer.perform_deliveries    = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
    :address              => 'smtp.exmail.qq.com',
    :port                 => 465,
    :domain               => 'qq.com',
    :user_name            => 'email_address',
    :password             => 'password',
    :authentication       =>  :plain,
    :enable_starttls_auto => true
  }
  • 配置ldap

cd /home/git/gitlab

$ vim config/gitlab.yml

  ldap:
    enabled: true
    host: your_ldap_host
    base: 'ou=Accounts,dc=domain,dc=com'
    port: your_port
    uid: 'uid'
    method: 'plain' # "tls" or "ssl" or "plain"
    bind_dn: 'cn=binder,dc=domain,dc=com'
    password: 'your_password'
    allow_username_or_email_login: true  # 是否容許使用username或者email登錄,設置爲false,登錄入口只會顯示ldap入口

NOTES: 遷移項目遇到的坑

1. 經過接口獲取用戶數據,默認只能獲取20條, 能夠分頁,每頁最多100條數據

2. 經過接口獲取項目,默認只能獲取20條

3. 若是是遷移項目,若之前的git項目是有多層級接口,須要修正爲一層,好比 java/abc/aaa.git => java/abc_aaa.git, 由於gitlab是不支持多層級結構的

4. 項目建立中有些帶有關鍵字的項目是不能建立成功的,好比 java/admin.git , ruby/services.git

5. gitlab clone項目不管是ssh, http 都會調用http請求,經過http請求判斷用戶的權限等操做。而咱們的http請求是作了ldap訪問權限設置的,所以須要對將本機(gitlab服務器)的IP加入ldap的白名單中

相關命令參考

  • 將現有的項目導入到gitlab中去
bundle exec rake gitlab:import:repos RAILS_ENV=production

* 添加全部的用戶到全部的分組中(admin的角色是owner)

bundle exec rake gitlab:import:all_users_to_all_groups RAILS_ENV=production

* 添加全部的用戶到全部的項目中(admin的角色是master)

bundle exec rake gitlab:import:all_users_to_all_projects RAILS_ENV=production

* 添加一個特殊的用戶到全部的分組中(角色爲developer)

bundle exec rake gitlab:import:user_to_groups[email] RAILS_ENV=production

* 添加一個特殊的用戶到全部的項目中(角色爲developer)

bundle exec rake gitlab:import:user_to_projects[email] RAILS_ENV=production

## gitlab 其餘相關參考 #### API相關 若是gitlab中有你的公鑰,你就能夠經過authentication_token來調用api

curl --header "PRIVATE-TOKEN: ArTMXVSWjFEYn9DQrL7f" "http://git.tuan800-inc.com/api/v3/user/keys"

gitlab api gem

refere: https://github.com/NARKOZ/gitlab

問題: 這個gem包的接口是v2的,可是gitlab 如今穩定版的是 V3了,可是部分功能能用,有些接口中描述的功能是須要本身去寫的

other helps

refer:http://mrk1869.com/blog/gitlab_installation/

git升級解決方案

How to Upgrade Git version >= 1.7.10 on CentOS 6

refer:http://tecadmin.net/how-to-upgrade-git-version-1-7-10-on-centos-6/#

git clone項目時報無環境變量

refer:http://thoughtpointers.net/2013/04/18/using-rbenv-with-gitlab-shell-on-os-x/

git push error

test [master] % ggpush
Counting objects: 3, done.
Writing objects: 100% (3/3), 229 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: GitLab: An unexpected error occurred (redis-cli returned 127).
remote: error: hook declined to update refs/heads/master
To git@git.58share.com:huhongda/test.git
 ! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'git@git.58share.com:huhongda/test.git'

解決: 修改 gitlab-shell/config/gitlab.yml 中的redis-cli 的路徑爲正確的路徑

#### 檢測gitlab運行環境是否正確

bundle exec rake gitlab:check RAILS_ENV=production

#### errors

All migrations up? ... rake aborted!
Cannot allocate memory - git log --pretty=format:'%h' -n 1
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/home/git/gitlab/config/initializers/2_app.rb:3:in `'
/home/git/gitlab/config/initializers/2_app.rb:1:in `'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `block in load'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/engine.rb:609:in `block (2 levels) in '
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/engine.rb:608:in `each'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/engine.rb:608:in `block in '
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:30:in `instance_exec'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:30:in `run'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:44:in `each'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:44:in `tsort_each_child'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:54:in `run_initializers'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:215:in `initialize!'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/git/gitlab/config/environment.rb:5:in `'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `block in require'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:189:in `require_environment!'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:250:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate:status => environment
(See full trace by running task with --trace)

解決: 是因爲缺乏內存致使的,若是用的是vps的話,用free -m 看看是不是內存太少,或者是沒有使用swap內存,若是沒有swap,須要加swap,通常是內存的1倍或者1.5倍

# 加swap

mkdir -p /data/swapdir
cd /data/swapdir

dd if=/dev/zero of=swapfile bs=1024  count=1024000

mkswap /data/swapdir/swapfile

swapon swapfile  # 開啓swap

swapoff swapfile # 關閉swap

# 能夠使用free -m 查看內存狀況

# 加入開啓重啓

echo '/data/swapdir/swapfile  swap  swap defaults 0 0' >> /etc/fstab

Reference

http://mrk1869.com/blog/gitlab_installation/ http://www.digitalsanctuary.com/tech-blog/general/installing-gitlab-on-redhat-enterprise-5-rhel-5.html https://gitlab.com/gitlab-org/gitlab-ce/blob/6-6-stable/doc/install/installation.md http://git.58share.com/help/api/README

this is a project for gitlab api

https://github.com/NARKOZ/gitlab

https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/groups.md

 

This entry was posted in gitlinux

Leave a Reply

相關文章
相關標籤/搜索