Gerrit安装配置

Gerrit安装

  1. 默认安装(不推荐

    rpm -i https://gerritforge.com/gerritforge-repo-1-2.noarch.rpm
    yum install -y gerrit

  2. war包安装
    可以在https://gerrit-releases.storage.googleapis.com/中查找自己需要的版本的Key,拼在utl后面得到下载地址。
    wget https://gerrit-releases.storage.googleapis.com/gerrit-2.14.2.war

    useradd gerrit 新建一个gerrit用户
    su gerrit 切换到gerrit用户
    java -jar gerrit*.war init -d ~/gerrit_site

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2017-08-17 10:50:16,724] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/gerrit_site/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 2.14.2
*** 

Create '/home/gerrit/gerrit_site' [Y/n]? y

*** 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.41
**  This library is required for your configuration. **
Download and install it now [Y/n]? y
Downloading https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.41/mysql-connector-java-5.1.41.jar ... OK
Checksum mysql-connector-java-5.1.41.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/?]: 

*** User Authentication
*** 

Authentication method          [OPENID/?]: HTTP
Get username from custom HTTP header [y/N]? 
SSO logout URL                 : 
Enable signed push support     [y/N]? 

*** Review Labels
*** 

Install Verified label         [y/N]? Y

*** Email Delivery
*** 

SMTP server hostname           [localhost]: smtp.163.com
SMTP server port               [(default)]: 
SMTP encryption                [NONE/?]: 
SMTP username                  [gerrit]: xxx@163.com
sz.lkl@163.com's password      : 
              confirm password : 

*** Container Process
*** 

Run as                         [gerrit]: 
Java runtime                   [/usr/java/jdk1.8.0_144/jre]: 
Copy gerrit-2.14.2.war to /home/gerrit/gerrit_site/bin/gerrit.war [Y/n]? 
Copying gerrit-2.14.2.war to /home/gerrit/gerrit_site/bin/gerrit.war

*** SSH Daemon
*** 

Listen on address              [*]: 
Listen on port                 [29418]: 
Generating SSH host key ... rsa... dsa... ed25519...unknown key type ed25519
 ecdsa 256... ecdsa 384... ecdsa 521... done

*** HTTP Daemon
*** 

