±à¼ÍƼö: |
±¾ÎÄÀ´×ÔÓÚcsdn£¬±¾ÎÄÕÂÖ÷Ҫͨ¹ý½¨Á¢ÕË»§£¬ÅäÖû·¾³°²×°gerritÒÔ¼°Gerrit´úÂëÉóºË·þÎñÆ÷´î½¨È«¹ý³Ì£¬Ï£Íû¶ÔÄúµÄѧϰÓÐËù°ïÖú¡£ |
|
½¨Á¢×¨ÓÐÕÊ»§
$
sudo useradd gerrit -m -s /bin/bash
$ sudo passwd gerrit
$ su gerrit
|
ÅäÖÃ Java »·¾³
´Ó¹ÙÍøÏÂÔØgerrit
https://www.gerritcodereview.com/
µ±Ç°×îа汾Ϊ 2.14¡£
°²×° MySQL
$
sudo apt-get install mysql-server
$ sudo apt-get install mysql-client
$ sudo apt-get install libmysqlclient-dev
|
°²×°gerrit
ͨ¹ýÈçÏÂÃüÁî°²×° Gerrit£º
$
java -jar gerrit-2.14.war init -d review_site
|
°´ÕÕÌáʾһ²½²½Íê³É°²×°¡£
Óм¸¸ö°´×ªÅäÖÃÐèÒªÌØ±ð×¢Òâһϡ£
¹ØÓÚ Gerrit µÄ Git ²Ö¿âµÄ±£´æµØÖ·£º
***
Git Repositories
***
Location of Git repositories [git]: GerritResource
|
Õâ¸öÑ¡ÏîÓÃÓÚÅäÖà Gerrit µÄ Git ²Ö¿âµÄ±£´æµØÖ·¡£ÉÏÃæµÄÅäÖý«´´½¨
/home/gerrit/review_site/GerritResource Ŀ¼ÓÃÓÚ±£´æ Gerrit
µÄ Git ²Ö¿â¡£
¹ØÓÚÊý¾Ý¿âµÄÅäÖãº
***
SQL Database
***
Database server type [h2]: mysql
Gerrit Code Review is not shipped with MySQL
Connector/J 5.1.41
** This library is required for your configuration.
**
Download and install it now [Y/n]? Y
Downloading https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.41/mysql-connector-java-5.1.41.jar
... OK
Checksum mysql-connector-java-5.1.41.jar OK
Server hostname [localhost]: cloudgame-codereview.com
Server port [(mysql default)]:
Database name [reviewdb]:
Database username [gerrit]:
gerrit's password :
confirm password :
|
ÕâÀïÑ¡Ôñ MySQL ×÷Ϊ Gerrit µÄÊý¾Ý¿â£¬ÆäËüÑ¡ÏîÈ«²¿²ÉÓÃĬÈÏÅäÖ᣶ÔÓÚÕâÖÖÑ¡Ôñ£¬ÐèÒªÁ¬ÉÏ
MySQL£¬Îª Gerrit ´´½¨ÏàÓ¦µÄÊý¾Ý¿â£¬Óû§£¬²¢ÎªÓû§ÊÚȨ£º
$
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with
; or \g.
Your MySQL connection id is 35
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, Oracle and/or its
affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation
and/or its
affiliates. Other names may be trademarks of
their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to
clear the current input statement.
mysql> SELECT USER();
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> create database reviewdb;
Query OK, 1 row affected (0.01 sec)
mysql> CREATE USER 'gerrit'@'localhost' IDENTIFIED
BY 'gerrit';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on reviewdb.*
to gerrit@localhost identified by 'gerrit';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| reviewdb |
| sys |
+--------------------+
8 rows in set (0.01 sec)
mysql>
|
Gerrit °²×°¹ý³ÌÖУ¬¿ÉÄܻᱨ³öÈçÏ嵀 Exception£º
Exception
in thread "main" com.google.gwtorm.server.
OrmException: Cannot
apply SQL
CREATE TABLE account_group_members_audit (
added_by INT DEFAULT 0 NOT NULL,
removed_by INT,
removed_on TIMESTAMP NULL DEFAULT NULL,
account_id INT DEFAULT 0 NOT NULL,
group_id INT DEFAULT 0 NOT NULL,
added_on TIMESTAMP NOT NULL
,PRIMARY KEY(account_id,group_id,added_on)
)
at com.google.gwtorm.jdbc.JdbcExecutor.execute
(JdbcExecutor.java:44)
at com.google.gwtorm.jdbc.JdbcSchema.createRelations
(JdbcSchema.java:134)
at com.google.gwtorm.jdbc.JdbcSchema.updateSchema
(JdbcSchema.java:104)
at com.google.gerrit.server.schema.SchemaCreator.create
(SchemaCreator.java:81)
at com.google.gerrit.server.schema.SchemaUpdater.update
(SchemaUpdater.java:108)
at com.google.gerrit.pgm.init.BaseInit$SiteRun.upgradeSchema
(BaseInit.java:386)
at com.google.gerrit.pgm.init.BaseInit.run
(BaseInit.java:143)
at com.google.gerrit.pgm.util.AbstractProgram.main
(AbstractProgram.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram
(GerritLauncher.java:204)
at com.google.gerrit.launcher.GerritLauncher.mainImpl
(GerritLauncher.java:108)
at com.google.gerrit.launcher.GerritLauncher.main
(GerritLauncher.java:63)
at Main.main(Main.java:24)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Invalid default
value for 'added_on'
at sun.reflect.NativeConstructorAccessorImpl.
newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance
(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException
(SQLError.java:943)
at com.mysql.jdbc.MysqlIO.checkErrorPacket
(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket
(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.
java:2497)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.
java:2455)at com.mysql.jdbc.StatementImpl.executeInternal
(StatementImpl.java:839)
at com.mysql.jdbc.StatementImpl.execute
(StatementImpl.java:739)
at com.google.gwtorm.jdbc.JdbcExecutor.execute
(JdbcExecutor.java:42)
... 15 more
|
Õâ¸öÒì³£¿Éͨ¹ýÈçÏ·½Ê½½â¾ö£ºÊ¹Óà MySQL root Óû§µÇ¼£¬ÉèÖÃ
set global explicit_defaults_for_timestamp=1;£¬ÏñÏÂÃæÕâÑù£º
$
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with
; or \g.
Your MySQL connection id is 76
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, Oracle and/or its
affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation
and/or its
affiliates. Other names may be trademarks of
their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to
clear the current input statement.
mysql> set global explicit_defaults_for_timestamp=1;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
|
È»ºóÖØÐ°²×° Gerrit ¼´¿É¡££¨Ð°汾µÄ MySQL TIMESTAMP
ĬÈÏÖµµÄÎÊÌâÐèÒªÊÖ¶¯ÅäÖÃһϡ££©
°²×°Íê³Éºó£¬Gerrit Server ½«×Ô¶¯Æô¶¯¡£
ÅäÖÃgerrit
$
vim review_site/etc/gerrit.config
|
Õâ¸öÅäÖÃÎļþµÄÄÚÈÝÈçÏ£º
[gerrit]
basePath = GerritResource
serverId = 7b8058ff-932a-41ed-a1fa-6ea53dfba8e1
canonicalWebUrl = http://review.virtcloudgame.com:8080/
useSSL=false
[database]
type = mysql
hostname = review.virtcloudgame.com
database = reviewdb
username = gerrit
[index]
type = LUCENE
[auth]
type = http
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[sshd]
listenAddress = *:29418
[download]
scheme = ssh
scheme = http
[httpd]
listenUrl = proxy-http://127.0.0.1:8080/
[cache]
directory = cache
[plugins]
allowRemoteAdmin = true
|
°´ÕÕÈçÉÏÄÚÈÝÅäÖÃÍê Gerrit Server Ö®ºó£¬¿ÉÒÔͨ¹ýÈçÏÂÃüÁîÖØÐÂÆô¶¯ËüÒÔÓ¦ÓÃеÄÅäÖãº
$
review_site/bin/gerrit.sh restart
|
ÉèÖõÚÒ»¸ö Gerrit Óû§µÄÕʺźÍÃÜÂë
$
touch ./review_site/etc/passwd
$ htpasswd -b ./review_site/etc/passwd admin
admin
Adding password for user admin
|
htpasswd ÃüÁîÊÇ apache2-utils Èí¼þ°üÖеÄÒ»¸ö¹¤¾ß¡£Èç¹ûϵͳÖл¹Ã»Óа²×°µÄ»°£¬Í¨¹ýÈçÏÂÃüÁî½øÐа²×°£º
$
sudo apt-get install apache2-utils
|
(ºóÐøÔÙÌí¼Ó Gerrit Óû§¿ÉʹÓà htpasswd -b ./review_site/etc/passwd
UserName PassWord)
¶ÔÓÚ Gerrit À´Ëµ£¬µÚÒ»¸ö³É¹¦µÇ¼µÄÓû§¾ßÓÐÌØÊâÒâÒå ¡ª¡ª
Ëü»áÖ±½Ó±»¸³Óè¹ÜÀíԱȨÏÞ¡£¶ÔÓÚµÚÒ»¸öÕË»§£¬ÐèÒªÌØ±ð×¢Òâһϡ£
¿ªÆô Gerrit ·þÎñÆ÷
Gerrit ·þÎñÆ÷»¹¿ÉÒÔͨ¹ýÈçϵÄÃüÁî½øÐÐÆô¶¯£º
$ review_site/bin/gerrit.sh
start
Starting Gerrit Code Review: FAILED |
ÉÏÃæµÄÃüÁͨ¹ý review_site/bin/gerrit.sh
start Æô¶¯ Gerrit Server£¬µ«ÊÇʧ°ÜÁË¡£Gerrit Server Æô¶¯£¬ÐèÒª¼àÌý
8080 ¶Ë¿Ú£¬ÈçÇ°ÃæµÄÅäÖÃÎļþ review_site/etc/gerrit.config ÖеÄ
listenUrl ÐÐËùÏÔʾµÄÄÇÑù¡£Í¨¹ýÈçϵÄÃüÁî²é¿´ 8080 ¶Ë¿ÚµÄʹÓÃÇé¿ö£º
$
sudo lsof -i -P | grep 8080
java 9538 tomcat 53u IPv6 17098680 0t0 TCP *:8080
(LISTEN)
|
¿ÉÒÔ¿´µ½ 8080 ¶Ë¿Ú±» tomcat Óû§ÏµÄij¸ö Java
½ø³ÌÕ¼ÓÃÁË¡£ÎÒÃÇ¿ÉÒÔɱµôÏàÓ¦µÄÓ¦ÓÃÀ´½â¾ö Gerrit Server Æô¶¯Ê§°ÜµÄÎÊÌ⣨Tomcat
µÄ°²×°ÅäÖÃÆô¶¯°´ÕÕUbuntu 16.04 Tomcat 8°²×°Ö¸ÄÏ Ò»ÎĵÄ˵Ã÷½øÐУ©£º
$
sudo systemctl stop tomcat
$ sudo systemctl status tomcat
¡ñ tomcat.service - Apache Tomcat Web Application
Container
Loaded: loaded (/etc/systemd/system/tomcat.service;
enabled; vendor preset: enabled)
Active: inactive (dead) since ËÄ 2017-11-23
10:23:02 CST; 4s
ago
Process: 9805 ExecStop=/opt/tomcat/bin/shutdown.
sh (code=exited,
status=0/SUCCESS)
Process: 9527 ExecStart=/opt/tomcat/bin/startup.
sh (code=exited,
status=0/SUCCESS)
Main PID: 9538 (code=exited, status=0/SUCCESS)
11ÔÂ 23 10:20:18 ThundeRobot startup.sh[9527]:
Removing/clearing stale PID file.
11ÔÂ 23 10:20:18 ThundeRobot systemd[1]: Started
Apache Tomcat Web Application Container.
11ÔÂ 23 10:23:01 ThundeRobot systemd[1]: Stopping
Apache Tomcat Web Application Container...
11ÔÂ 23 10:23:01 ThundeRobot shutdown.sh[9805]:
Using CATALINA_BASE:
/opt/tomcat
11ÔÂ 23 10:23:01 ThundeRobot shutdown.sh[9805]:
Using CATALINA_HOME:
/opt/tomcat
11ÔÂ 23 10:23:01 ThundeRobot shutdown.sh[9805]:
Using CATALINA_TMPDIR:
/opt/tomcat/temp
11ÔÂ 23 10:23:01 ThundeRobot shutdown.sh[9805]:
Using JRE_HOME:
/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
11ÔÂ 23 10:23:01 ThundeRobot shutdown.sh[9805]:
Using CLASSPATH:
/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/
tomcat-juli.jar
11ÔÂ 23 10:23:01 ThundeRobot shutdown.sh[9805]:
Using CATALINA_PID:
/opt/tomcat/temp/tomcat.pid
11ÔÂ 23 10:23:02 ThundeRobot systemd[1]: Stopped
Apache Tomcat Web Application Container.
|
µ±È»Ò²¿ÉÒÔͨ¹ýÐÞ¸Ä Gerrit Server ¼àÌýµÄ¶Ë¿ÚÀ´½â¾öÎÊÌâ¡£
ÔÙ´ÎÆô¶¯ Gerrit Server£º
$
review_site/bin/gerrit.sh start
Starting Gerrit Code Review: OK
|
¿ÉÒÔ¿´µ½ Gerrit Server ³É¹¦Æô¶¯ÁË¡£´Ëʱͨ¹ýä¯ÀÀÆ÷£¬´ò¿ª
http://review.virtcloudgame.com:8080 ½«¿ÉÒÔ¿´µ½ÈçÏÂÕâÑùµÄÒ³Ãæ£º

ÐÞ¸ÄÈÏÖ¤·½Ê½ºÍ·´Ïò´úÀí
ΪÁËͨ¹ý¸üΪǿ´óµÄ Web ·þÎñÆ÷À´¶ÔÍâÌṩ·þÎñ£¬Í¬Ê±·½±ã Gerrit
Server µÄ HTTP Óû§ÈÏÖ¤·½Ê½¿ÉÒÔÕý³£¹¤×÷£¬ÐèÒªÉèÖ÷´Ïò´úÀí¡£ÕâÀïʹÓà nginx ×÷Ϊ
Web ·þÎñÆ÷¡£
Ê×Ïȸü¸Ä Gerrit ÅäÖã¬Ê¹ÄÜ´úÀí£»ÁíÍ⣬ʹÓ÷´Ïò´úÀíºó¾Í¿ÉÒÔÖ±½ÓʹÓÃ
nginx µÄ 80 ¶Ë¿Ú·ÃÎÊÁË£¬ÐèÒª°Ñ canonicalWebUrl ÖÐµÄ 8080 È¥µô£¬Gerrit
Server ¼àÌýµÄ¶Ë¿ÚÒ²¸ÄΪ 8081£º
[gerrit]
basePath = GerritResource
serverId = 7b8058ff-932a-41ed-a1fa-6ea53dfba8e1
canonicalWebUrl = http://review.virtcloudgame.com/
useSSL=false
. . . . . .
[auth]
type = HTTP
. . . . . .
[httpd]
listenUrl = proxy-http://127.0.0.1:8081/
|
ÐÞ¸ÄÖ®ºó£¬ÖØÆô Gerrit Server£º
$
review_site/bin/gerrit.sh restart
Stopping Gerrit Code Review: OK
Starting Gerrit Code Review: OK
|
ÉÏÃæµÄÐ޸Ľ«Ê¹ Gerrit Server ¼àÌýÔÚ 8081 ¶Ë¿ÚÉÏ£¬Í¬ÉÏ£¬½«ÈÏÖ¤·½Ê½ÐÞ¸ÄΪ
HTTP¡£
Gerrit Server Ç¿ÖÆÒªÇóʹÓ÷´Ïò´úÀí£¬Í¨¹ý·´Ïò´úÀí·þÎñÆ÷ÌṩµÄ
Authorization µÈ HTTP Í·À´»ñµÃÓû§ÈÏÖ¤ÐÅÏ¢¡£
½Ó×ÅÅäÖà nginx¡£ÐÞ¸Ä nginx µÄÅäÖÃÎļþ /etc/nginx/nginx.conf£¬ÔÚËüµÄ
http ¿éÖмÓÈëÈçÏÂÄÚÈÝ£º
server {
listen 80;
server_name review.virtcloudgame.com;
location ^~ / {
auth_basic "Restricted";
auth_basic_user_file /home/gerrit/review_site/etc/passwd;
proxy_pass http://127.0.0.1:8081;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
|
auth_basic_user_file ÐÐÓû§ÅäÖÃÓû§ÃûºÍÃÜÂëÎļþµÄ±£´æÂ·¾¶¡£proxy_pass
ÐÐÓû§ÉèÖà Gerrit Server µÄµØÖ·¡£
ÐÞ¸ÄÖ®ºó£¬Èà nginx ÖØÐ¼ÓÔØÅäÖÃÎļþ£º
ÕâÑù¾Í¿ÉÒÔÖ±½Óͨ¹ý nginx ¼àÌýµÄ 80 ¶Ë¿Ú·ÃÎÊ Gerrit
Server ÁË¡£

Replication ÅäÖÃ
ËùνµÄ replication£¬ÊÇ Gerrit µÄÒ»¸ö²å¼þ£¬Ëü¿ÉÒÔ×Ô¶¯µØ½«
Gerrit Code Review ¶ÔËüËù¹ÜÀíµÄ Git ²Ö¿â´´½¨µÄÈκΠchanges push
µ½ÁíÍâÒ»¸öϵͳÀï¡£Gerrit ±¾ÉíÌṩÁËÁ½´ó¹¦ÄÜ£ºÒ»ÊÇ Code Review£»¶þÊÇ Git ²Ö¿â¡£Replication
²å¼þͨ³£ÓÃÓÚÌṩ changes µÄ¾µÏñ£¬»òÈȱ¸·Ý¡£
´ËÍ⣬Ðí¶àÏÖÓеÄÏîÄ¿¿ÉÄÜÊÇÓÃÁíÍâÒ»Ì×ϵͳÀ´¹ÜÀí Git ´úÂë²Ö¿âµÄ£¬±ÈÈç
GitLab£¬»òÕß GitHub¡£ÐèÒªÒýÈë Gerrit ×ö Code Review£¬Í¬Ê±¶Ô½ÓÕâЩÒÑÓеÄ
Git ²Ö¿âϵͳʱ£¬replication ²å¼þ±È½ÏÓÐÓá£
ÅäÖà replication ½«´úÂëͬ²½µ½ GitLab µÄ·½·¨ÈçÏ¡£
Èç¹ûͨ¹ý SSH À´´Ó Gerrit ͬ²½´úÂëµ½ GitLab£¬ÐèҪȷ±£Ô¶³Ìϵͳ£¬Ò²¾ÍÊÇ
GitLab ·þÎñÆ÷µÄÖ÷»úÃÜÔ¿ÒѾÔÚ Gerrit Óû§µÄ ~/.ssh/known_hosts ÎļþÖÐÁË¡£
Ê×ÏÈ£¬Èç¹û»¹Ã»ÓÐÉú³É¹ý SSH key µÄ»°£¬ÐèÒªÉú³É SSH Key£º
$
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/gerrit/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/gerrit/.ssh/id_rsa.
Your public key has been saved in /home/gerrit/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:idkrXgfm7oq+dNsWi9Q9ewDyZuQEYl8icA4ltq8o46U
gerrit@admins-B85-HD3-A
The key's randomart image is:
+---[RSA 2048]----+
| =oo |
| . *+ o . |
| ...+ + |
| . o++. |
| . oBSo |
| . . .oBo+ |
|+ ....o++o.+ |
|o.o. +.*o.. . |
| E .+.+++ . |
+----[SHA256]-----+
|
È»ºó½« SSK Key µÄ¹«Ô¿£¬¼´ ~/.ssh/id_rsa.pub
ÎļþµÄÄÚÈÝ£¬Ìí¼Óµ½ GitLab ÖоßÓÐȨÏÞµÄÓû§µÄ SSH key ÁбíÀï¡£
×î¼òµ¥µÄÌí¼ÓÖ÷»úÃÜÔ¿µÄ·½·¨ÊÇ£¬ÔÚÃüÁîÐÐÖÐÊÖ¶¯µØÁ¬½ÓÒ»´ÎÔ¶³Ìϵͳ£º
$
su -c 'ssh -p 22222 g.hz.netease.com echo' gerrit
ÃÜÂ룺
Permission denied (publickey).
|
ÉÏÃæµÄÔ¶³ÌµÇ¼ʧ°ÜÁË£¬µ«²»ÓùÜËü£¬Ô¶³ÌÖ÷»úµÄÃÜԿʵ¼ÊÉÏÒѾÌí¼Ó½ø
~/.ssh/id_rsa.pub ÎļþÀïÁË¡£
×¢Ò⣬Èç¹û GitLab µÄ SSH ·þÎñ²»ÊÇÔÚ±ê×¼µÄ 22 ¶Ë¿ÚÉÏÌṩµÄ£¬ÐèҪͨ¹ý
-p ²ÎÊý¸øÉÏÃæÖ´ÐÐµÄ ssh ÃüÁîÖ¸¶¨ SSH ·þÎñµÄ¶Ë¿ÚºÅ¡£GitLab µÄ SSH ·þÎñ¼àÌýµÄ¶Ë¿ÚºÅ£¬¿ÉÒÔ´ÓÏîÄ¿µÄ
URL Öп´³öÀ´ ¡ª¡ª SSH URL ÖÐÖ÷»úÃûºóÃæµÄðºÅÖ®ºóµÄÊǶ˿ںš£
»¹ÓÐÁíÍâÒ»ÖÖ·½·¨£¬Í¬Ñù¿ÉÒÔÓÃÀ´Ìí¼ÓÖ÷»úÃÜÔ¿£¬¼´Í¨¹ý ssh-keyscan
ÃüÁÏñÏÂÃæÕâÑù£º
$
ssh-keyscan -p 22222 -t rsa g.hz.netease.com
>> /home/gerrit/.ssh/known_hosts
# g.hz.netease.com:22222 SSH-2.0-OpenSSH_6.0p1
Debian-4+deb7u6
|
ͬÑùÐèҪעÒ⣬GitLab ²»ÊÇͨ¹ý±ê×¼ SSH ¶Ë¿Ú 22 À´Ìṩ
SSH ·þÎñµÄ»°£¬Í¨¹ý²ÎÊý -p Ϊ ssh-keyscan ÃüÁîÖ¸¶¨ GitLab ·þÎñÆ÷Ìṩ SSH
·þÎñµÄÕýÈ·¶Ë¿ÚºÅ¡£
½ÓÏÂÀ´£¬´´½¨ $site_path/etc/replication.config
Îļþ¡£ÕâÊÇÒ»¸ö Git
·ç¸ñµÄÅäÖÃÎļþ£¬ËüÓÃÀ´¿ØÖÆ replication ²å¼þµÄÉèÖá£Õâ¸öÎļþÓÉÒ»¸ö»ò¶à¸ö
remote ¶Î×é³É£¬Ã¿¸ö remote ¶Î¶¼ÎªÒ»¸ö»ò¶à¸öÄ¿±ê URIs Ìṩ¹«¹²ÅäÖÃÉèÖá£È磺
[remote
"g.hz.netease.com"]
url = ssh://git@g.hz.netease.com:22222/cloudgame/${name}.git
push = +refs/heads/*:refs/heads/*
push = +refs/tags/*:refs/tags/*
push = +refs/changes/*:refs/changes/*
timtout = 30
threads = 3
|
Èç¹û ~/.ssh/config Îļþ´æÔڵϰ£¬Gerrit ½«ÔÚÆô¶¯µÄʱ¶ÁÈ¡²¢»º´æËü£¬²¢Ö§³Ö´ó²¿·Ö
SSH ÅäÖÃÐò°¡Ï룬±ÈÈ磺
Host
g.hz.netease.com
User git
Port 22222
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
PreferredAuthentications publickey |
Õâ¸öÅäÖÃÎļþÖ§³ÖµÄÈ«²¿Ñ¡ÏîÈçÏ£º
Host
* Hostname
* User
* Port
* IdentityFile
* PreferredAuthentications
* StrictHostKeyChecking
|
ÐèҪעÒâµÄÊÇÕâ¸öÎļþµÄȨÏÞ£¬ÎļþµÄ ¡°ÆäËü¡± Óû§·ÃÎÊȨÏÞ£¬²»ÄܿɶÁд¡£
È»ºóÖØÐÂÆô¶¯ Gerrit Server£º
$
review_site/bin/gerrit.sh restart
|
»¹¿ÉÒÔͨ¹ýÈçÏÂÃüÁî£¬ÖØÐ¼ÓÔØ replication ²å¼þÀ´Ó¦ÓÃеÄÅäÖãº
$
ssh -p 29418 localhost gerrit plugin reload
replication
|
ÒªÔÚÔËÐÐʱÊÖ¶¯µØ´¥·¢ replication£¬¿ÉÒԲο¼ SSH ÃüÁî
start£º
ssh
-p @SSH_PORT@ @SSH_HOST@ @PLUGIN@ start |
±ÈÈ磺
$
ssh -p 29418 localhost replication start
|
replication ²å¼þÔÚÖ´Ðйý³ÌÖУ¬²úÉúµÄÈÕÖ¾ÎļþλÓÚ ~/review_site/logs/replication_log¡£µ±
replication ʧ°Üʱ£¬¿ÉÒÔ´ÓÕâ¸öÎļþÖÐÕÒµ½Ò»µãÏßË÷¡£Èç¹û Õâ¸öÈÕÖ¾ÖÐÌṩµÄÐÅÏ¢²»×㣬»¹¿ÉÒÔÐÞ¸Ä
replication µÄ´úÂ룬ÈÃËüÊä³ö¸ü¶àÈÕÖ¾£¬±àÒëËüµÄ´úÂ룬Ȼºó½«Éú³ÉµÄ jar Îļþ£¬Ìæ»» ~/review_site/plugins/replication.jar£¬²¢ÖØÆô
Gerrit Server¡£
Gerrit ¹¤³ÌµÄ´´½¨
ÓÃÇ°Ãæ´´½¨µÄ admin Óû§µÇ¼£¬Ëü½«×Ô¶¯»ñµÃ¹ÜÀíԱȨÏÞ£¬¿ÉÒÔÒÔÕâ¸öÓû§´´½¨¹¤³Ì¡£µÇ¼֮ºó£¬Ñ¡Ôñ
Projects -> Create New Project£º

ÔÚ Project Name: Ò»À¸ÊäÈ빤³ÌµÄÃû×Ö£¬²¢µã»÷ Create
Project °´Å¥¼´¿ÉÍê³É¹¤³ÌµÄ´´½¨¡£ÔÚ Gerrit µÄÅäÖÃÎļþ review_site/etc/gerrit.config
ÖУ¬basePath ¶¨ÒåÁËÕâЩ¹¤³ÌµÄλÖá£
ͬʱҪעÒ⣬¹¤³ÌÃû×ÖÒªÓë GitLab É϶ÔÓ¦µÄ¹¤³ÌÃû×ÖÏàͬ¡£
ÔÚ Gerrit ÉÏ´´½¨Á˹¤³ÌÖ®ºó£¬»¹ÐèÒªÓà GitLab ÉÏÒÑÓеĴúÂëÌæ»»
Gerrit ÖеĿչ¤³Ì£º
$
cd ~/review_site/GerritResource/
$ rm -rf cloudgame_tools.git/
$ git clone --bare ssh://git@g.hz.netease.com:22222/cloudgame
/cloudgame_tools.git
|
ÔÚ¹¤³ÌµÄÖ÷Ò³£¬¿ÉÒÔÕÒµ½ clone ¹¤³ÌµÄÃüÁî¡£Ö±½Ó¸´ÖÆÃüÁȻºó½«¹¤³Ì
clone µ½±¾µØ£º

ÏñÏÂÃæÕâÑù Clone Gerrit ÉϵŤ³Ì£º
$
git clone ssh://admin@review.virtcloudgame.com:29418/EventServer
&& scp -p -P 29418 admin@review.virtcloudgame.com:hooks/commit-msg
EventServer/.git/hooks/
Õý¿Ë¡µ½ 'EventServer'...
remote: Counting objects: 255, done
remote: Finding sources: 100% (255/255)
remote: Total 255 (delta 156), reused 255 (delta
156)
½ÓÊÕ¶ÔÏóÖÐ: 100% (255/255), 412.77 KiB | 0 bytes/s,
Íê³É.
´¦Àí delta ÖÐ: 100% (156/156), Íê³É.
¼ì²éÁ¬½Ó... Íê³É¡£
commit-msg
|
¸ù¾ÝÐèÒª£¬ÏñʹÓÃÆÕͨµÄ Git ¹¤³ÌÄÇÑù£¬Ð޸ĴúÂ룬commit£¬È»ºóͨ¹ýÈçÏÂÃüÁî
push ´úÂëµ½ Gerrit ½øÐÐ Code Review£º
git
push Ô¶³ÌµØÖ· ±¾µØ·ÖÖ§:refs/for/Ô¶³Ì·ÖÖ§
|
È磺
$
git push origin master:refs/for/master
¶ÔÏó¼ÆÊýÖÐ: 3, Íê³É.
Delta compression using up to 8 threads.
ѹËõ¶ÔÏóÖÐ: 100% (2/2), Íê³É.
дÈë¶ÔÏóÖÐ: 100% (3/3), 329 bytes | 0 bytes/s, Íê³É.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1)
remote: Processing changes: new: 1, refs: 1,
done
remote:
remote: New Changes:
remote: http://review.virtcloudgame.com/12 Just
for test.
remote:
To ssh://admin@review.virtcloudgame.com:29418/EventServer
* [new branch] master -> refs/for/master
|
ÔÚ Gerrit ÉϽ«¿´µ½¸Õ¸ÕÌá½»µÄ´úÂ룺

Code Review ½áÊøÖ®ºó£¬Submit ´úÂ룬´úÂ뽫±»Ìá½»µ½
Gerrit µÄ Git ²Ö¿â£¬Í¬Ê±±»¸´ÖƵ½ GitLab µÄ¶ÔÓ¦²Ö¿âÖС£
|