日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Gitlab+Gerrit+Ldap+nginx+mysql 之Gerrit搭建与配置(一)

發布時間:2023/12/15 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Gitlab+Gerrit+Ldap+nginx+mysql 之Gerrit搭建与配置(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

公司之前一直用gitlab來存放項目代碼 ,目前因為業務需要(代碼bug太多)需要引入gerrit來進行code review。

最初用的是centos 7.4,但是安裝完成后,GerritResource中沒有ALL_Project.git和All_Users.git生成,日志中一直在報錯,反復裝了幾次后發現,在centos7上的兼容性不是太完美,所以采購了centos6.8 服務器進行安裝,還是比較順利的完成了安裝。

另外本文采用LDAP認證,LDAP的配置本文不做講解,參考其他文章。

已經在用:
gitlab-ce-9.3.3-ce.0.el7.x86_64
最新部署:
centos 6.8 x64
gerrit 2.15.6
nginx 1.10.2
mysql 5.6

1、建立專有帳戶
$ useradd gerrit -m -s /bin/bash
$ passwd gerrit ##本文密碼與用戶同名
$ su - gerrit

2、配置 Java 環境

[root@ao-internal02 ~]# java -version java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode) [root@ao-internal02 ~]#

3、從官網下載gerrit
https://www.gerritcodereview.com/
當前最新版本為 2.15.6。

4、安裝 MySQL

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)

6、安裝gerrit
把包傳到gerrit的家目錄,修改相關的權限 。通過如下命令安裝 Gerrit:

[gerrit@ao-internal02 ~]$ java -jar gerrit-2.15.6.war init -d review_site Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore*** Gerrit Code Review 2.15.6 *** *** Git Repositories *** Location of Git repositories [GerritResource]: **git 代碼倉庫的位置, 默認會在之前敲的init -d 目錄下新建一個GerritResource文件夾,這個選項用于配置 Gerrit 的 Git 倉庫的保存地址。上面的配置將創建 /home/gerrit/review_site/GerritResource 目錄用于保存 Gerrit 的 Git 倉庫。 *** SQL Database *** Database server type [mysql]: ##這里使用Mysql數據,默認是H2不太會用。 Server hostname [localhost]: 10.81.232.115 ##數據庫地址 Server port [(mysql default)]: 3306 ##數據庫端口 Database name [reviewdb]: ##數據庫名稱 Database username [gerrit]: ##數據庫用戶 Change gerrit's password [y/N]?] ##數據庫用戶的密碼*** Index *** Type [lucene/?]: ##默認*** User Authentication *** Authentication method [http/?]: ##使用哪種認證方式,這里使用ldap Get username from custom HTTP header [y/N]? ##默認 SSO logout URL : ##默認 Enable signed push support [y/N]? ##默認*** Review Labels *** Install Verified label [y/N]? ##默認*** Email Delivery *** SMTP server hostname [smtp.exmail.qq.com]: SMTP server port [465]: SMTP encryption [tls/?]: SMTP username [dr@baidu.com]: Change dr@baidu.com's password [y/N]? *** Container Process *** Run as [gerrit]: Java runtime [/usr/share/jdk1.8.0_151/jre]: Upgrade review_site/bin/gerrit.war [Y/n]? n*** SSH Daemon *** Listen on address [*]: Listen on port [29418]: *** HTTP Daemon *** Behind reverse proxy [Y/n]? Y ##是否使用反向代理 ,這是配置為是 Proxy uses SSL (https://) [y/N]? Subdirectory on proxy server [/]: Listen on address [*]: Listen on port [8080]: Canonical URL [http://gerrit.baidu.com/]: *** Cache *** *** Plugins *** ##以下這些插件要全部安裝上,不然后續很麻煩。 ##download-commands 尤其是這個插件,不安裝的是沒有clone地址的Installing plugins. Install plugin commit-message-length-validator version v2.15.6 [y/N]? Install plugin download-commands version v2.15.6 [y/N]? Install plugin hooks version v2.15.6 [y/N]? Install plugin replication version v2.15.6 [y/N]? Install plugin reviewnotes version v2.15.6 [y/N]? Install plugin singleusergroup version v2.15.6 [y/N]? Initializing plugins. No plugins found with init steps.*** Experimental features *** Enable any experimental features [y/N]? Initialized /data/gerrit/review_site [gerrit@ao-internal02 ~]$

##默認安裝完后服務是會啟動的。

