5、創建數據庫、用戶、授權 這里選擇 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> 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)
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
如果數據庫是主從,一定要在主庫上創建庫、用戶、授權。否則會報錯:
Enable any experimental features [y/N]? Exception in thread "main" com.google.gwtorm.server.OrmException: Cannot apply SQL
CREATE TABLE account_group_id(s SERIAL)at com.google.gwtorm.jdbc.JdbcExecutor.execute(JdbcExecutor.java:44)at com.google.gwtorm.jdbc.JdbcSchema.createSequences(JdbcSchema.java:122)at com.google.gwtorm.jdbc.JdbcSchema.updateSchema(JdbcSchema.java:103)at com.google.gerrit.server.schema.SchemaCreator.create(SchemaCreator.java:84)at com.google.gerrit.server.schema.SchemaUpdater.update(SchemaUpdater.java:111)at com.google.gerrit.pgm.init.BaseInit$SiteRun.upgradeSchema(BaseInit.java:389)at com.google.gerrit.pgm.init.BaseInit.run(BaseInit.java:146)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:223)at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:119)at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:63)at Main.main(Main.java:24)
Caused by: java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statementat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)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:2490)at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2448)at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:845)at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:745)at com.google.gwtorm.jdbc.JdbcExecutor.execute(JdbcExecutor.java:42)... 15 more
[gerrit@ao-gerrit01 ~]$ gerrit restart
Stopping Gerrit Code Review: OK
Starting Gerrit Code Review: WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer.This may be caused by /usr/bin/gerrit not being run as root.Consider changing the OOM score adjustment manually for Gerrit's PID=6302 with e.g.:echo '-1000' | sudo tee /proc/6302/oom_score_adj
OK
[gerrit@ao-gerrit01 ~]$
安裝replication
[gerrit@ao-gerrit01 ~]$ ssh -i .ssh/id_rsa -p 29418 gerritadmin@localhost gerrit plugin install -n replication.jar - < gerrit-2.15.6/WEB-INF/plugins/replication.jar
[gerrit@ao-gerrit01 ~]$
查看
[gerrit@ao-gerrit01 etc]$ ssh -i .ssh/id_rsa -p 29418 gerritadmin@localhost gerrit plugin ls
Warning: Identity file .ssh/id_rsa not accessible: No such file or directory.
Name Version Status File
-------------------------------------------------------------------------------
replication v2.15.6 ENABLED replication.jar
[gerrit@ao-gerrit01 etc]$