天天看點

CI持續內建環境搭建(5)--gerrit的安裝與配置1. gerrit的安裝2. gerrit的配置3. Nginx反向代理配置4. 建立認證權限(也就是登陸gerrit的時候輸入的使用者)5. 配置gitweb6. Issues

1. gerrit的安裝

前提:已安裝好java環境,mysql環境,nginx環境

1) 建立gerrit資料庫,并自定義編碼為utf8

# mysql -u root 
mysql>create database gerritdb CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql>grant all on gerritdb.* to 'gerrit'@'localhost' identified by 'gerritpass';
**Note**: gerritpass是密碼
           

2)建立使用者gerrit

# useradd gerrit
# passwd gerrit
           

3) 下載下傳gerrit war包,到目錄/home/gerrit/

下載下傳link : 

https://www.gerritcodereview.com/2.16.html

下載下傳版2.16.6

4) 切換到使用者gerrit, 安裝gerrit

java -jar gerrit-2.16.6.war init -d ~/gerrit_site
           

除了選用mysql資料庫,Verified,http認證代理,下載下傳mysql-connector-java-5.1.10.jar,bcpkix-jdk15on-151.jar 其他的都是預設!

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.16.6

*** Git Repositories

Location of Git repositories [git]:

*** SQL Database

Database server type [h2]: mysql

Gerrit Code Review is not shipped with MySQL Connector/J 5.1.21

** This library is required for your configuration. **

Download and install it now [Y/n]? Y

Renaming mysql-connector-java-5.1.10.jar to .mysql-connector-java-5.1.10.jar.backupDownloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar … OK

Checksum mysql-connector-java-5.1.21.jar OK

Server hostname [localhost]:

Server port [(mysql default)]:

Database name [reviewdb]: gerritdb

Database username [gerrit]: gerrit

gerrit’s password :

confirm password :

*** Index

Type [LUCENE/?]:

The index must be rebuilt before starting Gerrit:

java -jar gerrit.war reindex -d site_path

*** User Authentication

Authentication method [OPENID/?]: http

Get username from custom HTTP header [y/N]?

SSO logout URL :

*** Review Labels

Install Verified label [y/N]? y

*** Email Delivery

SMTP server hostname [localhost]:

SMTP server port [(default)]:

SMTP encryption [NONE/?]:

SMTP username :

*** Container Process

Run as [gerrit]:

Java runtime [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.el6.x86_64/jre]:

Copy gerrit-2.16.6.war to /home/gerrit/gerrit_site/bin/gerrit.war [Y/n]?

Copying gerrit-2.16.6.war to /home/gerrit/gerrit_site/bin/gerrit.war

*** SSH Daemon

Listen on address [*]:

Listen on port [29418]:

Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v151

If available, Gerrit can take advantage of features

in the library, but will also function without it.

Download and install it now [Y/n]? y

Renaming bcpkix-jdk15on-1.52.jar to .bcpkix-jdk15on-1.52.jar.backupDownloading http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar … OK

Press enter to continue

Continue without this library [Y/n]?

Generating SSH host key … rsa(simple)… done

*** 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 download-commands version v2.11.3 [y/N]?

Install plugin reviewnotes version v2.11.3 [y/N]?

Install plugin singleusergroup version v2.11.3 [y/N]?

Install plugin replication version v2.11.3 [y/N]?

Install plugin commit-message-length-validator version v2.11.3 [y/N]?

Initializing plugins.

No plugins found with init steps.

Initialized /home/gerrit/gerrit_site

2. gerrit的配置

1)切換到root, 修改/home/gerrit/gerrit_site/etc/gerrit.config配置檔案

将gerrit端口改為8082,因為預設端口8080被tomcat占用。

canonicalWebUrl = http://${centosip}:8082/

[httpd]

listenUrl = http://*:8082/

2) 啟動gerrit

# /home/gerrit/gerrit_site/bin/gerrit.sh start
           

Starting Gerrit Code Review: OK

檢視gerrit占用端口:

netstat -ltpn | grep -i gerrit
           
CI持續內建環境搭建(5)--gerrit的安裝與配置1. gerrit的安裝2. gerrit的配置3. Nginx反向代理配置4. 建立認證權限(也就是登陸gerrit的時候輸入的使用者)5. 配置gitweb6. Issues

3) 設定gerrit開機啟動

未完待續

3. Nginx反向代理配置

https://blog.csdn.net/Coder80/article/details/48176559

a. 在root使用者下面,輸入下面的指令:

# cd /etc/nginx/conf.d
           

建立一個 gerrit.conf 檔案,用來處理gerrit的反向代理, 配置如下内容:

server {

listen 88;

server_name localhost;

location / {

auth_basic “Gerrit Code Review”;

auth_basic_user_file /home/gerrit/review2/etc/passwords;

proxy_pass http://127.0.0.1:8082;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Host $host;

}

}

b. 重新開機nginx, gerrit服務, 檢視端口占用:

CI持續內建環境搭建(5)--gerrit的安裝與配置1. gerrit的安裝2. gerrit的配置3. Nginx反向代理配置4. 建立認證權限(也就是登陸gerrit的時候輸入的使用者)5. 配置gitweb6. Issues

4. 建立認證權限(也就是登陸gerrit的時候輸入的使用者)

注意:第一次加-c參數是為了建立密碼檔案,預設第一個使用者是系統管理者

