本文使用VMWare虚拟机进行实验。html
Gerrit支持多种数据库、多种认证方式(参考官网手册),这里使用java
yum -y install git gitweb httpd mariadb-server
systemctl start mariadb
mysql
键入以下内容,这里密码是secretmysql
CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'secret'; CREATE DATABASE reviewdb DEFAULT CHARACTER SET 'utf8'; GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost'; FLUSH PRIVILEGES;
vim /etc/httpd/conf.d/gerrit.conf
键入以下内容linux
<VirtualHost *> ServerName 192.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>
注意,git
启动httpd,将监听80端口(反向代理到8081端口)web
systemctl start httpd
touch /gerrit.passwd htpasswd /gerrit.passwd "root"
New password:
Re-type new password: Adding password for user root
这里添加了用户root,密码123456(跟Linux本地用户没有关系!)sql
这样首次访问gerrit时的用户将成为gerrit的管理员,若想再添加用户,须要先在/gerrit.passwd中添加,再登陆gerrit。数据库
从官网下载Java SE Runtime Environment 8u162 Linux x64vim
jre-8u162-linux-x64.tarapi
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
sudo adduser gerrit2 sudo su gerrit2
从官网下载gerrit的war包gerrit-2.14.6.war,这里放至gerrit2的home目录
mv gerrit-2.14.6.war gerrit.war
mkdir gerrit-test
进入交互命令,蓝色粗体表示输入的内容
[gerrit2@ted ~]$ java -jar 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 : co3@qq.com co3@qq.com'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
Waiting for server on 192.168.118.158:80 ... OK
Opening http://192.168.118.158/#/admin/projects/ ...FAILED #(由于尚未用户,因此failed,不影响)
Open Gerrit with a JavaScript capable browser:
http://192.168.118.158/#/admin/projects/
[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 = co3@qq.com [container] user = gerrit2 javaHome = /opt/jre1.8.0_162 [sshd] listenAddress = *:29418 [httpd] listenUrl = proxy-http://127.0.0.1:8081/ [cache] directory = cache
使用浏览器访问canonicalWebUrl ,
http://192.168.118.145
提示输入用户密码,就是/gerrit.password里的http认证用户密码
登陆成功后,将看到gerrit用户信息登记界面(添Full Name什么的),而后进入主界面
管理命令以下
./gerrit-test/bin/gerrit.sh start ./gerrit-test/bin/gerrit.sh stop ./gerrit-test/bin/gerrit.sh status
参考官网手册,可使用命令行实现,我这里直接编辑配置文件,
vi gerrit-test/etc/gerrit.config
添加以下gitweb配置
[gitweb] cgi = /var/www/git/gitweb.cgi type = gitweb
(注意!此处有坑!若是按官网手册用命令配置,type是没有值的,而默认是disabled,不会显示gitweb超连接!必须手动设置!)
重启gerrit,退出web窗口,从新认证登陆,能够看见gitweb超连接了
浏览hey项目,
若是按前面默认配置,使用本机smtp发送邮件,这样若是发到公网邮箱(qq、163等),会被断定为垃圾邮件,发不出去。
若是是实验性质的话,能够在局域网搭建postfix+dovecot+dnsmasq简单邮件系统,进行邮箱注册。
(gerrit的帐号必须注册邮箱,添加ssh公钥/http密码,git 配置邮箱必须跟注册邮箱一致,才能push)
我再看看其余解决垃圾邮件方法...