ubuntu 安装gerrit+nginx

gerrit 是目前android应用最广泛的代码review工具,由于是Java 后端开发,目前团队采用gerrit做代码审查。

系统环境如下:
Ubuntu 16
mysql 5.7
gerrit 2.15.2

下载gerrit
https://www.gerritcodereview.com/releases/README.md

配置gerrit用户
sudo adduser gerrit
sudo apt install mysql-server
sudo service mysql start
mysql -u root -p 输入密码登录

登录需要设置一下

mysql> set global explicit_defaults_for_timestamp=1;
Query OK, 0 rows affected (0.00 sec)

这个跟mysql 有关系, 在严格模式,’0000-00-00’不是合法日期,mysql 5.7 不接受月或日部分为0的日期。在非严格模式会产生警告。
如果没有指定默认值,那么会自动设置 DEFAULT ‘0000-00-00 00:00:00’属性,很显然这个不是合法的日期,会报如下异常:

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

设置
设置管理员密码
tpasswd -b -c /home/gerrit/review-site/etc/passwd admin admin

安装nginx

sudo apt install nginx
sudo service nginx restart

然后编辑nginx.conf文件vim /etc/nginx/nginx.conf,在http里面添加如下配置

   server {
            listen 8081;
            server_name localhost;
            auth_basic "Restricted";
            auth_basic_user_file /home/gerrit/gerrit.password;
            location / { 
                proxy_pass        http://127.0.0.1:8080;
                proxy_set_header  X-Forwarded-For $remote_addr;
                proxy_set_header  Host $host;
        }
      }  

注意点,如果打开localhost:8081报server error,那么极有可能是文件夹权限的原因,将review-site , gerrit.password 设置777

参考资料:

  1. Gerrit代码审核服务器搭建全过程
  2. MySQL 5.7中timestamp数据类型和explicit_defaults_for_timestamp参数+

你可能感兴趣的:(ubuntu 安装gerrit+nginx)