您的位置:首页 > 其它

Git+Gerrit学习搭建笔记

2014-11-27 22:31 369 查看
Git是目前最流行的分布式版本控制系统,而Gerrit是一种免费、开放源代码的代码审查软件,使用网页界面。利用浏览器,同一个团队的软件程序员,可以相互审阅彼此修改后的程序代码,决定是否能够提交,退回或者继续修改。它使用Git作为底层版本控制系统。趁着做测试的机会,简单学习了解一下Git+Gerrit是如何搭建使用的,顺便简单做个小笔记。
系统环境:Ubuntu12.04 Server 64
安装Git
$sudo su - ##切换到root账户环境下(个人习惯)
#apt-get update
#apt-get install git-core ##一条命令就可以吧Git搞定了~
# git --help ##Git的相关命令
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-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账号是管理员账号~
有问题多多指教,希望能和大家多学习多交流。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git gerrit