Skip to content

git gerrit 版本控制

yangyp8110 edited this page Jan 17, 2018 · 1 revision

git安装

先查看是否已经安装git(centos 7.X 的git版本是1.8)

[root@localhost ~]# git version
git version 1.8.3.1
[root@localhost ~]# yum remove git
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 93772.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  66 M RSS (382 MB VSZ)
    Started: Fri Mar 31 10:44:20 2017 - 07:31 ago
    State  : Traced/Stopped, pid: 93772

执行命令,释放yum

[root@localhost ~]# rm -f /var/run/yum.pid 
[root@localhost ~]#
[root@localhost ~]# yum remove git

删除成功后,安装git

1、安装所需软件包

[root@localhost ~] yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel 
[root@localhost ~] yum install gcc perl-ExtUtils-MakeMaker

2、下载&安装

[root@localhost ~]# cd /usr/local/soft-package
[root@localhost soft-package]# wget https://www.kernel.org/pub/software/scm/git/git-2.7.3.tar.gz
[root@localhost soft-package]# tar -zxvf git-2.7.3.tar.gz
[root@localhost git-2.7.3]# cd git-2.7.3
[root@localhost git-2.7.3]# mkdir /usr/local/install/git
[root@localhost git-2.7.3]# make prefix=/usr/local/install/git all
[root@localhost git-2.7.3]# make prefix=/usr/local/install/git install
[root@localhost git-2.7.3]# echo "export PATH=$PATH:/usr/local/install/git/bin" >> /etc/bashrc
[root@localhost git-2.7.3]# source /etc/bashrc
[root@localhost git-2.7.3]# cd /usr/local/install
[root@localhost install]# git --version
git version 2.7.3
[root@localhost install]# 

配置用户

  • 设置git的用户名和email:
[root@localhost install]# git config --global user.name 'yangyp8110'
[root@localhost install]# git config --global user.email yangyp8110@126.com
[root@localhost install]# cd ~/.ssh
-bash: cd: /root/.ssh: No such file or directory
[root@localhost install]#
  • 如果没有git仓库,可以初始化一个repository,后面gerrit安装时会用到
[root@localhost local]# git init --bare /usr/local/gitRepository/example.git
Initialized empty Git repository in /usr/local/gitRepository/example.git/
[root@localhost local]#
  • 生成ssh(可以不用配置,如果出现附录的 错误1,按此方法解决):
    • 不输入路径,默认保存地址/root/.ssh/id_rsa
    • 直接enter,不输入密码
      Enter passphrase (empty for no passphrase):   
      Enter same passphrase again:  
    
[root@localhost install]# ssh-keygen -t rsa -C 'yangyp8110@126.com'
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
9f:00:18:d7:fd:f2:5c:d8:14:ba:22:6c:98:c8:47:ca yangyp8110@126.com
The key's randomart image is:
+--[ RSA 2048]----+
|    . .. .    .. |
|     +  . .  ..  |
|    . o    ..+   |
|   o + =  . o.o  |
|    E + S .+..   |
|     . . + oo    |
|          o      |
|                 |
|                 |
+-----------------+
[root@localhost install]# 

最后得到了两个文件:id_rsa和id_rsa.pub

  • 复制~/.ssh/id_rsa.pub里的内容添加到github
    • 复制id_rsa.pub里面的全部内容
    • 打开github》settings》SSH and GPK keys》New SSH Key,粘贴保存

查看java版本,Centos 7.X 的version应该是 1.7 (安装jdk1.8请参考:jdk8

[root@localhost install]# java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
[root@localhost install]# 

安装MySQL(也可不装使用gerrit默认的h2也行)

安装gerrit

  • 先要做一下准备工作在mysql中配置一下gerrit要用的库
# 创建用户
mysql> create user 'gerrit001'@'localhost' identified by 'qwer123';
Query OK, 0 rows affected (0.11 sec)

# 创建gerrit要用的数据库
mysql> create database reviewdb;
Query OK, 1 row affected (0.02 sec)

# 设定编码为latin1, 中文不支持   设为utf8会有其它问题
mysql> alter database reviewdb charset=latin1;
Query OK, 1 row affected (0.24 sec)

# 把reviewdb的所有权限赋给gerrit001
mysql> grant all on reviewdb.* to 'gerrit001'@'localhost';
Query OK, 0 rows affected (0.12 sec)

# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.17 sec)
  • 新建 linux 用户 gerrit001,并切换到 gerrit001 用户
[root@localhost ~]# adduser gerrit001
[root@localhost ~]# su gerrit001
ABRT has detected 2 problem(s). For more info run: abrt-cli list
[gerrit001@localhost root]$ 
  • 下载Gerrit的java包(war包)
  • 安装

    注意事项

    • 我们安装的时候,可以只在 Authentication method 时输入 http ,其他全部回车用默认值,因为其他配置我们待会可以通过 etc/gerrit.config 文件进行修改
    • 期间可能会下载两个文件,这两个文件虽然都很小(不到3M),但是可能是因为GFW的原因,下载速度很慢。你可以到 /lib 文件夹下面查看他们是不是已经下载完了,或者你手动把那两个文件下载完之后,scp到 /lib 下面。
    • 在安装 http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar 时失败了,没关系,继续往下走,一路enter,直至安装成功。
    • 如果你发现已经下完了,但是安装过程卡主了,没有关系,直接 ctrl+c 然后重新安装就可以了。
# 在gerrit-2.11.2.war所在目录执行如下命令,如果不存目录gerrit_site,会自动创建目录gerrit_site
[gerrit001@localhost ~]$ java -jar gerrit-2.11.2.war init -d ~/gerrit_site
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11.2
*** 

Create '/home/gerrit001/gerrit_site' [Y/n]? 

*** Git Repositories
*** 

Location of Git repositories   [git]: 

*** SQL Database
*** 

Database server type           [h2]: 

*** Index
*** 

Type                           [LUCENE/?]: 

*** User Authentication
*** 

Authentication method          [OPENID/?]: http
Get username from custom HTTP header [y/N]? 
SSO logout URL                 : 

*** Review Labels
*** 

Install Verified label         [y/N]? 

*** Email Delivery
*** 

SMTP server hostname           [localhost]: 
SMTP server port               [(default)]: 
SMTP encryption                [NONE/?]: 
SMTP username                  : 

*** Container Process
*** 

Run as                         [gerrit001]: 
Java runtime                   [/usr/local/install/jdk1.8.0_111/jre]: 
Copy gerrit-2.11.2.war to /home/gerrit001/gerrit_site/bin/gerrit.war [Y/n]? 
Copying gerrit-2.11.2.war to /home/gerrit001/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]? 
Downloading http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar ... !! FAIL !!


