CI持续集成环境搭建(5)--gerrit的安装与配置

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

在这里插入图片描述

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服务, 查看端口占用:
在这里插入图片描述

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 ' 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 iscom.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

发布了13 篇原创文章 · 获赞 2 · 访问量 2614

猜你喜欢

转载自blog.csdn.net/a10703060237/article/details/89708186