安裝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環境搭建