htpasswd -c /home/gerrit/gerrit_site/etc/passwords  gerrit
htpasswd /home/gerrit/gerrit_site/etc/passwords jenkins
           

檢視下認證賬号檔案資訊

cat /home/gerrit/gerrit_site/etc/passwords
           

重新開機nginx服務

nginx -s reload
           

可通過http://ip:88 和http://ip:8082打開gerrit頁面, 用gerrit登入(管理者):

note: 必須先用88端口打開gerrit, 否則會報Configuration error的錯

5. 配置gitweb

在前面章節已經安裝了gitweb, 下面對gitweb進行配置:

git config --file /home/gerrit/review2/etc/gerrit.config gitweb.cgi /var/www/git/gitweb.cgi 
git config --file /home/gerrit/review2/etc/gerrit.config --unset gitweb.url
           

重新開機gerrit,然後登陸gerrit後,gitweb超連結效果就有了

6. Issues

issue 1: xxx is not in the sudoers file.This incident will be reported

solution:

1.切換到root使用者下

2./etc/sudoers檔案預設是隻讀的,對root來說也是,是以需先添加sudoers檔案的寫權限,指令是:

chmod u+w /etc/sudoers

3.編輯sudoers檔案

vi /etc/sudoers

找到這行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (這裡的xxx是你的使用者名)

ps:這裡說下你可以sudoers添加下面四行中任意一條

youuser ALL=(ALL) ALL

%youuser ALL=(ALL) ALL

youuser ALL=(ALL) NOPASSWD: ALL

%youuser ALL=(ALL) NOPASSWD: ALL

第一行:允許使用者youuser執行sudo指令(需要輸入密碼).

第二行:允許使用者組youuser裡面的使用者執行sudo指令(需要輸入密碼).

第三行:允許使用者youuser執行sudo指令,并且在執行的時候不輸入密碼.

第四行:允許使用者組youuser裡面的使用者執行sudo指令,并且在執行的時候不輸入密碼.

Issue 2: Starting Gerrit Code Review: FAILED

https://www.cnblogs.com/kevingrace/p/5624122.html

檢視log , /home/gerrit/review2/logs/error_log

issue 3: fatal: caused by java.sql.SQLException: Access denied for user ‘gerrit’@‘localhost’ (using password: YES)

Solution:

a. Please make user you can login to mysql with command: mysql -u gerrit -p

If it shows Access denied for user ‘gerrit’@‘localhost’ (using password: YES)

b. Please update the password for gerrituser:

mysqladmin -ugerrit -p o l d p a s s w o r d p a s s w o r d ′ oldpassword password ' oldpasswordpassword′newpassword’

such as :

mysqladmin -ugerrit -pgerrit123 password gerrit123!

Then, it should be ok to login to mysql with the newpassword

Issue 4: htpasswd: command not found

Solution:

yum install -y httpd
           

Issue 5: Configuration Error: Check the HTTP server’s authentication settings.

Solution:

https://blog.csdn.net/Coder80/article/details/48176559

gerrit和nginx占用了相同的端口号80

修改nginx監聽端口:

Gerrit: 8082

Nginx:80

Nginx監聽gerrit:88 (反向代理)

issue 6: 啟動nginx失敗 bind() to 0.0.0.0:8088 failed (13: Permission denied)

Solution:

nginx -c /etc/nginx/nginx.conf
           

issue 7: The branch ‘master’ does not exist on the given remote ‘gerrit’. If

these changes are intended to start a new branch, re-run with the ‘-R’

option enabled.

Solution:

the failed caused by the creating project in gerrit with non-empty project

issue 8: mysqladmin: connect to server at ‘localhost’ failed

Solution:

https://blog.csdn.net/zl17/article/details/8589454

use mysql;

update user set password=PASSWORD(“gerrit123!”)where user=“gerrit”;

更改密碼為 newpassord

flush privileges; 更新權限

quit 退出

issue 9: the command failed for failed: grant all on gerritdb.* to ‘gerrit’@‘slave1’ identified by ‘gerritpass’;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘gerritpass’’ at line 1

Solution:

https://blog.csdn.net/li_0891/article/details/80915780

issue10: install gerrit failed, "Unable to load authentication plugin ‘caching_sha2_password’."

fatal: DbInjector failed

fatal: Unable to determine SqlDialect

fatal: caused by java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password’.

Solution:

https://zhuanlan.zhihu.com/p/48263574

一、建立了一個新使用者,并指定加密規則為mysql_native_password:

CREATE USER ‘your username’@’%’ IDENTIFIED WITH mysql_native_password BY 'your password;

或者修改使用者加密方式

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘root’;

二、将預設密碼規則設定為mysql_native_password,重新整理權限并重置root密碼。

default_authentication_plugin=mysql_native_password

issue 11: install gerrit failed, “Unknown system variable ‘tx_isolation’”

Solution:

Update jdbc version to 8.x.x as mysql is updated to 8.x.x

that is : mysql-connector-java-8.0.xx.jar

issue 12: install gerrit failed: Loading class

com.mysql.jdbc.Driver'. This is deprecated. The new driver class is

com.mysql.cj.jdbc.Driver’.

Solution:

Download the latest version of gerrit, such as gerrit-3.0.1.war, which use mysql-connector-8.0.x.jar

繼續閱讀