Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

公司原本用 SVN 做版本管理,但集中式代碼庫不支持離線提交,後來遷到 Git。Git 是分布式架構,用戶脫離伺服器也能在本地查看、編寫與提交,但缺少 Web 界面,於是選用了 GitLab——一款用 Ruby on Rails 寫的開源項目管理程序,可透過瀏覽器管理項目、用戶與 SSH Key,也能直接瀏覽與修改源碼。官方文檔支援 Debian/Ubuntu,以下在我的 Ubuntu 12.04.2 上實作。

1. 建立數據庫並授權

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 'gitlab'@'192.168.1.230' identified by 'gitlab!@#';

接著配置 config/database.yml(由 database.yml.mysql 複製而來),填好 adapter、encoding、database、username、password 與 host,然後初始化:

sudo -u git -H chmod o-rwx config/database.yml
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

2. 預設帳號

安裝完成後的預設帳號是 admin@local.host,密碼 5iveL!fe,首次登入必須改密碼。

3. 郵件通知

建立帳號、添加 SSH Key 都會發信,因此要改兩處:全局配置文件 git/.gitconfig 中的 email(gitlab 發信地址),以及 gitlab/config/environments/production.rb 中的 SMTP 設置。

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

4. 配置 URL 與 Nginx

sudo cp gitlab/lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# 編輯 server 段,設定 listen 與 server_name

5. 修改倉庫存儲路徑

預設在 /home/git/repositories,可改到 gitlab-shell/config.yml 的 repos_path(該路徑不可為符號鏈接):

repos_path: "/data/gitlab/repositories"

6~11. 日常使用

登入後在 Profile 中改密碼、設置通知(Notifications)、添加 SSH Key 與調整界面風格。

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

新建項目等同 git init --bare,可設為 Public 讓任何人瀏覽。

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

在 SourceTree 的 Settings 中添加 gitlab 的 remote origin,再推送即可。

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

Public 項目不登入也能瀏覽:

GitLab 在 Ubuntu 12.04.2 上的安裝與配置實錄

踩坑總結

搭建完成後 clone 若出現 RPC failed; result=22, HTTP code = 411,這是因為推送數據超過 Git 的 post buffer(預設 1 MB)。在 nginx 配置的 http 段加上 client_max_body_size 500m; 即可。

原文出自「樸實的追夢者」博客:https://sfzhang88.blog.51cto.com/4995876/1323201

Copyright © Linux教程網 All Rights Reserved