Gerrit,一種免費、開放源代碼的代碼審查軟件,使用網(wǎng)頁界面。利用網(wǎng)頁瀏覽器,同一個團隊的軟件程序員,可以相互審閱彼此修改后的程序代碼,決定是否能夠提交,退回或者繼續(xù)修改。它使用Git作為底層版本控制系統(tǒng)。
引言
- 本文介紹如何搭建gerrit服務器,以及搭配LDAP認證的詳細流程。我以在云服務器 ESC (Elastic Compute Service)上搭建為例,ESC系統(tǒng)為 centos7.9。公網(wǎng)IP為121.51.39.239。
- 里面涉及到的密碼設置,可以自行選擇密碼配置,這里我統(tǒng)一設置為123123,避免搞混。
- 如果你清除 LDAP 服務器如何搭建,請參考我的博文 搭建LDAP服務器詳細流程,里面詳細介紹了LDAP 服務器的搭建流程。
資源包準備
- 有些資源在centos中無法通過
yum install
安裝,需要下載后手動安裝。 - 下面的下載鏈接中有個 Gerrit 資源壓縮包,需要提前下載準備好。
鏈接:https://pan.baidu.com/s/1KspZJGBzjXt0QIm3ITE2QQ?pwd=xofo 提取碼:xofo - 下載完成后,需要在Windows下解壓出來得到 gerrit_src 文件夾,里面包括 gerrit 安裝包 (
gerrit-2.13.11.war
) , 以及 Gerrit 插件 (gerrit_lib.tar.gz
).后續(xù)將這兩個文件上傳到 centos 的根路徑中。需要進行手動安裝。
安裝部署
1. 安裝 gerrit
- 安裝git
yum -y install git
- 獲取 gerrit 資源包
將一開始準備的資源包gerrit-2.13.11.war
和gerrit_lib.tar.gz
軟件包上傳至/root
目錄 - 安裝java(java版本要大于1.7)
yum -y install java
2. 安裝數(shù)據(jù)庫
-
安裝數(shù)據(jù)庫mysql
yum -y install mariadb*
-
啟動數(shù)據(jù)庫
systemctl start mariadb systemctl enable mariadb
-
初始化數(shù)據(jù)庫
[root@codesweet ~]# mysql_secure_installation Enter current password for root (enter for none): # 輸入數(shù)據(jù)庫超級管理員root的密碼(注意不是系統(tǒng)root的密碼),第一次進入還沒有設置密碼則直接回車 Set root password? [Y/n] # 設置密碼,y New password: # 新密碼 123456 Re-enter new password: # 再次輸入密碼 123456 Remove anonymous users? [Y/n] # 移除匿名用戶, y Disallow root login remotely? [Y/n] # 拒絕root遠程登錄,n Remove test database and access to it? [Y/n] # 刪除test數(shù)據(jù)庫,y Reload privilege tables now? [Y/n] # 重新加載權限表,y?;蛘咧貑⒎找苍S
-
數(shù)據(jù)庫字符集配置
a.vim /etc/my.cnf
,在 [mysqld] 標簽下添加:init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
b.
vim /etc/my.cnf.d/client.cnf
,在 [client] 標簽下添加:default-character-set=utf8
c.
/etc/my.cnf.d/mysql-clients.cnf
,在 [mysql] 標簽下添加default-character-set=utf8
d. 重啟數(shù)據(jù)庫服務
systemctl restart mariadb
3. 配置啟動
- 登錄數(shù)據(jù)庫
mysql -p123456
- 創(chuàng)建數(shù)據(jù)庫
create database reviewdb; grant all privileges on reviewdb.* to "gerrit"@"%" identified by "123456";
- 刷新權限并退出
flush privileges; exit;
- 創(chuàng)建gerrit用戶
adduser gerrit
- 切換到gerrit用戶
cd / \cp gerrit-2.13.11.war /home/gerrit/ \cp gerrit_lib.tar.gz /home/gerrit/ su - gerrit
- 初始化環(huán)境
mkdir -p /home/gerrit/code_review tar xf gerrit_lib.tar.gz -C code_review/
4. 安裝 gerrit
-
安裝 gerrit
java -jar gerrit-2.13.11.war init -d /home/gerrit/code_review
ldap認證的初始化配置方式如下:
*** Gerrit Code Review 2.13.11 *** Create '/home/gerrit/code_review' [Y/n]? 回車 *** Git Repositories *** Location of Git repositories [git]: 回車 *** SQL Database *** Database server type [h2]:mysql *** User Authentication *** Authentication method [OPENID/?]: LDAP LDAP server [ldap://localhost]: ldap://121.51.39.239 LDAP username : cn=admin,dc=codesweet,dc=com cn=admin,dc=bkce,dc=com's password : 123456 confirm password : 123456 Account BaseDN [DC=168,DC=56,DC=85]: ou=users,dc=codesweet,dc=com Group BaseDN [ou=users,dc=bkce,dc=com]: ou=users,dc=codesweet,dc=com Enable signed push support [y/N]? n *** Review Labels *** Install Verified label [y/N]? 回車 *** Email Delivery *** *** SMTP server hostname [localhost]: 回車 SMTP server port [(default)]: 回車 SMTP encryption [NONE/?]: 回車 SMTP username : 回車 *** Container Process *** Run as [gerrit]: 回車 Java runtime [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre]: 回車 Copy gerrit-2.13.11.war to /home/gerrit/code_review/bin/gerrit.war [Y/n]? y Copying gerrit-2.13.11.war to /home/gerrit/code_review/bin/gerrit.war *** SSH Daemon *** Listen on address [*]: 回車 Listen on port [29418]: 回車 Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v152 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 https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.52/bcpkix-jdk15on-1.52.jar ... OK Checksum bcpkix-jdk15on-1.52.jar OK Gerrit Code Review is not shipped with Bouncy Castle Crypto Provider v152 ** This library is required by Bouncy Castle Crypto SSL v152. ** Download and install it now [Y/n]? y Downloading https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.52/bcprov-jdk15on-1.52.jar ... OK Checksum bcprov-jdk15on-1.52.jar OK Generating SSH host key ... rsa... dsa... done *** HTTP Daemon *** Behind reverse proxy [y/N]? 回車 Use SSL (https://) [y/N]? 回車 Listen on address [*]: 回車 Listen on port [8080]: 回車 Canonical URL [http://linux-node83.domain.local:8080/]: http://121.51.39.239:8080/ *** Cache *** *** Plugins *** Installing plugins. Install plugin commit-message-length-validator version v2.13.11 [y/N]? y Installed commit-message-length-validator v2.13.11 Install plugin download-commands version v2.13.11 [y/N]? y Installed download-commands v2.13.11 Install plugin hooks version v2.13.11 [y/N]? y Installed hooks v2.13.11 Install plugin replication version v2.13.11 [y/N]? y Installed replication v2.13.11 Install plugin reviewnotes version v2.13.11 [y/N]? y Installed reviewnotes v2.13.11 Install plugin singleusergroup version v2.13.11 [y/N]? y Installed singleusergroup v2.13.11 Initializing plugins. No plugins found with init steps.
-
啟動 gerrit
/home/gerrit/code_review/bin/gerrit.sh restart
-
配置文件
上面的安裝步驟后續(xù)如果有些配置想要更改的話,可以對/home/gerrit/code_review/etc/gerrit.config
文件進行更改vim /home/gerrit/code_review/etc/gerrit.config
然后重啟 gerrit
/home/gerrit/code_review/bin/gerrit.sh restart
我的 gerrit.config 文件內容:
[gerrit] basePath = git serverId = 3c7f6094-4b63-4c30-a4e3-7e1805a3f1ed canonicalWebUrl = http://121.51.39.239:8080/ [database] type = mysql hostname = localhost database = reviewdb username = gerrit [auth] type = LDAP [ldap] server = ldap://121.51.39.239 username = cn=admin,dc=codesweet,dc=com accountBase = ou=users,dc=codesweet,dc=com groupBase = ou=users,dc=codesweet,dc=com [receive] enableSignedPush = false [sendemail] #smtpServer = localhost enable = true smtpServer = smtp.qq.com smtpServerPort = 465 smtpEncryption = SSL sslVerify = true smtpUser = 24611***@qq.com smtpPass = dmytimlooemd*** from = 24611***@qq.com [container] user = gerrit javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.an7.x86_64/jre [sshd] listenAddress = *:29418 [httpd] listenUrl = http://*:8080/ [cache] directory = cache [gitweb] type = gitweb cgi = /var/www/git/gitweb.cgi
-
配置 gerrit 服務器郵箱
a. 如果需要郵箱推服務,就是提交代碼后,會有郵件告知 code review 審查人員。那么就需要配置 gerrit 服務器郵箱,可以在 gerrit.config 中進行配置。b. gerrit 服務器郵箱只有一個,起轉發(fā)作用,就是將某個 gerrit 客戶端的信息轉發(fā)給另一個或多個客戶端。
c. 如果你的服務器郵箱配置的是 qq 郵箱 gerrit.config 中 sendemail 字段中如果是qq郵箱,則按照下述配置,里面最終要的一點不要搞錯,smtpPass填的不是郵箱密碼,而是授權碼,這個授權碼是需要提前到qq郵箱的設置中開啟smtp授權的,開啟后會得到授權碼。開啟方法:qq郵箱如何開啟SMTP服務
[sendemail] #smtpServer = localhost enable = true smtpServer = smtp.qq.com smtpServerPort = 465 smtpEncryption = SSL sslVerify = true smtpUser = 24611***@qq.com smtpPass = dmytimlooemd*** from = 24611****@qq.com
d. 163 郵箱也類似的步驟
[sendemail] #smtpServer = localhost enable = true smtpServer = smtp.163.com smtpServerPort = 465 smtpEncryption = SSL sslVerify = true smtpUser = 788844***@163.com smtpPass = dmdddsemd*** from = 788844***@163.com
管理員用戶登錄
1. 在LDAP上注冊用戶
- 先登錄 LDAP 服務器
- 創(chuàng)建用戶組
a. 先點擊users
,再點擊創(chuàng)建一個子目錄
b. 點擊 Posix Group
c. 輸入組名,然后點擊創(chuàng)建對象
d. 然后點擊提交 - 創(chuàng)建用戶
a. 先點擊users
,再點擊創(chuàng)建一個子目錄
b. 點擊 User Accout
c. 創(chuàng)建用戶對象
d. 點擊提交
第一次登陸gerrit的用戶默認為超級管理員用戶,管理員可以創(chuàng)建倉庫,后面登陸的用戶都是普通用戶,普通用戶無法創(chuàng)建倉庫,除非被管理員賦予權限。 - 添加郵箱
a. 點擊eric
,然后點擊添加新的屬性
,然后在選框中選中 Email
b. 在添加屬性
欄中的下拉框選中Email
,
c. 然后填寫郵箱信息后直接回車即可
d. 然后點擊Update Object
- web 端登錄 gerrit
a. 打開瀏覽器:http://121.51.39.239:8080
b. 輸入用戶名eric
和密碼123456
,然后點擊Sign In
c. 登陸成功后,可以看到可以創(chuàng)建倉庫
在gerrit服務器上集成gitweb
-
安裝gitweb
yum install gitweb
安裝完成后會有如下文件:/var/www/git/gitweb.cgi
-
配置gitweb
修改gitweb的配置文件(/etc/gitweb.conf),將配置項“$projectroot”修改為gerrit的git倉庫目錄$projectroot = "/etc/gerrit/git"
-
配置gerrit
修改gerrit的配置文件(gerrit.config),添加如下配置文章來源:http://www.zghlxwxcb.cn/news/detail-432840.html[gitweb] type = gitweb cgi = /var/www/git/gitweb.cgi
-
驗證是否成功
可以看到gitweb
字樣就表示成功了
點擊gitweb
,可以看到下述內容表示成功文章來源地址http://www.zghlxwxcb.cn/news/detail-432840.html
到了這里,關于搭建gerrit服務器+LDAP認證+集成gitewb詳細流程的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!