Skip to content

gerrit 配置 MySQL

yangyp8110 edited this page Jan 17, 2018 · 1 revision

MySQL配置

  • 安装过程中遇到问题,可参考本文末尾问题与对应解决办法

配置gerrit使用MySQL

[gerrit001@localhost gerrit_site]$ vi etc/gerrit.config 
[gerrit]
	basePath = git
	canonicalWebUrl = http://localhost:8080/
[database]
	type = mysql
	hostname = localhost
	database = reviewdb
	username = gerrit001
	port = 3306
[index]
	type = LUCENE
[auth]
	type = HTTP
[sendemail]
	smtpServer = smtp.163.com
	smtpServerPort = 25
	smtpUser = yangyp8110@126.com
[container]
	user = gerrit001
	javaHome = /usr/local/install/jdk1.8.0_111/jre
[sshd]
	listenAddress = *:29418
[httpd]
	listenUrl = http://*:8080/
[cache]
	directory = cache
[gerrit001@localhost gerrit_site]$ 

配置mysql密码,在gerrit_site/etc/secure.config里添加如下配置:

[gerrit001@localhost gerrit_site]$ vi etc/secure.config 
[database]
	username = gerrit001
	password = qwer123
……
……

重新init下gerrit:(直接启动会报错)

[gerrit001@localhost gerrit_site]$ java -jar ../gerrit-2.11.2.war init -d /home/gerrit001/gerrit_site
[gerrit001@localhost gerrit_site]$ java -jar ../gerrit-2.11.2.war init -d /home/gerrit001/gerrit_siteUsing secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11.2
*** 


*** Git Repositories
*** 

Location of Git repositories   [git]: 

*** SQL Database
*** 

Database server type           [mysql]: 
Server hostname                [localhost]: 
Server port                    [3306]: 
Database name                  [reviewdb]: 
Database username              [gerrit001]: 
Change gerrit001's password    [y/N]? 

*** Index
*** 

Type                           [LUCENE/?]: 

The index must be rebuilt before starting Gerrit:
  java -jar gerrit.war reindex -d site_path

*** User Authentication
*** 

Authentication method          [HTTP/?]: http
Get username from custom HTTP header [y/N]? 
SSO logout URL                 : 
fatal: Could not switch to '/usr/local/install/git/etc/': No such file or directory

*** Review Labels
*** 

Install Verified label         [y/N]? 

*** Email Delivery
*** 

SMTP server hostname           [smtp.163.com]: 
SMTP server port               [25]: 
SMTP encryption                [NONE/?]: 
SMTP username                  [yangyp8110@126.com]: 
Change yangyp8110@126.com's password [y/N]? 

*** Container Process
*** 

Run as                         [gerrit001]: 
Java runtime                   [/usr/local/install/jdk1.8.0_111/jre]: 
Upgrade /home/gerrit001/gerrit_site/bin/gerrit.war [Y/n]? 
Copying gerrit-2.11.2.war to /home/gerrit001/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/]: 

*** Plugins
*** 

Installing plugins.
Install plugin reviewnotes version v2.11.2 [y/N]? 
Install plugin replication version v2.11.2 [y/N]? 
Install plugin download-commands version v2.11.2 [y/N]? 
Install plugin singleusergroup version v2.11.2 [y/N]? 
Install plugin commit-message-length-validator version v2.11.2 [y/N]? 
Initializing plugins.
No plugins found with init steps.

Initialized /home/gerrit001/gerrit_site
[gerrit001@localhost gerrit_site]$ 

gerrit配置mysql成功,登陆mysql可以看到reviewdb里创建了表:

