ubuntu-12.0.4安装svn
1.安装subversion
sudo apt-get install subversion2.添加svn管理用户及subversion组
$ sudo adduser svnuser$ sudo addgroup subversion
$ sudo addgroup svnuser subversion
3.建立项目
cd /home/svnuser$ sudo mkdir test
$ sudo chown -R root:subversion test
$ sudo chmod -R g+rws test
svnadmin create /home/svnuser/test/
4.test文件描述
在LK中可以看到conf文件夹,可针对conf文件夹中的authz、passwd、svnserve.conf进行设置,svnserve.conf主要设置整体的安全策略,passwd则设置用户名和密码,authz则是设置具体的用户有什么权限。
5.导入,导出
svn import -m "New import" /work/newa/ file:///home/svnuser/test/svn co file:///home/svnuser/test/ /root/桌面/a
* 注意:
如果您并不确定主机的名称,您必须使用三个斜杠(///),而如果您指定了主机的名称,则您必须使用两个斜杠(//).
6.访问权限设置
svnserve.conf 、passwd 、authz三个文件,行最前端不允许有空格//--
6.1 编辑svnserve.conf文件
把如下两行取消注释password-db = password
authz-db = authz
//补充说明
# [general]
anon-access = read
auth-access = write
password-db = passwd
其中 anon-access 和 auth-access 分别为匿名和有权限用户的权限
,默认给匿名用户只读的权限,但如果想拒绝匿名用户的访问,只需把 read 改成 none 就能达到目的。
6.2 编辑passwd
如下:[users]
elvis = 123456
user1 = 123456
user2 = 123456
6.3 编辑authz
如下:[groups]
admin = elvis,user1
test = user2
[/]
@admin=rw
*=r
这里设置了三个用户elvis,user1,user2密码都是123456
其中elvis和user1属于admin组,有读和写的权限,user2属于test组只有读的权限
7.确定svnserve启动
netstat -ntlp,可看到svn对应的端口3690(如果没有看见,则证明服务未启动,可使用svnserve -d启动svn服务,还可以通过svnserve -d -r /home/svnuser来指定启动目录)
停止svnserve:killall svnserve
启动svnserve: svnserve -d -r /home/svnuser
描述说明:
-d 表示svnserver以“守护”进程模式运行
-r 指定文件系统的根位置(版本库的根目录),这样客户端不用输入全路径,就可以访问版本库
可通过file:///home/svnuser/test/方式访问,也可以通过svn://localhost/test(局域网内可以通过ip访问)
8.搭建apache
8.1 安装 libapache2-svn
apt-get install libapache2-svn8.2 添加apache用户到subversion组
把apache 用户www-data添加到 subversionusermod -G subversion -a www-data
8.3 配置 /etc/apache2/mods-available/dav_svn.conf
在最后加上<Location /svn>
#enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /home/svn/vod
# 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.
#用这个,以便放多个repository
SVNParentPath /home/svnuser
# 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 "Subversion Repository"
#指定基本用户验证的密码文件存放位置
AuthUserFile /etc/subversion/dav_svn.passwd
# To enable authorization via mod_authz_svn
#mod_authz_svn配置文件的位置
AuthzSVNAccessFile /etc/subversion/dav_svn.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>
8.4 添加用户到apache
sudo htpasswd -c /etc/subversion/dav_svn.passwd user_name它会提示你输入密码,当您输入了密码,该用户就建立了。“-c”选项表示创建新的/etc/subversion/dav_svn.passwd 文件
,所以user_name所指的用户将是文件中唯一的用户。如果要添加其他用户,则去掉“-c”选项即可:
sudo htpasswd /etc/subversion/dav_svn.passwd other_user_name
8.5 对添加的用户进行授权
编辑授权文件/etc/subversion/dav_svn.authz[groups]
administrator=admin,elvis
tester=test1
[test:/]
@administrator=rw
tester=r
8.6错误处理
重启apache:sudo /etc/init.d/apache2 restart出现错误:
root@elvis-desktop:~/work/KAPP# /etc/init.d/apache2 restart
Syntax error on line 83 of /etc/apache2/mods-enabled/dav_svn.conf:
Invalid command 'AuthzSVNAccessFile', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
编辑:/etc/apache2/mods-enabled/dav.load 内容如下
LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
# LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so
重启 apache 成功
8.7关于授权
8.7.1 资源库定制
通过 svn:// file:///方式 访问则应用该授权可针对每个资源库定制权限
svnadmin create /home/svnuser/test/
配置../conf目录下三个文件:
svnserve.conf
passwd
authz
8.7.2 apache 方式
通过 http:// 方式访问则应用该授权配置以下两个文件:
/etc/subversion/dav_svn.passwd
/etc/subversion/dav_svn.authz