刚接触SVN的时候,因为对它不了解,又在Windows下面,被它的多版本库配置问题困扰很久,一直找不到完美解决方案,今天无意中在Linux下配置SVN时,发现它本身是支持的,通过配置--config-file参数指定全局的配置文件实现。写下此文来纠正以前错误的配置方式(主要是Windows系统下),分享给大家。
Linux和Windows下处理基本上一样的,先来看Linux下的svnserve的帮助信息:
[root@localhost ~]# svnserve --help
usage: svnserve [-d | -i | -t | -X] [options]
Valid options:
-d [--daemon] : daemon mode
-i [--inetd] : inetd mode
-t [--tunnel] : tunnel mode
-X [--listen-once] : listen-once mode (useful for debugging)
-r [--root] ARG : root of directory to serve
-R [--read-only] : force read only, overriding repository config file
--config-file ARG : read configuration from file ARG
--listen-port ARG : listen port
[mode: daemon, listen-once]
--listen-host ARG : listen hostname or IP address
[mode: daemon, listen-once]
-T [--threads] : use threads instead of fork [mode: daemon]
--foreground : run in foreground (useful for debugging)
[mode: daemon]
--log-file ARG : svnserve log file
--pid-file ARG : write server process ID to file ARG
[mode: daemon, listen-once]
--tunnel-user ARG : tunnel username (default is current uid's name)
[mode: tunnel]
-h [--help] : display this help
--version : show program version information
通常启动SVN服务,仅指定SVN版本库的根目录,如下:
svnserve -d -r /data/svn
然后在/data/svn下创建多个版本库:
cd /data/svn
svnadmin create repos1
svnadmin create repos2
再依次配置repos1和repos2等版本库下的conf/svnserve.conf、conf/passwd、conf/authz文件。
问题便来了,因为大多数的时候,同一个用户需要用相同的帐号和密码去访问不同的版本库,这时的权限配置就不好处理了,以前看其他人的解决方法是在svnserve.conf中指定passwd和authz的路径时用相对路径指到同一个文件。这是一个可行的方法,但新增版本库的时候,就得更改svnserve.conf文件,不方便。
仔细看svnserve的帮助信息,大家都会发现有一个--config-file参数,这个参数就是用来指定svnserve.conf路径的,说到这,问题已经明了,只要在启动SVN服务的时候,指定--config-file参数,只要指定了此参数,所有的权限都由参数指定的svnserve.conf控制,而每个版本库conf目录下的svnserve.conf的配置都会忽略掉。
svnserve -d -r /data/svn --config-file /data/svn/svnserve.conf
Windows下使用的是CollabNet的Subversion Server,它安装的服务,指定的ImagePath形式为:"d:\Program Files (x86)\CollabNet\Subversion Server\svnserve.exe" --service -r "e:\svn_repository" --listen-port "3690" ,是没有指定--config-file参数的,因此导致我等刚接触SVN的新手会被多版本库的配置问题纠结,现在只要到注册表更改一下SVN所在服务的ImagePath参数,追加上--config-file参数:
"d:\Program Files (x86)\CollabNet\Subversion Server\svnserve.exe" --service -r "e:\svn_repository" --listen-port "3690" --config-file "e:\svn_repository\conf\svnserve.conf"
以上中使用的路径等,请自行转换成各自对应的路径。