CentOS 7.2 安裝Gerrit 2.14.6
阿新 • • 發佈:2018-01-28
config nta body 情況 sso www order false src
1.環境
本文使用VMWare虛擬機進行實驗。
- 2核CPU,4GB內存,20GB硬盤,IP:192.168.159.131
- CentOS 7.2最小安裝(CentOS-7-x86_64-Minimal-1511.iso)
2.需求
Gerrit支持多種數據庫、多種認證方式(參考官網手冊),這裏使用
- mariadb數據庫
- http認證
- HTTPd作為web服務器,提供反向代理
- gitweb作為Repository Browser
3.安裝
3.1 安裝軟件
yum -y install git gitweb httpd mariadb-server
3.2 配置數據庫
systemctl start mariadb
mysql
鍵入如下內容,這裏密碼是secret
CREATE USER ‘gerrit2‘@‘localhost‘ IDENTIFIED BY ‘secret‘; CREATE DATABASE reviewdb DEFAULT CHARACTER SET ‘utf8‘; GRANT ALL ON reviewdb.* TO ‘gerrit2‘@‘localhost‘; FLUSH PRIVILEGES;
3.3 配置httpd反向代理
vim /etc/httpd/conf.d/gerrit.conf
鍵入如下內容
<VirtualHost *> ServerName192.168.159.131 ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> <Location /login/> AuthType Basic AuthName "Gerrit Code Review" AuthBasicProvider file AuthUserFile/gerrit.password Require valid-user </Location> AllowEncodedSlashes On ProxyPass / http://127.0.0.1:8081/ </VirtualHost>
註意,
- ServerName根據自己實際情況來定, 我用的本機IP
- gerrit的http認證方式,需要使用HTTP基本認證,這裏使用文件(/gerrit.password,httpd要有訪問權限才行)方式認證。
- 反向代理設置,從根目錄"/",代理到"http://127.0.0.1:8081/",註意端口8001後面有個斜線。8081是gerrit監聽的端口,後面會提到。
啟動httpd,將監聽80端口(反向代理到8081端口)
systemctl start httpd
3.4 添加認證用戶
touch /gerrit.passwd htpasswd /gerrit.passwd "root"
New password:
Re-type new password:
Adding password for user root
這裏添加了用戶root,密碼123456(跟linux本地用戶沒有關系!)
這樣首次訪問gerrit時的用戶將成為gerrit的管理員,若想再添加用戶,需要先在/gerrit.passwd中添加,再登錄gerrit。
3.5 安裝JRE
從官網下載Java SE Runtime Environment 8u162 Linux x64
jre-8u162-linux-x64.tar
tar zxvf jre-8u162-linux-x64.tar -C /opt
export JAVA_HOME=/opt/jre1.8.0_162
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/toos.jar
3.6 安裝gerrit
3.6.1 添加用戶
sudo adduser gerrit2 sudo su gerrit2
從官網下載gerrit的war包gerrit-2.14.6.war,這裏放至gerrit2的home目錄
3.6.2 創建工作目錄
mv gerrit-2.14.6.war gerrit.war
mkdir gerrit-test
3.6.3 安裝
進入交互命令,藍色粗體表示輸入的內容
[gerrit2@ted ~]$ java -jar /opt/gerrit.war init -d gerrit-test/ Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore [2018-01-28 13:14:14,823] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit2/gerrit-test/etc/gerrit.config; assuming defaults *** Gerrit Code Review 2.14.6 *** Create ‘/home/gerrit2/gerrit-test‘ [Y/n]y *** Git Repositories *** Location of Git repositories [git]: #回車 *** SQL Database *** Database server type [h2]: mariadb Gerrit Code Review is not shipped with MariaDB Connector/J 1.5.9 ** This library is required for your configuration. ** Download and install it now [Y/n]? y Downloading https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/1.5.9/mariadb-java-client-1.5.9.jar ... OK Checksum mariadb-java-client-1.5.9.jar OK Server hostname [localhost]: #回車 Server port [(mariadb default)]: #回車 Database name [reviewdb]: #回車 Database username [gerrit2]: #回車 gerrit2‘s password : #secret confirm password : #secret *** Index *** Type [lucene/?]: #回車 *** User Authentication *** Authentication method [openid/?]: http Get username from custom HTTP header [y/N]? #回車 SSO logout URL : #回車 Enable signed push support [y/N]? #回車 *** Review Labels *** Install Verified label [y/N]? #回車 *** Email Delivery *** SMTP server hostname [localhost]: #回車 SMTP server port [(default)]: #回車 SMTP encryption [none/?]: #回車 SMTP username : [email protected] [email protected]‘s password : #123456 confirm password : #123456 *** Container Process *** Run as [gerrit2]: #回車 Java runtime [/opt/jre1.8.0_162]: #回車 Copy gerrit.war to gerrit-test/bin/gerrit.war [Y/n]? #回車 Copying gerrit.war to gerrit-test/bin/gerrit.war *** SSH Daemon *** Listen on address [*]: #回車 Listen on port [29418]: #回車 Generating SSH host key ... rsa... dsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done *** HTTP Daemon *** Behind reverse proxy [y/N]? y Proxy uses SSL (https://) [y/N]? #回車 Subdirectory on proxy server [/]: #回車 Listen on address [*]: 127.0.0.1 Listen on port [8081]: #回車 Canonical URL [http://localhost/]: http://192.168.159.131 *** Cache *** *** Plugins *** Installing plugins. Install plugin commit-message-length-validator version v2.14.6 [y/N]? y Installed commit-message-length-validator v2.14.6 Install plugin download-commands version v2.14.6 [y/N]? y Installed download-commands v2.14.6 Install plugin hooks version v2.14.6 [y/N]? y Installed hooks v2.14.6 Install plugin replication version v2.14.6 [y/N]? y Installed replication v2.14.6 Install plugin reviewnotes version v2.14.6 [y/N]? y Installed reviewnotes v2.14.6 Install plugin singleusergroup version v2.14.6 [y/N]? y Installed singleusergroup v2.14.6 Initializing plugins. Initialized /home/gerrit2/gerrit-test Executing /home/gerrit2/gerrit-test/bin/gerrit.sh start Starting Gerrit Code Review: OK
......
[gerrit2@ted ~]$
完成後查看端口情況
[root@ted ~]# netstat -ltnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2718/mysqld tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1125/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1563/master tcp6 0 0 :::29418 :::* LISTEN 3118/GerritCodeRevi tcp6 0 0 :::80 :::* LISTEN 2465/httpd tcp6 0 0 127.0.0.1:8081 :::* LISTEN 3118/GerritCodeRevi tcp6 0 0 :::22 :::* LISTEN 1125/sshd tcp6 0 0 ::1:25 :::* LISTEN 1563/master [root@ted ~]#
這樣初始化好後,gerrit的配置文件(gerrit-test/etc/gerrit.config)
[gerrit]
basePath = git
serverId = 70a67d2b-e12e-42b9-a978-705d7685654d
canonicalWebUrl = http://192.168.118.145
[database]
type = mariadb
hostname = localhost
database = reviewdb
username = gerrit2
[index]
type = LUCENE
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
smtpUser = [email protected]
[container]
user = gerrit2
javaHome = /opt/jre1.8.0_162
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://127.0.0.1:8081/
[cache]
directory = cache
4.測試
使用瀏覽器訪問canonicalWebUrl ,
http://192.168.118.145
提示輸入用戶密碼,就是/gerrit.password裏的用戶密碼
登錄成功後,將看到gerrit用戶信息登記界面(添Full Name什麽的),然後進入主界面
管理命令如下
./gerrit-test/bin/gerrit.sh start ./gerrit-test/bin/gerrit.sh stop ./gerrit-test/bin/gerrit.sh status
5.配置gitweb
6.配置郵箱驗證
CentOS 7.2 安裝Gerrit 2.14.6