Git+Gerrit學習搭建筆記

    Git是目前最流行的分佈式版本控制系統,而Gerrit是一種免費、開放源代碼的代碼審查軟件,使用網頁界面。利用瀏覽器,同一個團隊的軟件程序員,能夠相互審閱彼此修改後的程序代碼,決定是否可以提交,退回或者繼續修改。它使用Git做爲底層版本控制系統。趁着作測試的機會,簡單學習瞭解一下Git+Gerrit是如何搭建使用的,順便簡單作個小筆記。html

     系統環境:Ubuntu12.04 Server 64java

安裝Gitmysql

$sudo su -           ##切換到root帳戶環境下(我的習慣)git

#apt-get update程序員

#apt-get install git-core             ##一條命令就能夠吧Git搞定了~sql

# git --help                        ##Git的相關命令數據庫

usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]vim

           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]瀏覽器

           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]oracle

           [-c name=value] [--help]

           <command> [<args>]


The most commonly used git commands are:

   add        Add file contents to the index

   bisect     Find by binary search the change that introduced a bug

   branch     List, create, or delete branches

   checkout   Checkout a branch or paths to the working tree

   clone      Clone a repository into a new directory

   commit     Record changes to the repository

   diff       Show changes between commits, commit and working tree, etc

   fetch      Download objects and refs from another repository

   grep       Print lines matching a pattern

   init       Create an empty git repository or reinitialize an existing one

   log        Show commit logs

   merge      Join two or more development histories together

   mv         Move or rename a file, a directory, or a symlink

   pull       Fetch from and merge with another repository or a local branch

   push       Update remote refs along with associated objects

   rebase     Forward-port local commits to the updated upstream head

   reset      Reset current HEAD to the specified state

   rm         Remove files from the working tree and from the index

   show       Show various types of objects

   status     Show the working tree status

   tag        Create, list, delete or verify a tag object signed with GPG

安裝Gerrit

Gerrit是由Java開發的,被封裝爲一個war包,因此須要Java環境。

#java --version                ##看一下Java是否被安裝配置好

默認安裝的OpenJDK,可是當時的同事說推薦仍是用Oracle JDK,使用最新的穩定版本 Oracel JDK7

安裝配置Oracel JDK7

#apt-get install oracle-java7-installer

#update-alternatives --config java

#vim /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

#source /etc/environment

#echo $JAVA_HOME

安裝配置Mysql數據庫

這裏也可使用H2或者PostgreSQL數據庫均可以。

#apt-get install mysql-server                 ##默認密碼爲空,記得爲root設置一個密碼,可使用mysqladmin命令來設置

#mysql -u root  -p

mysql>CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'password';

mysql>CREATE DATABASE reviewdb;

mysql>ALTER DATABASE reviewdb charset=latin1;

mysql>GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';

mysql>FLUSH PRIVILEGES;

建立gerrit2帳戶並下載初始化配置Gerrit

我下載的是gerrit-2.7-rcl.war

#adduser gerrit2                  ##建立gerrit2帳戶

#sudo su gerrit2

由於我都已經初始化設置過Gerrit,因此下面的顯示結果是我又從新再執行一次命令以後的顯示結果:

$java -jar gerrit-2.7-rc1.war init  -d  ~/gerrit_testsite


*** Gerrit Code Review 2.7-rc1

*** 

*** Git Repositories

*** 

Location of Git repositories   [test]:     ##指定Git庫的位置,test就是Git的庫的位置

*** SQL Database

*** 

Database server type           [mysql]: 

Server hostname                [127.0.0.1]: 

Server port                    [3306]: 

Database name                  [reviewdb]:                ##指定以前建立的數據庫

Database username              [gerrit2]: 

Change gerrit2's password      [y/N]? 

*** User Authentication

*** 

Authentication method          [LDAP/?]:                      ##使用Windos AD域控做爲認證

LDAP server                    [ldap://10.100.2.75]: 

LDAP username                  [gerrit]: 

Change gerrit's password       [y/N]? 

Account BaseDN                 [dc=test,dc=com]: 

Group BaseDN                   [dc=test,dc=com]: 

*** Email Delivery

*** 

SMTP server hostname           [localhost]: 

SMTP server port               [(default)]: 

SMTP encryption                [NONE/?]: 

SMTP username                  : 

*** Container Process

*** 

Run as                         [gerrit2]: 

Java runtime                   [/usr/lib/jvm/java-7-oracle]: 

Upgrade /home/gerrit2/gerrit_testsite/bin/gerrit.war [Y/n]? 

Copying gerrit.war to /home/gerrit2/gerrit_testsite/bin/gerrit.war

*** SSH Daemon

*** 

Listen on address              [*]: 

Listen on port                 [29418]: 

*** HTTP Daemon

*** 

Behind reverse proxy           [Y/n]? 

Proxy uses SSL (https://)      [y/N]? 

Subdirectory on proxy server   []: 

Listen on address              [10.100.2.201]: 

Listen on port                 [8080]: 

Canonical URL                  [http://10.100.2.201:8080]: 

*** Plugins

*** 

Prompt to install core plugins [y/N]? y

Install plugin reviewnotes version 2.7-rc1 [y/N]? y

version 2.7-rc1 is already installed, overwrite it [y/N]? y

Install plugin commit-message-length-validator version 2.7-rc1 [y/N]? y

version 2.7-rc1 is already installed, overwrite it [y/N]? y

Install plugin replication version 2.7-rc1 [y/N]? y

version 2.7-rc1 is already installed, overwrite it [y/N]? y

Initialized /home/gerrit2/gerrit_testsite

$cd /home/gerrit2/gerrit_testsite/bin/

$./gerrit.sh   start    ##可使用它自帶的腳原本啓動和中止Gerrit服務

$cd /home/gerrit2/gerrit_testsite/etc          ##上面的一些配置能夠在這裏再作修改

登錄訪問Gerrit

打開瀏覽器使用測試機域控制器上的test帳號就能夠登錄訪問Gerrit了

在Web上面就能夠直接建立項目,管理權限之類的,還在學習中~

第一次登錄Gerrit帳戶的AD帳號是管理員帳號~

有問題多多指教,但願能和你們多學習多交流。

相關文章
相關標籤/搜索