配置一下端口映射:
config.vm.network :forwarded_port, guest: 18080, host: 18080
config.vm.network :forwarded_port, guest: 29418, host: 29418
参考: https://gerrit-documentation.storage.googleapis.com/Documentation/2.9/install.html
mysql> CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'secret';
mysql> CREATE DATABASE gerrit2db default charset utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL ON gerrit2db.* TO 'gerrit2'@'localhost';
mysql> FLUSH PRIVILEGES;
$ sudo adduser gerrit2
$ sudo su - gerrit2
初始化启动:
$ java -jar gerrit-2.9.war init -d /home/gerrit2/review_site
*** Gerrit Code Review 2.9
***
Create '/home/gerrit2/review_site' [Y/n]? Y
*** Git Repositories
***
Location of Git repositories [git]:
*** SQL Database
***
Database server type [h2]: mysql
Gerrit Code Review is not shipped with MySQL Connector/J 5.1.21
** This library is required for your configuration. **
Download and install it now [Y/n]? Y
Downloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar ... OK
Checksum mysql-connector-java-5.1.21.jar OK
Server hostname [localhost]:
Server port [(mysql default)]:
Database name [reviewdb]: gerrit2db
Database username [gerrit2]:
gerrit2's password :
confirm password :
*** Index
***
Type [LUCENE/?]: ?
Supported options are:
lucene
solr
Type [LUCENE/?]:
*** User Authentication
***
Authentication method [OPENID/?]: ?
Supported options are:
openid
openid_sso
http
http_ldap
client_ssl_cert_ldap
ldap
ldap_bind
custom_extension
development_become_any_account
Authentication method [OPENID/?]: development_become_any_account
*** 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 [gerrit2]:
Java runtime [/opt/jdk7/jre]:
Copy gerrit-2.9.war to /home/gerrit2/review_site/bin/gerrit.war [Y/n]?
Copying gerrit-2.9.war to /home/gerrit2/review_site/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]:
Listen on port [29418]:
Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v149
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 http://www.bouncycastle.org/download/bcpkix-jdk15on-149.jar ... OK
Checksum bcpkix-jdk15on-149.jar OK
Gerrit Code Review is not shipped with Bouncy Castle Crypto Provider v149
** This library is required by Bouncy Castle Crypto SSL v149. **
Download and install it now [Y/n]? Y
Downloading http://www.bouncycastle.org/download/bcprov-jdk15on-149.jar ... OK
Checksum bcprov-jdk15on-149.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]: 18080
Canonical URL [http://review-ci:18080/]: http://gerrit.local.com:18080/
*** Plugins
***
Install plugin commit-message-length-validator version v2.9 [y/N]? y
Install plugin download-commands version v2.9 [y/N]? y
Install plugin replication version v2.9 [y/N]? y
Install plugin reviewnotes version v2.9 [y/N]? y
Install plugin singleusergroup version v2.9 [y/N]? y
Initialized /home/gerrit2/review_site
Executing /home/gerrit2/review_site/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on gerrit.local.com:18080 ... OK
Opening http://gerrit.local.com:18080/#/admin/projects/ ...FAILED
Open Gerrit with a JavaScript capable browser:
http://gerrit.local.com:18080/#/admin/projects/
review_site/bin/gerrit.sh start
review_site/bin/gerrit.sh stop
review_site/bin/gerrit.sh restart
修改数据库连接参数,看gerrit的配置帮助吧,这里直接给结果吧:
[database]
type = mysql
url = jdbc:mysql://localhost:3306/reviewdb?user=user&password=pwd&useUnicode=true&characterEncoding=utf8
这样的话,中文便显示正常了。原来的配置是这样子的:
[database]
type = mysql
hostname = localhost
database = reviewdb
username = user
数据库要修改一下:
alter table account_diff_preferences engine=innodb;
alter table account_external_ids engine=innodb;
alter table account_group_id engine=innodb;
alter table account_group_includes_by_uuid engine=innodb;
alter table account_group_includes_by_uuid_audit engine=innodb;
alter table account_group_members engine=innodb;
alter table account_group_members_audit engine=innodb;
alter table account_group_names engine=innodb;
alter table account_groups engine=innodb;
alter table account_id engine=innodb;
alter table account_patch_reviews engine=innodb;
alter table account_project_watches engine=innodb;
alter table account_ssh_keys engine=innodb;
alter table accounts engine=innodb;
alter table change_id engine=innodb;
alter table change_message_id engine=innodb;
alter table change_messages engine=innodb;
alter table changes engine=innodb;
alter table patch_comments engine=innodb;
alter table patch_set_ancestors engine=innodb;
alter table patch_set_approvals engine=innodb;
alter table patch_sets engine=innodb;
alter table schema_version engine=innodb;
alter table starred_changes engine=innodb;
alter table submodule_subscriptions engine=innodb;
alter table system_config engine=innodb;
alter table tracking_ids engine=innodb;
ALTER TABLE account_diff_preferences CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_external_ids CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_includes_by_uuid CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_includes_by_uuid_audit CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_members CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_members_audit CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_names CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_patch_reviews CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_project_watches CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_ssh_keys CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE accounts CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE change_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE change_message_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE change_messages CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE changes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE patch_comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE patch_set_ancestors CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE patch_set_approvals CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE patch_sets CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE schema_version CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE starred_changes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE submodule_subscriptions CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE system_config CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tracking_ids CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
网上的配置可能会出现不能打开Review界面,应该用下面这个配置, 注意AllowEncodedSlashes NoDecode和nocanon:
<VirtualHost *:10080>
ServerAdmin webmaster@localhost
ServerName gerrit.local.com
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
AllowEncodedSlashes NoDecode
ProxyPass / http://localhost:18080/ nocanon
</VirtualHost>
git config --file $site_path/etc/gerrit.config auth.type HTTP
sudo apt-get install apache2-utils
sudo htpasswd -c /var/www/mywebsite.com/.htpasswd exampleuser
The tool will prompt you for a password.
New password:
Re-type new password:
Adding password for user exampleuser
server {
listen 80;
server_name review.example.com;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
auth_basic "Restricted"; #For Basic Auth
auth_basic_user_file /var/www/mywebsite.com/.htpasswd; #For Basic Auth
}
}