安装brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装Nginx
// 安装nginx
$ brew install nginx
// 查看nginx版本
$ brew -v
// 查看nginx服务进程
$ ps -ef|grep nginx
// 开启nginx服务
$ nginx
// 停止nginx服务
$ nginx -s stop
// 重新加载
$ nginx -s reload
下载Gerrit
安装Gerrit
$ java -jar gerrit-2.15.1.war init -d ~/gerrit_site
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
*** Gerrit Code Review 2.15.1
***
*** Git Repositories
***
Location of Git repositories [git]:
*** SQL Database
***
Database server type [mysql]: h2
*** Index
***
Type [lucene/?]:
*** User Authentication
***
Authentication method [http/?]: http
Supported options are:
openid
openid_sso
http
http_ldap
client_ssl_cert_ldap
ldap
ldap_bind
custom_extension
development_become_any_account
Get username from custom HTTP header [y/N]?
SSO logout URL :
Enable signed push support [y/N]?
*** Review Labels
***
Install Verified label [y/N]? Y
*** Email Delivery
***
SMTP server hostname [localhost]:
SMTP server port [(default)]:
SMTP encryption [none/?]:
SMTP username :
*** Container Process
***
Run as [wangyanan]:
Java runtime [/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre]:
Upgrade /Users/wangyanan/gerrit_site/bin/gerrit.war [Y/n]?
Copying gerrit-2.15.1.war to /Users/wangyanan/gerrit_site/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]: Listen on port [29418]:
*** HTTP Daemon
***
Behind reverse proxy [y/N]?
Use SSL (https://) [y/N]?
Listen on address [*]:
Listen on port [8080]:
Canonical URL [http://localhost:8080/]:
*** Cache
***
*** Plugins
***
Installing plugins.
Install plugin commit-message-length-validator version v2.15.1 [Y/n]?
commit-message-length-validator v2.15.1 is already installed, overwrite it [Y/n]?
Updated commit-message-length-validator to v2.15.1
Install plugin download-commands version v2.15.1 [Y/n]?
download-commands v2.15.1 is already installed, overwrite it [Y/n]?
Updated download-commands to v2.15.1
Install plugin hooks version v2.15.1 [Y/n]?
hooks v2.15.1 is already installed, overwrite it [Y/n]?
Updated hooks to v2.15.1
Install plugin replication version v2.15.1 [Y/n]?
replication v2.15.1 is already installed, overwrite it [Y/n]?
Updated replication to v2.15.1
Install plugin reviewnotes version v2.15.1 [Y/n]?
reviewnotes v2.15.1 is already installed, overwrite it [Y/n]?
Updated reviewnotes to v2.15.1
Install plugin singleusergroup version v2.15.1 [Y/n]?
singleusergroup v2.15.1 is already installed, overwrite it [Y/n]?
Updated singleusergroup to v2.15.1
Initializing plugins.
*** Experimental features
***
Enable any experimental features [y/N]?
Initialized /Users/wangyanan/gerrit_site
Executing /Users/wangyanan/gerrit_site/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on localhost:8080 ... OK
Opening http://localhost:8080/#/admin/projects/ ...OK
配置Gerrit
- 修改 ~/gerrit_site/etc/gerrit.config 配置文件
[gerrit]
basePath = git
canonicalWebUrl = http://127.0.0.1:8080/ //nginx的代理端口
.........
[httpd]
listenUrl = http://*:8080/
- 添加 ~/gerrit_site/etc/gerrit.password 配置文件
// 添加管理员账户gerrit
$ htpasswd -c gerrit~/gerrit_site/etc/gerrit.password gerrit
配置Nginx
- 修改 /usr/local/etc/nginx/nginx.conf 配置文件
http {
include mime.types;
default_type application/octet-stream;
server {
listen 7780;
server_name 127.0.0.1;
allow all;
deny all;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
auth_basic "Welcomme to Gerrit Code Review Site!";
auth_basic_user_file ~/gerrit_site/etc/gerrit.password; // AuthUserFile路径
proxy_pass http://127.0.0.1:8080; // 注意后面不能加"/",否则会出现“Code Review - Error The page you requested was not found....permission to view this page”的报错
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
include servers/*;
}
启动Nginx和Gerrit
$ nginx -s reload
$ gerrit.sh restart // 注意:如果没有添加环境变量,在配置~/.bash_profile中,只能使用绝对路径访问sh命令。
正常来说,访问http://127.0.0.1:7780/,然后,在弹出的对话框中输入Gerrit的管理员账户密码,就能正常的访问到http://127.0.0.1:8080/的Gerrit服务。
配置Gerrit邮件系统
- 修改 ~/gerrit_site/etc/gerrit.config 配置文件
[sendemail]
smtpServer = smtp.163.com
smtpServerPort = 465
smtpEncryption = ssl
sslVerify = false
smtpUser = 发送者邮箱
from = 发送者邮箱
- 修改 ~/gerrit_site/etc/secure.config 配置文件
[sendemail]
smtpPass = 邮箱登陆密码
gerrit对接gitweb(没有对接成功)
- gitweb安装
----> Git-GitWeb文档 - gerrit参数配置
$ git config --file ~/gerrit_site/etc/gerrit.config gitweb.cgi /var/www/gitweb/gitweb.cgi
$ git config --file ~/gerrit_site/etc/gerrit.config --unset gitweb.url
$ cat ~/gerrit_site/etc/gerrit.config
[gerrit]
basePath = git
serverId = 375c686a-b8d3-4798-934f-01e5d532dae9
canonicalWebUrl = http://localhost:8080/
...
...
[gitweb]
cgi = /var/www/gitweb/gitweb.cgi
注意
用htpasswd创建第一个用户时默认是系统管理员,ID为1000000,默认只有这个系统管理员才有Create权限(创建group和Project),其他的都只有“List”查看权限
用htpasswd创建的用户时,并没有往gerrit中添加账号,只有当该用户通过web登陆gerrit服务器时,该账号才会被添加进gerrit数据库中。
退出admin账号重新登陆(HTTP认证模式不支持Sign Out,需要先Sign Out退出账号,关闭浏览器后再登陆才能出现http验证密码的对话框。
Linux环境搭建