##這里因為有調整,所以手工啟動服務了。 [root@ao-internal02 bin]# ./gerrit.sh start Starting Gerrit Code Review: OK [root@ao-internal02 bin]# [root@ao-internal02 bin]# netstat -antlop | grep 8082 tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN 16538/GerritCodeRev off (0.00/0/0) [root@ao-internal02 bin]#

監控日志輸出:

[gerrit@ao-gerrit01 logs]$ pwd /home/gerrit/review_site/logs [gerrit@ao-gerrit01 logs]$ tail -f error_log

排錯過程:
1、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

如果數據庫是主從,一定要在主庫上創建庫、用戶、授權。否則會報錯:

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 etc]$ more gerrit.config [gerrit]basePath = GerritResourceserverId = 5ae3e303-92dc-4823-8284-e21a14034f75canonicalWebUrl = http://gerrit.baidu.com/ [database]type = mysqlhostname = localhostdatabase = reviewdbusername = gerrit [noteDb "changes"]disableReviewDb = trueprimaryStorage = note dbread = truesequence = truewrite = true [index]type = LUCENE [auth]type = LDAPgitBasicAuthPolicy = LDAP [ldap]server = ldap://101.11.23.191:389username = cn=Manager,dc=baidu,dc=comaccountBase = dc=baidu,dc=comgroupBase = dc=baidu,dc=com [receive]enableSignedPush = false [sendemail]enable = truesmtpServer = smtp.exmail.qq.comsmtpServerPort = 587smtpEncryption = TLSsmtpUser = dr@baidu.comsmtpPass = 123456from = dr@baidu.com [container]user = gerritjavaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el6_10.x86_64/jre [sshd]listenAddress = *:29418 [httpd]listenUrl = http://*:8080/ [cache]directory = cache [gitweb]cgi = /var/www/git/gitweb.cgitype = gitweb [plugins]# allow install pluginallowRemoteAdmin = true [gerrit@ao-gerrit01 etc]$

后續配置:
1、在/review_gerrit/bin/gerrit.sh中實際代碼第一行加入
GERRIT_SITE=/home/gerrit/review_site

例如:

[root@ao-gerrit01 logs]# vim /review_gerrit/bin/gerrit.sh GERRIT_SITE=/home/gerrit/review_site #!/bin/shGERRIT_SITE = /home/gerrit/review_site

2、全局使用gerrit:
[root@ao-gerrit01 logs]# ln -s /home/gerrit/review_site/bin/gerrit.sh /usr/bin/gerrit
安裝插件:

[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 fatal: remote installation is disabled [gerrit@ao-gerrit01 ~]$

3、# 安裝復制插件

unzip gerrit-2.14.1.war ssh -p 29418 gerrit_admin_user@localhost gerrit plugin install -n replication.jar - < ./WEB-INF/plugins/replication.jar

#如果安裝時提示權限問題,要在gerrit.config 上添加 allowRemoteAdmin 參數,文件見下面

[plugins]# allow install pluginallowRemoteAdmin = true

重啟一下服務

[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]$

4、Gerrit部署成功后創建項目看不到clone地址
在gerrit部署成功后使用admin賬號登錄,完成管理員注冊流程,然后嘗試創建第一個項目。創建項目test,權限繼承ALL project,然后進入test,但是看不到clone地址。如下圖:

解決辦法:
安裝插件download-commands

5、添加key的時候報504

解決辦法:
確保gerrit.config中,郵箱配置是正確的。另外你的gerrit所在的機器是可以發送郵件的。我這里用的是postfix。配置完后,通過以下命令能收到郵件,即為正常
echo testmail| mail -s "testmail" dragon@baidu.com

6、代碼同步到gerrit后,開發者diff不了,一點就報錯,很憂傷 。如下圖:

解決辦法 :
nginx配置文件的配置問題:

proxy_pass http://gerrit_server/;
修改為
proxy_pass http://gerrit_server;

重啟nginx服務

7、

配置/home/gerrit/review_site/etc/replication.config,沒有的話新建:

URL這里目前只能寫多個了,嘗試使用了namespace無效。
就是倉庫沒辦法使用變量,當有新增的話 維護起來比較麻煩,
目前還沒有更好的解決辦法,哪位大佬給予指導。

轉載于:https://blog.51cto.com/zhaowl/2315989

總結

以上是生活随笔為你收集整理的Gitlab+Gerrit+Ldap+nginx+mysql 之Gerrit搭建与配置(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。