error: http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar: 302 Found
Please download:

  http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar

and save as:

  /home/gerrit001/gerrit_site/lib/bcpkix-jdk15on-151.jar

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 reviewnotes version v2.11.2 [y/N]? 
Install plugin replication version v2.11.2 [y/N]? 
Install plugin download-commands version v2.11.2 [y/N]? 
Install plugin singleusergroup version v2.11.2 [y/N]? 
Install plugin commit-message-length-validator version v2.11.2 [y/N]? 
Initializing plugins.
No plugins found with init steps.

fatal: Could not switch to '/usr/local/install/git/etc/': No such file or directory
Initialized /home/gerrit001/gerrit_site
Executing /home/gerrit001/gerrit_site/bin/gerrit.sh start
Starting Gerrit Code Review: 
OK
Waiting for server on localhost:8080 ... OK
Opening http://localhost:8080/#/admin/projects/ ...OK
[gerrit001@localhost ~]$ 

默认配置安装完成了。

  • 下载失败处理方法:

    安装过程中会下载下面三个文件,也可以手工下载并拷贝到gerrit_site/lib目录中:

    • bcpkix-jdk15on-151.jar——可以在以后添加到gerrit_site/lib
    • bcprov-jdk15on-151.jar——可以在以后添加到gerrit_site/lib
    • mysql-connector-java-5.1.21.jar——可以在以后添加到gerrit_site/lib,使用mysql时必须安装
  • 启动gerrit:

[gerrit001@localhost gerrit_site]$ ./bin/gerrit.sh start 如果报错如下:

[gerrit001@localhost gerrit_site]$ ./bin/gerrit.sh start
Starting Gerrit Code Review: FAILED
[gerrit001@localhost gerrit_site]$ cat logs/error_log 
[2017-04-02 23:51:51,145] INFO  com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk
 cache /home/gerrit001/gerrit_site/cache[2017-04-02 23:51:52,636] INFO  com.google.gerrit.server.config.ScheduleConfig : gc schedule par
ameter "gc.interval" is not configured[2017-04-02 23:51:54,571] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher aes192-cbc: 
Illegal key size; try installing unlimited cryptography extension[2017-04-02 23:51:54,571] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher aes256-cbc: 
Illegal key size; try installing unlimited cryptography extension[2017-04-02 23:51:54,573] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher aes256-ctr: 
Illegal key size; try installing unlimited cryptography extension[2017-04-02 23:51:54,576] WARN  com.google.gerrit.sshd.SshDaemon : Disabling cipher arcfour256: 
Illegal key size or default parameters; try installing unlimited cryptography extension[2017-04-02 23:51:54,634] WARN  com.google.gerrit.httpd.GitWebConfig : gitweb not installed (no 
/usr/lib/cgi-bin/gitweb.cgi found)[2017-04-02 23:51:55,271] INFO  org.eclipse.jetty.util.log : Logging initialized @13471ms
[2017-04-02 23:51:58,007] INFO  com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaul
ting core.streamFileThreshold to 60m[2017-04-02 23:51:58,114] INFO  com.google.gerrit.server.plugins.PluginLoader : Loading plugins 
from /home/gerrit001/gerrit_site/plugins[2017-04-02 23:51:58,281] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) No index versions ready; run Reindex
……

[gerrit001@localhost ~]$ java -jar gerrit-2.11.2.war reindex
fatal: not a Gerrit site: '/home/gerrit001'
fatal: Perhaps you need to run init first?
[gerrit001@localhost ~]$ cd gerrit_site/
[gerrit001@localhost gerrit_site]$ java -jar ../gerrit-2.11.2.war reindex
[2017-04-02 23:55:38,910] INFO  com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaul
ting core.streamFileThreshold to 60m[2017-04-02 23:55:39,781] INFO  com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk
 cache /home/gerrit001/gerrit_site/cacheReindexing changes: done    
Reindexed 0 changes in 0.1s (0.0/s)
[2017-04-02 23:55:42,114] WARN  com.google.gerrit.server.cache.h2.H2CacheImpl : Cannot build Blo
omFilter for jdbc:h2:file:/home/gerrit001/gerrit_site/cache/diff_intraline: Error opening database: "Sleep interrupted" [8000-174][2017-04-02 23:55:42,115] INFO  com.google.gerrit.server.cache.h2.H2CacheFactory : Finishing 4 d
isk cache updates[gerrit001@localhost gerrit_site]$ 

启动成功:

[gerrit001@localhost gerrit_site]$ ./bin/gerrit.sh start
Starting Gerrit Code Review: OK
[gerrit001@localhost gerrit_site]$ 
  • 配置gerrit
    • gerrit可以使用H2,PostgreSQL,MySQL和Oracle数据库。
    • 参考配置:gerrit配置
Clone this wiki locally