主机名 | IP地址 |
master | 192.168.30.130 |
slave | 192.168.30.131 |
安装
[root@master ~]# yum install -y subversion httpd mod_dav_svn
创建工程版本库
[root@master ~]# mkdir /webdept #版本库目录 [root@master ~]# svnadmin create /webdept/www.sishen.cn 第一个版本库 查看版本库中的内容 [root@master ~]# ll /webdept/www.sishen.cn/ total 24 drwxr-xr-x 2 root root 4096 May 27 15:49 conf #是这个仓库的配置文件(仓库的用户访问账号、权限等),也是我们要关注的配置文件 drwxr-sr-x 6 root root 4096 May 27 15:49 db #所有版本控制的数据存放文件 -r--r--r-- 1 root root 2 May 27 15:49 format #是一个文本文件,里面只放了一个整数。表示当前文件库配置的版本号 drwxr-xr-x 2 root root 4096 May 27 15:49 hooks #放置hook脚本文件的目录 drwxr-xr-x 2 root root 4096 May 27 15:49 locks #用来放置subversion常见锁定数据的目录,用来追踪存取文件库的客户端 -rw-r--r-- 1 root root 229 May 27 15:49 README.txt [root@master ~]# ll /webdept/www.sishen.cn/conf/ total 12 -rw-r--r-- 1 root root 1080 May 27 15:49 authz #权限认证 -rw-r--r-- 1 root root 309 May 27 15:49 passwd #用户名和密码 -rw-r--r-- 1 root root 2279 May 27 15:49 svnserve.conf #服务器配置文件
对不同的版本库,修改配置文件
[general] .......... anon-access = read .......... auth-access = write .......... password-db = passwd .......... authz-db = authz .......... realm = www.sishen.cn ..........
配置用户和密码
[root@master ~]# vim /webdept/www.sishen.cn/conf/passwd [users] sishen = 123456 xueji = 123456 haha = 123456 #末尾添加这三行 #对于部分版本,前面的[users]是有#号的,如果有#号,一定要取消,否则只能使用匿名用户登录,客户端登录不会出现登录窗口或密码提示,除非在配置文件将anon设置为none,否则将返回一个错误 #这里的密码都是明文,没有加密。
配置认证信息
[root@master ~]# vim /webdept/www.sishen.cn/conf/authz [groups]
Check = sishen,xueji #此行添加,定义组 [/] #此行添加,/表示在当前所在版本库目录,这里表示在www.sishen.cn目录下 user = rw @Check = r #表示这个组的权限 * = #除了上面的有赋予权限成员之外,其他成员都没有权限
该文件的定义格式:
[/目录名]
@用户组名 = 权限
用户名 = 权限
* =
启动svn服务创建测试代码
[root@master ~]# svnserve -d -r /webdept/ #启动了/wendept下的所有的版本库 查看进程 [root@master ~]# ps -aux | grep svn Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 48890 0.0 0.0 183112 1080 ? Ss 16:21 0:00 svnserve -d -r /webdept/ root 48894 0.0 0.0 103252 832 pts/0 S+ 16:22 0:00 grep svn [root@master ~]# netstat -antup | grep svn tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 48890/svnserve
在SVN服务端提交代码测试
[root@master ~]# mkdir localsvn [root@master ~]# cd localsvn/ [root@master localsvn]# touch 1.html [root@master localsvn]# touch 2.html [root@master localsvn]# cd root@master ~]# svn import /root/localsvn/ file:///webdept/www.sishen.cn/ -m "The First Commit" Adding /root/localsvn/1.html Adding /root/localsvn/2.html Committed revision 1 在客户端 [root@slave editweb]# svn import /root/editweb/ svn://192.168.30.130/www.sishen.cn/ -m "The Second Commit" Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Password for 'root': Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Username: haha Password for 'haha': ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://192.168.30.130:3690> www.sishen.cn can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/root/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? yes Adding /root/editweb/3.html Adding /root/editweb/4.html Adding /root/editweb/5.html Committed revision 2.
代码提取
[root@master ~]# svn checkout svn://192.168.30.130/www.sishen.cn download-source #会自动新建download-source目录 Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Password for 'root': #这里直接回车 Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Username: sishen #输入sishen,或者xueji,这两个用户只有读取的权限 Password for 'sishen': #输入sishen的密码123456 ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://192.168.30.130:3690> www.sishen.cn can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/root/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? no #不要存储密码 A download-source/1.html A download-source/2.html A download-source/3.html A download-source/4.html A download-source/5.html Checked out revision 2.
添加代码
[root@master download-source]# touch a.html [root@master download-source]# ls 1.html 2.html 3.html 4.html 5.html a.html [root@master download-source]# svn add a.html A a.html [root@master download-source]# svn commit -m "The third commit" Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Password for 'sishen': #输入密码发现提示认证失败,因为sishen用户没有写权限,再次执行svn提交命令到此处时,直接回车切换用户haha Authentication realm: <svn://192.168.30.130:3690> www.sishen.cn Username: haha Password for 'haha': ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://192.168.30.130:3690> www.sishen.cn can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/root/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? no Sending 5.html Adding a.html Transmitting file data .. Committed revision 3. #提交成功
配置SVN+Apache
[root@master ~]# vim /etc/httpd/conf.d/subversion.conf LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so #如果有这两个库文件说明安装成功 #然后在文件末尾田间如下内容 <Location /webdept> DAV svn SVNParentPath /webdept AuthType Basic AuthName "www.sishen.cn website dept" AuthUserFile /webdept/svn/passwd AuthzSVNAccessFile /webdept/svn/authz Require valid-user </Location>
创建用户passwd文件
[root@master ~]# mkdir /webdept/svn [root@master ~]# htpasswd -c /webdept/svn/passwd webuser #首次创建passwd文件需要使用-c参数,之后就不要使用了,否则会覆盖文件内容 New password: Re-type new password: Adding password for user webuser [root@master ~]# htpasswd /webdept/svn/passwd webuser01 New password: Re-type new password: Adding password for user webuser01 [root@master ~]# htpasswd /webdept/svn/passwd depuser New password: Re-type new password: Adding password for user depuser [root@master ~]# cat /webdept/svn/passwd webuser:KdGQogiSh/owA webuser01:xa4W7xxnGNzHw depuser:sw3dIsOwv4IAc
创建权限authz认证文件
[root@master ~]# vim /webdept/svn/authz [groups] all = webuser,webuser01 [/] # / 表示版本库根目录 webuser = rw [www.sishen.cn:/] @all = rw #表示webuser和webuser01都可以读写 [www.xueji.cn:/] #该目录只有webuser01和depuser可以读写 webuser01 = rw depuser = rw
启动服务测试
[root@master ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
物理机浏览器访问测试
在linux客户端执行以下操作
[root@slave ~]# mkdir /website [root@slave ~]# svn checkout svn://192.168.30.130/www.sishen.cn/ source A source/1.html A source/a.html A source/2.html A source/3.html A source/4.html A source/5.html Checked out revision 3. [root@slave ~]# svn co "http://192.168.30.130/webdept/www.sishen.cn" source Authentication realm: <http://192.168.30.130:80> www.sishen.cn website dept Password for 'root': #直接回车 Authentication realm: <http://192.168.30.130:80> www.sishen.cn website dept Username: webuser #输入webuser用户 Password for 'webuser': #输入密码123456 ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <http://192.168.30.130:80> www.sishen.cn website dept can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/root/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? no svn: 'source' is already a working copy for a different URL
至于windows下的svn客户端在此就不在演示了。