%toc
安装软件包
$ sudo apt-get install subversion
创建版本仓库:
sudo svnadmin create /目录地址
目录地址必须存在,这个就是保存版本仓库的地方,不同的版本仓库创建不同的文件夹即可,比如:
sudo svnadmin create /home/svn/repo
本来/home/svn/repo/ 这个目录下什么都没有,执行下面的命令之后再去看一下,多出一些文件和文件夹,我们需要操作的是conf这个文件夹,这个文件夹下有一个文件,叫做passwd,用来存放用户名和密码。 然后把这个版本仓库目录授权给svn用户读写: sudo chown -R svn.svn /目录地址
修改版本配置库文件
vim /home/svn/repo/conf/svnserve.conf
### This file controls the configuration of the svnserve daemon, if you ### use it to allow access to this repository. (If you only allow ### access through http: and/or file: URLs, then this file is ### irrelevant.) ### Visit http://subversion.tigris.org/ for more information. [general] ### These options control access to the repository for unauthenticated ### and authenticated users. Valid values are "write", "read", ### and "none". The sample settings below are the defaults. anon-access = none # 注意这里必须设置,否则所有用户不用密码就可以访问 auth-access = write ### The password-db option controls the location of the password ### database file. Unless you specify a path starting with a /, ### the file's location is relative to the directory containing ### this configuration file. ### If SASL is enabled (see below), this file will NOT be used. ### Uncomment the line below to use the default password file. password-db = passwd ### The authz-db option controls the location of the authorization ### rules for path-based access control. Unless you specify a path ### starting with a /, the file's location is relative to the the ### directory containing this file. If you don't specify an ### authz-db, no path-based access control is done. ### Uncomment the line below to use the default authorization file. authz-db = authz ### This option specifies the authentication realm of the repository. ### If two repositories have the same authentication realm, they should ### have the same password database, and vice versa. The default realm ### is repository's uuid. realm = tshop [sasl] ### This option specifies whether you want to use the Cyrus SASL ### library for authentication. Default is false. ### This section will be ignored if svnserve is not built with Cyrus ### SASL support; to check, run 'svnserve --version' and look for a line ### reading 'Cyrus SASL authentication is available.' # use-sasl = true ### These options specify the desired strength of the security layer ### that you want SASL to provide. 0 means no encryption, 1 means ### integrity-checking only, values larger than 1 are correlated ### to the effective key length for encryption (e.g. 128 means 128-bit ### encryption). The values below are the defaults. # min-encryption = 0 # max-encryption = 256
创建用户
最后一步就是创建访问用户了,将用户名密码文件存放在当前版本仓库下conf文件夹下,这样版本仓库多的时候无至于太乱。
因为conf文件夹下已经存在passwd文件了,所以直接添加用户:
vim /home/svn/repo/conf/passwd
### This file is an example password file for svnserve. ### Its format is similar to that of svnserve.conf. As shown in the ### example below it contains one section labelled [users]. ### The name and password for each user follow, one account per line. ### 在下面添加用户和密码,每行一组username = password [users] # harry = harryssecret # sally = sallyssecret ###===========我添加的用户信息========####### user1 = password1 user2 = password2
- 开始设置authz. 用户访问权限
vim /home/svn/repo/conf/authz
### This file is an example authorization file for svnserve. ### Its format is identical to that of mod_authz_svn authorization ### files. ### As shown below each section defines authorizations for the path and ### (optional) repository specified by the section name. ### The authorizations follow. An authorization line can refer to: ### - a single user, ### - a group of users defined in a special [groups] section, ### - an alias defined in a special [aliases] section, ### - all authenticated users, using the '$authenticated' token, ### - only anonymous users, using the '$anonymous' token, ### - anyone, using the '*' wildcard. ### ### A match can be inverted by prefixing the rule with '~'. Rules can ### grant read ('r') access, read-write ('rw') access, or no access ### (''). [aliases] # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average # [groups] # harry_and_sally = harry,sally # harry_sally_and_joe = harry,sally,&joe # [/foo/bar] # harry = rw # &joe = r # * = # [repository:/baz/fuz] # @harry_and_sally = rw # * = r ###--------------------下面我新加的------------------------### [groups] dev = user1,user2 [/] user1 = rw * = [/dir1] @dev = rw [/dir2] @dev = rw
对权限配置文件的修改立即生效,不必重启svn!
启动SVN服务
useradd svn
vim /etc/init.d/svn
#!/bin/bash # build this file in /etc/rc.d/init.d/svn # chmod 755 /etc/rc.d/init.d/svn # 可以用如下命令管理svn: service svn start(restart/stop) SVN_HOME=/home/svn/repo if [ ! -f "/usr/local/svn/bin/svnserve" ] then echo "svnserver startup: cannot start" exit fi case "$1" in start) echo "Starting svnserve..." su - svn -c /usr/local/svn/bin/svnserve -d -r $SVN_HOME echo "Finished!" ;; stop) echo "Stoping svnserve..." killall svnserve echo "Finished!" ;; restart) $0 stop $0 start ;; *) echo "Usage: svn { start | stop | restart } " exit 1 esac
之后就可以通过 /etc/init.d/svn start|stop 来控制svn了!
客户端访问可以通过 svn co svn://{你的IP}/ 来使用了
SVN 备份还原
- 首先创建一个空的项目repo,步骤参见上面。
- 然后将dumpfile导入到新的repository 目录中。
svnadmin load /home/svn/repo/ < /tmp/full_dump.file
将原先服务器的配置文件备份后复制到新服务器中 #/home/svn/repo/conf目录下 authz、passwd、svnserve.conf文件
就完成了备份的恢复,很方便吧。