Behind reverse proxy           [y/N]? Y
Proxy uses SSL (https://)      [y/N]? 
Subdirectory on proxy server   [/]: 
Listen on address              [*]: 
Listen on port                 [8081]: 8088
Canonical URL                  [http://admin.banklun.com/]: 

*** Cache
*** 


*** Plugins
*** 

Installing plugins.
Install plugin commit-message-length-validator version v2.14.2 [y/N]? y
Installed commit-message-length-validator v2.14.2
Install plugin download-commands version v2.14.2 [y/N]? y
Installed download-commands v2.14.2
Install plugin hooks version v2.14.2 [y/N]? y
Installed hooks v2.14.2
Install plugin replication version v2.14.2 [y/N]? y
Installed replication v2.14.2
Install plugin reviewnotes version v2.14.2 [y/N]? y
Installed reviewnotes v2.14.2
Install plugin singleusergroup version v2.14.2 [y/N]? y
Installed singleusergroup v2.14.2
Initializing plugins.

fatal: DbInjector failed
fatal: Unable to determine SqlDialect
fatal:   caused by java.sql.SQLException: Access denied for user 'gerrit'@'localhost' (using password: YES)
[gerrit@admin ~]$ mysql -u gerrit -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'gerrit'@'localhost' (using password: YES)

注意:要搭建CI系统,这里需要选择安装 Label Verified

vim /etc/profile 配置环境变量

export GERRIT_HOME=/home/gerrit/gerrit_site
export PATH=$NGINX_HOME/sbin:$GERRIT_HOME/bin:$PATH

Gerrit-webview安装

查看代码需要用到的
yum -y install gitweb
vim /etc/gitweb.conf

  1 # The gitweb config file is a fragment of perl code. You can set variables
  2 # using "our $variable = value"; text from "#" character until the end of a
  3 # line is ignored. See perlsyn(1) man page for details.
  4 #
  5 # See /usr/share/doc/gitweb-*/README and /usr/share/doc/gitweb-*/INSTALL for
  6 # more details and available configuration variables.
  7 
  8 # Set the path to git projects.  This is an absolute filesystem path which will
  9 # be prepended to the project path.
 10 #our $projectroot = "/var/lib/git";
 11 $projectroot = "/home/gerrit/gerrit_site/git";

$projectroot设置为Location of Git repositories的路径,安装Gerrit时指定的。

配置

mysql添加gerrit用户及数据库

  • 查看用户表
    select user,password,host from mysql.user;
  • 插入新的用户
    insert into mysql.user(Host,User,Password) values("localhost","gerrit",password("gerrit"));
  • 创建gerrit所要使用的数据库
    create databasegerritdbdefault character set utf8 collate utf8_general_ci;
    flush privileges; //创建完成后一定要刷新一下,不然不生效
  • 设置gerrit用户对gerritdb的操作权限
    grant all privileges on gerritdb.* to gerrit@’localhost’ identified by ‘vhost’ with grant option;
    SHOW GRANTS FOR gerrit@’localhost’; //验证结果
+---------------------------------------------------------------------------------------------------------------+
| Grants for gerrit@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'gerrit'@'localhost' IDENTIFIED BY PASSWORD '*AD8354BBE56D9AF515F3FC9A5CCB80E3483BA3E6' |
| GRANT ALL PRIVILEGES ON `gerritdb`.* TO 'gerrit'@'localhost' WITH GRANT OPTION                                |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

配置完成后一定要先用gerrit登录验证一下是否可以登录成功,这一步很关键
mysql -u gerrit -p
可能会出现登录不成功的情况,可以用root用户登录后重置一下gerrit用户的密码再试
SET PASSWORD FOR 'gerrit'@'localhost' = PASSWORD('gerrit');

gerrit.config文件配置

vim /etc/gerrit/gerrit.config

  1 [gerrit]
  2         basePath = git
  3         serverId = ab8a6c3f-90b0-47b5-ac81-eed3d584c7b9
  4         canonicalWebUrl = http://xxx:8088/
  5 [database]
  6         type = mysql
  7         hostname = localhost
  8         database = gerritdb
  9         username = gerrit
 10 [index]
 11         type = LUCENE
 12 [auth]
 13         type = HTTP
 14 [receive]
 15         enableSignedPush = false
 16 [sendemail]
 17         smtpServer = smtp.163.com
 18         smtpUser = xxx@163.com
 19         from = xxx@163.com
 20         smtpPass = ******
 21 #       smtpServer = localhost
 22 [container]
 23         user = gerrit
 24         javaHome = /usr/java/jdk1.8.0_144/jre
 25 [sshd]
 26         listenAddress = *:29418
 27 [httpd]
 28         listenUrl = proxy-http://*:8088/
 29 [cache]
 30         directory = cache
 31 [gitweb]
 32         type = gitweb
 33         cgi = /var/www/git/gitweb.cgi

主要是增加了[gitweb],其他的在安装时已经默认配置好了,不过也可以修改,修改最多的就是httpd中的监听端口号,可以根据实际需求来变更。

Nginx反向代理配置

Nginx的安装配置:http://blog.csdn.net/lkl22/article/details/77244237

vim /usr/local/nginx/conf/vhost/gerrit.conf

server {
     #网址访问时的端口号
     listen *:8089;
     server_name gerrit.microwu.com;
     allow   all;
     deny    all;

     auth_basic "Welcomme to Gerrit Code Review Site!";
     #反向代理认证登录验证文件的路径,里面存储了用户名、密码
     auth_basic_user_file /home/gerrit/gerrit_site/htpasswd.conf; 

     location / { 
        #8088为gerrit的监听端口
        proxy_pass  http://127.0.0.1:8088;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
     }   
}

htpasswd指令配置登录用户名、密码

安装工具
yum install -y httpd-tools

cd /home/gerrit/gerrit_site/
创建用户、密码
htpasswd -c htpasswd.conf admin
添加/修改用户、密码
htpasswd -m htpasswd.conf admin

修改文件权限,不然用户登录会报500 Internal Server Error
chmod 755 /home/gerrit/
chmod 755 /home/gerrit/gerrit_site/htpasswd.conf

配置gitweb的反向代理

使用的是apache代理
vim /etc/httpd/conf.d/gitweb.conf

#
# gitweb
#
Alias /gitweb "/var/www/git"
<Directory "/var/www/git">
    Options +ExecCGI
    AddHandler cgi-script .cgi
    DirectoryIndex index.cgi gitweb.cgi
    Order allow,deny
    Allow from all
</Directory>
  • 开机自动启动apache代理
    systemctl enable httpd

设置开机自动启动

sudo ln -s etc/gerrit.config /etc/init.d/gerrit
sudo ln -snf /etc/init.d/gerrit /etc/rc2.d/S90gerrit
sudo ln -snf /etc/init.d/gerrit /etc/rc3.d/S90gerrit


启动、停止、重启

配置好环境变量,可以直接通过下面的指令来启动、停止、重启gerrit
gerrit.sh start
gerrit.sh stop
gerrit.sh restart


常见问题

  • ./bin/gerrit.sh: line 175: cd: /var/gerrit: No such file or directory
    ERROR: Gerrit site /var/gerrit not found
    vim /etc/default/gerritcodereview
    GERRIT_SITE=/home/gerrit/gerrit_site
    GERRIT_SITE指定为安装时指定的路径

  • 500 Internal Server Error
    可以通过nginx代理的错误日志查看原因
    vim /usr/local/nginx/logs/error.log

  • 查看错误日志
    vim /home/gerrit/gerrit_site/logs/error_log

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值