之前整好了Ubuntu Server了,现在可以在Server上装好用的软件,为了便于代码管理,自然想到了svn,其实安装配置过程也很简单。
目的就是要通过命令行和web都能访问svn。以下命令都是以root用户执行的,如果是普通用户,可以在命令之前加上sudo。
1.安装apache2
apt-get install apache2
2.安装svn
apt-get install subversion
3.安装apache-svn
apt-get install libapache2-svn
4.配置svn
添加组
addgroup rd
把test用户加到rd组
usermod -G rd -a test
创建svn项目仓库
mkdir /home/svn
cd /home/svn
mkdir android
将android下的文件和目录的所有权交给rd组下的root用户
chown -R root:rd android
创建项目android
svnadmin create /home/svn/android
赋予用户组rd下的用户对于项目的权限
chmod g+rws android
到这里svn基本可以使用了,接下来就是要配置apache,让用户能用web访问svn项目
5.配置apache
修改成蓝色的样子,当然目录、文件什么的换成自己想要的
vim /etc/apache2/mods-available/dav_svn.conf
<Location /svn>
# Uncomment this to enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /home/svn
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache <Limit> and <LimitExcept>, also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.
# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Android Subversion Repository"
#AuthUserFile /etc/apache2/dav_svn.passwd
AuthUserFile /etc/subversion/passwd
# To enable authorization via mod_authz_svn
#AuthzSVNAccessFile /etc/apache2/dav_svn.authz
AuthzSVNAccessFile /etc/subversion/authz
# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>
上面的密码文件和授权文件都不存在,现在我们来创建他们
htpasswd -c /etc/subversion/passwd test
然后输入密码,以后再创建用户就不用加"-c"参数了,如果加了,就把之前的冲掉了。
vim /etc/subversion/authz
加入如下内容:
[groups]
rd = test
[android:/]
@rd = rw
最后重启apache:
/etc/init.d/apache2 restart
接着就可以用web访问svn了,在浏览器里输入:
http://svn ip address/svn/android
这样就可以使用svn了。
svn 常用的命令:
如果是在svn项目server上,
导入非工作目录到svn
svn import PATH file:///home/svn/trunk -m "comment"
check out 到工作目录
svn co file:///home/svn/trunk PATH
如果是在其他主机上,
导入非工作目录到svn
svn import PATH http://IP ADDRESS/svn/trunk -m "comment"
check out 到工作目录
svn co http://IP ADDRESS/svn/trunk PATH
工作目录下:
check in 到svn
svn ci FILE/PATH -m "modify something"
更新
svn up