CI 系統搭建:三. Gerrit 的安裝配置


重新安裝 gerrit 需要特別注意:

  • 如果有項目在使用記得備份 /etc/gerrit/git 目錄
  • rm -fr /etc/gerrit
  • mysql -uroot -p
  • >>>drop database gerritdb;
  • >>>create database gerritdb;
  • 重新安裝吧。
  • 如果 /etc/gerrit/logs/error_log 里出現 java.lang.IllegalStateException: Missing project All-Projects 這個錯誤,那就重新安裝下,記得清除一下 db。

之前寫過兩篇文章,CI 系統搭建:一. 基礎環境設置、規划CI 系統搭建:二. GitLab 的安裝配置,本文主要記錄 Gerrit 的安裝的過程。

 

下載 Gerrit 包

目前最新版為 2.8

wget http://gerrit-releases.storage.googleapis.com/gerrit-2.8.war 

安裝 Gerrit 依賴

Gerrit 的包是 java 格式,需要安裝 jre

apt-get install default-jre daemon

創建 Gerrit 數據庫

上一篇再安裝 GitLab 時已經安裝了 Mysql,直接創建庫

sudo mysql -uroot -p
> create database gerritdb;
> grant all on gerritdb.* to 'gerrituser'@'localhost' identified by 'gerritpass';

開始安裝

把 gerrit 安裝再 /etc/gerrit/ 下

# java -jar gerrit-2.8.war init -d /etc/gerrit/

*** Gerrit Code Review 2.8
***

Create '/etc/gerrit'           [Y/n]? y

*** Git Repositories
***

Location of Git repositories   [git]:

*** SQL Database
***

Database server type           [h2]: mysql

Gerrit Code Review is not shipped with MySQL Connector/J 5.1.21
**  This library is required for your configuration. **
Download and install it now [Y/n]? y
Downloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar ... OK
Checksum mysql-connector-java-5.1.21.jar OK
Server hostname                [localhost]:
Server port                    [(mysql default)]:
Database name                  [reviewdb]: gerritdb
Database username              [root]: gerrituser
gerrituser's password          :
              confirm password :

*** User Authentication
***

Authentication method          [OPENID/?]: http
Get username from custom HTTP header [y/N]? n
SSO logout URL                 :

*** Email Delivery
***

SMTP server hostname           [localhost]: smtp.googlemail.com
SMTP server port               [(default)]: 587
SMTP encryption                [NONE/?]: tls
SMTP username                  [root]: gerrit@thstack.com
review@thstack.com's password  :
              confirm password :

*** Container Process
***

Run as                         [root]:
Java runtime                   [/usr/lib/jvm/java-6-openjdk-amd64/jre]:
Copy gerrit-2.8.war to /etc/gerrit/bin/gerrit.war [Y/n]? y
Copying gerrit-2.8.war to /etc/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:

Gerrit Code Review is not shipped with Bouncy Castle Crypto v144
  If available, Gerrit can take advantage of features
  in the library, but will also function without it.
Download and install it now [Y/n]? y
Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK
Checksum bcprov-jdk16-144.jar OK
Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon
***

Behind reverse proxy           [y/N]? y
Proxy uses SSL (https://)      [y/N]? n
Subdirectory on proxy server   [/]:
Listen on address              [*]:
Listen on port                 [8081]: 8082
Canonical URL                  [http://www.thstack.com/]: http://review.thstack.com/

*** Plugins
***

Install plugin reviewnotes version v2.8 [y/N]? y
Install plugin download-commands version v2.8 [y/N]? y
Install plugin replication version v2.8 [y/N]? y
Install plugin commit-message-length-validator version v2.8 [y/N]? y

Initialized /etc/gerrit
Executing /etc/gerrit/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on review.thstack.com:80 ... OK
Opening http://review.thstack.com/#/admin/projects/ ...FAILED
Open Gerrit with a JavaScript capable browser:

http://review.thstack.com/#/admin/projects/

在安裝完后 Gerrit 默認會打開瀏覽器,由於我的系統是 Server 版沒有桌面和瀏覽器,所以才會出現上面倒數第三行的 …FAILED 同時從上面的信息看出我使用了 http 方式驗證、啟用代理服務器,指定了 Gerrit 端口為 8082,URL 為 review.thstack.com。需要在 nginx 里設置下端口轉發。

Gerrit 啟動腳本

cp /etc/gerrit/bin/gerrit.sh /etc/init.d/gerrit
vim /etc/init.d/gerrit
GERRIT_SITE=/etc/gerrit/       # 在代碼 47 行增加
sudo update-rc.d gerrit defaults 21
service gerrit restart

Nginx

修改 Nginx 配置文件,給 Gerrit 做端口轉發和訪問控制,把下面內容寫入到文件最后

# vim /etc/nginx/sites-available/gitlab
server {
  listen *:80;
  server_name review.thstack.com;
  allow   all;
  deny    all;
  auth_basic "THSTACK INC. Review System Login";
  auth_basic_user_file /etc/gerrit/etc/htpasswd.conf;

  location / { 
    proxy_pass  http://review.thstack.com:8082;
  }   
}

創建 htpasswd.conf 文件,並添加 admin 用戶、密碼到文件中

# touch /etc/gerrit/etc/htpasswd.conf
# htpasswd /etc/gerrit/etc/htpasswd.conf admin
  New password: 
  Re-type new password: 
  Adding password for user admin

默認第一個登錄 Gerrit 的用戶是 Admin。

訪問

在瀏覽器 url 輸入:http://review.thstack.com/,記得添加 hosts 解析。由於做了訪問控制,會出現如下驗證框,輸入剛才創建的 admin 和密碼 gerrit-admin-access

注冊 admin 的郵箱,並添加 admin@thstack.com 密鑰 gerrit-admin-sshkey

使用 htpasswd 創建 longgeek 用戶和密碼

htpasswd /etc/gerrit/etc/htpasswd.conf longgeek

換個瀏覽器或清除下瀏覽器保存的 admin 的密碼 訪問 http://review.thstack.com/ 輸入 longgeek 和密碼: gerrit-longgeek-login

注冊郵箱和添加 longgeek@thstack.com 的密鑰 gerrit-longgeek-create-user

最后

如果想 Gitlab 上創建的項目使用 Gerrit 的 Code Review 功能,兩個系統的用戶必須統一,也就是說不管哪個用戶使用 Gerrit,前提是這個用戶在 Gitlab 和 Gerrit 上都已注冊,郵箱一致、sshkey 一致。當然 Nginx 訪問控制用戶的密碼那就隨意了。至於 Gitlab 上創建的項目如何同步到 Gerrit 上、Gitlab 如何使用 Gerrit 的 Code Review 功能等等都在 Jenkins 安裝完之后會一起整合在一起。請關注后面的文章。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM