一、简介
SVN全名Subversion,即版本控制系统。作为一个开源的版本控制系统,Subversion管理着随时间改变的数据。这些数据放置在一个仓库(repository)中。这个仓库很像一个普通的文件服务器,不过它会记住每一次文件的变动。这样你就可以把档案恢复到旧的版本,或是浏览文件的变动历史。
二、方式1---独立服务器
主机介绍:
node1:192.168.0.166 #SVN的Server端
node2:192.168.0.156 #SVN的linux Client端
Windows:192.168.0.141 #SVN的Windows Client端
1. 安装SVN
[[email protected] ~]# yum install subversion mod_dav_svn -y
2. 制作仓库
[[email protected] ~]# mkdir /MySvn/ [[email protected] ~]# svnadmin create /MySvn/repos [[email protected] ~]# cd /MySvn/repos [[email protected] repos]# ls conf db format hooks locks README.txt [[email protected] repos]# cd conf/ [[email protected] conf]# ls authz passwd svnserve.conf
3. 配置SVN的配置文件
authz: SVN的权限文件
passwd: SVN的密码文件
svnserve.conf: SVN的配置文件
[[email protected] conf]# vim authz [groups] admin = admin,zhu #admin组里有admin和zhu 2个成员 [repos:/] #仓库名:/ 表示这个仓库的根目录 @admin = rw #组名前面使用@,单个用户直接写用户名 xue = r
[[email protected] conf]# vim passwd [users] admin = admin #用户名 = 密码 zhu = 12345 xue = qwer
[[email protected] conf]# vim svnserve.conf [general] anon-access = none #匿名用户没有访问权限 auth-access = write password-db = passwd authz-db = authz
4. 启动SVN
[[email protected] ~]# svnserve -d -r /MySvn/ [[email protected] ~]# netstat -tnlp | grep svn tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 2114/svnserve [[email protected] ~]# iptables -I INPUT 1 -p tcp --dport 3690 -j ACCEPT #放行端口
这里-r后面的参数,是用来指定SVN的根目录的,不要将仓库名写进去,即不要写成/MySvn/repos。
5. 测试
这里我先将/etc/目录下的文件导入到仓库中进行测试
[[email protected] ~]# svn import /etc/ file:///MySvn/repos/ -m "message"
-m后面的参数是备注信息,根据自己的需要写
linux(node2)上测试:
[[email protected] ~]# svn checkout svn://192.168.0.166/repos/ /mnt/ #IP后面直接跟仓库名,副本放到/mnt/目录下 Authentication realm: <svn://192.168.0.166:3690> 57532f62-ae95-428e-9a43-9a0a78173f2d Password for ‘root‘: #node2的root密码 Authentication realm: <svn://192.168.0.166:3690> 57532f62-ae95-428e-9a43-9a0a78173f2d Username: admin Password for ‘admin‘: #上面配置的admin用户和密码 ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://192.168.0.166:3690> 57532f62-ae95-428e-9a43-9a0a78173f2d 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
密码文件的存放位置
[[email protected] ~]# tree .subversion/ .subversion/ ├── auth │ ├── svn.simple │ │ └── 845e591d3dae91ace580695b8dc4a30d #密码文件,可以将它删除,重新认证 │ ├── svn.ssl.client-passphrase │ ├── svn.ssl.server │ └── svn.username ├── config ├── README.txt └── servers
这样在/mnt/目录下就有了SVN的一个副本。
[[email protected] mnt]# ls #列出了部分文件 1.txt cron.deny fstab jvm abrt cron.hourly gai.conf jvm-commmon acpi cron.monthly gconf kde
Windows上测试:
提示输入用户名和密码,然后也会生成一个副本
三、方式2--apache+svn
主机列表:
Server:192.168.0.146 #SVN的Server端
node2:192.168.0.156 #SVN的linux Client端
Windows:192.168.0.124 #SVN的Windows Client端
1. 下载所需的源码包
[[email protected] ~]# wget -c t 0 www.sqlite.org/2014/sqlite-autoconf-3080701.tar.gz [[email protected] ~]# wget -c -t 0 apache.cs.utah.edu/subversion/subversion-1.8.10.tar.bz2 [[email protected] ~]# wget -c -t 0 http://apache.fayea.com/apache-mirror/apr/apr-1.5.1.tar.bz2 [[email protected] ~]# wget -c -t 0 http://apache.fayea.com/apache-mirror/apr/apr-util-1.5.4.tar.bz2 [[email protected] ~]# wget -c -t 0 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.bz2 [[email protected] ~]# wget -c -t 0 mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.bz2
2.安装apache
[[email protected] ~]# tar xf apr-1.5.1.tar.bz2 [[email protected] ~]# tar xf apr-util-1.5.4.tar.bz2 [[email protected] ~]# tar xf pcre-8.36.tar.bz2 [[email protected] ~]# tar xf httpd-2.4.10.tar.bz2 [[email protected] apr]# ./configure --prefix=/usr/local/apr #安装apr [[email protected] apr]# make && make install [[email protected] apr-util]# ./configure --prefix=/usr/local/apr-util \ #安装apr-util --with-apr=/usr/local/apr/ [[email protected] apr-util]# make && make install [[email protected] pcre-8.36]# ./configure --prefix=/usr/local/pcre #安装pcre [[email protected] pcre-8.36]# make && make install [[email protected] httpd-2.4.10]# ./configure --prefix=/usr/local/apache \ #安装apache --enable-dav --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-track-vars --enable-rewrite --with-zlib --enable-mods=most --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre [[email protected] httpd-2.4.10]# make [[email protected] httpd-2.4.10]# make install
3. 安装subversion
[[email protected] ~]# tar xf sqlite-autoconf-3080701.tar.gz [[email protected] sqlite-autoconf-3080701]# ./configure --prefix=/usr/local/sqlite #安装sqlite [[email protected] sqlite-autoconf-3080701]# make && make install [[email protected] subversion-1.8.10]# ./configure --prefix=/usr/local/subversion \ #安装SVN --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-sqlite=/usr/local/sqlite --with-apxs=/usr/local/apache/bin/apxs --with-zlib --enable-mod-activation [[email protected] subversion-1.8.10]# make && make install
--enable-mod-activation选项一定要加,不然apache会找不到mod_dav_svn.so和mod_authz_svn.so这2个模块的。
4. 完善安装(一个良好的习惯)
[[email protected] ~]# vim /etc/profile export PATH=$PATH:/usr/local/apache/bin/:/usr/local/subversion/bin/ [[email protected] ~]# . !$ #在PATH变量中添加apache和subversion的可执行文件 [[email protected] ~]# vim /etc/man.config MANPATH /usr/local/apache/man MANPATH /usr/local/subversion/share/man/ #让系统可以找到apache的帮助文档 [[email protected] ~]# vim /etc/ld.so.conf.d/apache-x86_64.conf /usr/local/apache/lib [[email protected] ~]# vim /etc/ld.so.conf.d/subverion-x86_64.conf /usr/local/subversion/lib [[email protected] ~]# ldconfig -v #让系统可以找到apache和subversion的库文件 [[email protected] ~]# ln -sv /usr/local/apache/include /usr/include/apache `/usr/include/apache/include‘ -> `/usr/local/apache/include‘ [[email protected] ~]# ln -sv /usr/local/subversion/include /usr/include/subverion `/usr/include/subverion‘ -> `/usr/local/subversion/include‘ #让系统可以找到apache和subverion的头文件
5. 配置apache,让apache管理SVN
[[email protected] ~]# vim /etc/httpd/httpd.conf LoadModule dav_svn_module /usr/local/subversion/libexec/mod_dav_svn.so #确保有这2行 LoadModule authz_svn_module /usr/local/subversion/libexec/mod_authz_svn.so User apache #修改这4行 Group apache DocumentRoot "/OtherSvn" <Directory "/OtherSvn"> pidFile "/var/run/httpd.pid" #增加下面的配置 <Location /svn> #这个路径可以随便写,到时URL后面加上这个路径就可以了 DAV svn SVNParentPath /OtherSvn #版本库根目录(不要加上仓库名) AuthType Basic #基本认证类型 AuthName "welcome you" #提示对话框的标题 AuthUserFile /OtherSvn/passwd #登录的密码文件 AuthzSVNAccessFile /OtherSvn/auth.conf #SVN的授权文件 Require valid-user #认证用户可以访问 </Location>
6.制作仓库并添加配置文件
[[email protected] ~]# mkdir /OtherSvn [[email protected] ~]# svnadmin create /OtherSvn/OtherRepos #制作仓库 [[email protected] ~]# cd /OtherSvn/ [[email protected] OtherSvn]# cp OtherRepos/conf/authz auth.conf [[email protected] OtherSvn]# vim auth.conf #授权文件 [groups] admin = admin,zhu [OtherRepos:/] @admin = rw [[email protected] ~]# htpasswd -c -m -b /OtherSvn/passwd admin admin #密码文件 Adding password for user admin
-c的意思是创建passwd文件,只有在第一次的时候才会使用。
7.修改文件权限并启动
[[email protected] ~]# useradd -r -s /sbin/nologin apache [[email protected] ~]# chown -R apache:apache /OtherSvn/ [[email protected] ~]# chmod -R 755 /OtherSvn/ [[email protected] ~]# service httpd start [[email protected] ~]# iptables -I INPUT 1 -m state --state NEW -p tcp --dport 80 -j ACCEPT
httpd的启动脚本放在附件里
8. 测试
还是将/etc/导入仓库中进行测试
[[email protected] ~]# svn import /etc/ file:///OtherSvn/OtherRepos/ -m "message"
Windows测试:
URL:SVN服务器IP地址 + Location后面指定的路径 + 仓库名
一定要加仓库名,不然会出现下面的报错
[Fri Nov 14 13:43:25.789643 2014] [:error] [pid 2048:tid 140506000836352] [client 192.168.0.124:52380] The URI does not contain the name of a repository. [403, #190001]
意思就是URL里面没有包括仓库名
linux测试:
[[email protected] ~]# mkdir /SVN_Client [[email protected] ~]# svn checkout http://192.168.0.146/svn/OtherRepos/ /SVN_Client Authentication realm: <http://192.168.0.146:80> welcome you Password for ‘root‘: Authentication realm: <http://192.168.0.146:80> welcome you Username: admin Password for ‘admin‘: #只是路径不同了而已
四、备份和恢复
- svnadmin dump
参数介绍:
-r [--revision] :指定版本ARG(或X:Y范围)
--incremental :以增量方式进行转存
用法:
svnadmin dump REPOS_PATH [-r LOWER[:UPPER] [--incremental]]
全量备份:
[[email protected] ~]# svnadmin dump /OtherSvn/OtherRepos/ > OtherRepos.bak
增量备份:
[[email protected] ~]# svnadmin dump /OtherSvn/OtherRepos/ -r 2 --incremental > OtherRepos2.bak
将版本1中的文件转存出来
恢复:
[[email protected] ~]# svnadmin create /OtherSvn/test [[email protected] ~]# svnadmin load /OtherSvn/test/ < OtherRepos.bak [[email protected] ~]# svnadmin load /OtherSvn/test/ < OtherRepos2.bak #先还原全量再还原增量
2. svnadmin hotcopy
用法:
svnadmin hotcopy REPOS_PATH NEW_REPOS_PATH
[[email protected] ~]# svnadmin hotcopy /OtherSvn/OtherRepos/ /media/ [[email protected] ~]# cd /media/ [[email protected] media]# ls conf db format hooks locks README.txt #恢复的时候,直接把文件移动过去就好了