mysql> use reviewdb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-----------------------------+
| Tables_in_reviewdb          |
+-----------------------------+
| account_diff_preferences    |
| account_external_ids        |
| account_group_by_id         |
| account_group_by_id_aud     |
| account_group_id            |
| account_group_members       |
| account_group_members_audit |
| account_group_names         |
| account_groups              |
| account_id                  |
| account_patch_reviews       |
| account_project_watches     |
| account_ssh_keys            |
| accounts                    |
| change_id                   |
| change_message_id           |
| change_messages             |
| changes                     |
| patch_comments              |
| patch_set_ancestors         |
| patch_set_approvals         |
| patch_sets                  |
| schema_version              |
| starred_changes             |
| submodule_subscriptions     |
| system_config               |
+-----------------------------+
26 rows in set (0.00 sec)

mysql> 

启动gerrit成功:

[gerrit001@localhost gerrit_site]$ ./bin/gerrit.sh start
Starting Gerrit Code Review: OK
[gerrit001@localhost gerrit_site]$ 

错误处理:

错误一 : Access denied for user 'gerrit001'@'localhost' (using password: NO)
  • 错误详细:
[gerrit001@localhost gerrit_site]$ cat logs/error_log
[2017-04-03 00:00:35,941] ERROR com.google.gerrit.httpd.auth.container.HttpLoginServlet : Unable
 to authenticate user by Authorization request header.  Check container or server configuration.[2017-04-03 00:01:23,461] INFO  com.google.gerrit.pgm.Daemon : caught shutdown, cleaning up
[2017-04-03 00:01:24,006] INFO  org.eclipse.jetty.server.ServerConnector : Stopped ServerConnect
or@12c78f36{HTTP/1.1}{0.0.0.0:8080}[2017-04-03 00:01:24,144] INFO  org.eclipse.jetty.server.handler.ContextHandler : Stopped o.e.j.
s.ServletContextHandler@3bb4c2b2{/,file:/home/gerrit001/gerrit_site/tmp/gerrit_4598146742162660786_app/gerrit_war/,UNAVAILABLE}[2017-04-03 00:01:24,589] INFO  com.google.gerrit.sshd.SshDaemon : Stopped Gerrit SSHD
[2017-04-03 00:16:48,170] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
com.google.gerrit.common.Die: Unable to determine SqlDialect
  caused by java.sql.SQLException: Access denied for user 'gerrit001'@'localhost' (using password: NO)
  • 解决办法:

    配置mysql服务密码


错误二 : Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Invalid default value for 'added_on'
  • 错误详细:
Exception in thread "main" com.google.gwtorm.server.OrmException: Cannot apply SQL
CREATE TABLE account_group_by_id_aud (
added_by INT DEFAULT 0 NOT NULL,
removed_by INT,
removed_on TIMESTAMP NULL DEFAULT NULL,
group_id INT DEFAULT 0 NOT NULL,
include_uuid VARCHAR(255) BINARY DEFAULT '' NOT NULL,
added_on TIMESTAMP NOT NULL
,PRIMARY KEY(group_id,include_uuid,added_on)
)
	at com.google.gwtorm.jdbc.JdbcExecutor.execute(JdbcExecutor.java:44)
	at com.google.gwtorm.jdbc.JdbcSchema.createRelations(JdbcSchema.java:119)
	at com.google.gwtorm.jdbc.JdbcSchema.updateSchema(JdbcSchema.java:89)
	at com.google.gerrit.server.schema.SchemaCreator.create(SchemaCreator.java:77)
	at com.google.gerrit.server.schema.SchemaUpdater.update(SchemaUpdater.java:99)
	at com.google.gerrit.pgm.init.BaseInit$SiteRun.upgradeSchema(BaseInit.java:339)
	at com.google.gerrit.pgm.init.BaseInit.run(BaseInit.java:120)
	at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:64)
	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:166)
	at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:93)
	at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:50)
	at Main.main(Main.java:25)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Invalid default value for 'added_on'
  • 解决办法:
    • 使用MySQL root用户登录,设置 set global explicit_defaults_for_timestamp=1;
    mysql> set global explicit_defaults_for_timestamp=1;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> flush privileges
    
    • 重新安装gerrit即可.
Clone this wiki locally