一、实验环境:
[[email protected] ~]# uname -a
Linux node02 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[[email protected] ~]#
[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:DF:59:C7
inet addr:192.168.112.129 Bcast:192.168.112.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fedf:59c7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:37078 errors:0 dropped:0 overruns:0 frame:0
TX packets:21925 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26850825 (25.6 MiB) TX bytes:3241796 (3.0 MiB)
[[email protected] ~]#
二、SVN Apache安装
这里我直接用yum安装
[[email protected] ~]# yum install subversion apr apr-util mod_dav_svn httpd
[[email protected] ~]#
[[email protected] ~]# rpm -qa subversion apr apr-util mod_dav_svn httpd
apr-util-1.3.9-3.el6_0.1.x86_64
subversion-1.6.11-15.el6_7.x86_64
apr-1.3.9-5.el6_2.x86_64
httpd-2.2.15-55.el6.centos.2.x86_64
mod_dav_svn-1.6.11-15.el6_7.x86_64
[[email protected] ~]#
查看目录结构:
[[email protected] ~]# tree /etc/httpd/
/etc/httpd/
├── conf
│ ├── httpd.conf
│ └── magic
├── conf.d
│ ├── passwd
│ ├── README
│ ├── subversion.conf
│ ├── subversion.conf.bak
│ └── welcome.conf
├── logs -> ../../var/log/httpd
├── modules -> ../../usr/lib64/httpd/modules
└── run -> ../../var/run/httpd
5 directories, 7 files
[[email protected] ~]#
目录配置:
(1)svn目录配置
[[email protected] ~]# mkdir -p /application/svn/svndata
[[email protected] ~]# mkdir -p /application/svn/svndata/svnpasswd/
[[email protected] ~]#
注意:这里的/application/svn/svndata是SVN的项目目录,该目录下就是我们平常的项目存放位置
目录/application/svn/svndata/svnpasswd/是用用户认证和权限文件存放路径,结构如下:
[[email protected] ~]# tree /application/svn/svndata/svnpasswd/
/application/svn/svndata/svnpasswd/
├── authz
└── passwd
0 directories, 2 files
[[email protected] ~]#
(2)启动SVN
[[email protected] ~]# svnserve -d -r /application/svn/svndata/
[[email protected] ~]# ps -ef|grep svn
root 13512 1 0 18:48 ? 00:00:00 svnserve -d -r /application/svn/svndata/
root 14068 1977 0 22:49 pts/0 00:00:00 grep svn
[[email protected] ~]# netstat -lnput|grep svn
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 13512/svnserve
[[email protected] ~]#
(3)创建项目
[[email protected] ~]# svnadmin create /application/svn/svndata/project001
[[email protected] ~]# tree /application/svn/svndata/project001/
/application/svn/svndata/project001/
├── conf
│ ├── authz
│ ├── passwd
│ └── svnserve.conf
├── db
│ ├── current
│ ├── format
│ ├── fsfs.conf
│ ├── fs-type
│ ├── min-unpacked-rev
│ ├── rep-cache.db
│ ├── revprops
│ │ └── 0
│ │ └── 0
│ ├── revs
│ │ └── 0
│ │ └── 0
│ ├── transactions
│ ├── txn-current
│ ├── txn-current-lock
│ ├── txn-protorevs
│ ├── uuid
│ └── write-lock
├── format
├── hooks
│ ├── post-commit.tmpl
│ ├── post-lock.tmpl
│ ├── post-revprop-change.tmpl
│ ├── post-unlock.tmpl
│ ├── pre-commit.tmpl
│ ├── pre-lock.tmpl
│ ├── pre-revprop-change.tmpl
│ ├── pre-unlock.tmpl
│ └── start-commit.tmpl
├── locks
│ ├── db.lock
│ └── db-logs.lock
└── README.txt
10 directories, 28 files
[[email protected] ~]#
(3)修改项目配置文件
[[email protected] ~]# cd /application/svn/svndata/project001
[[email protected] project001]# ls
conf db format hooks locks README.txt
[[email protected] project001]#
[[email protected] project001]# cd conf/
[[email protected] conf]# ll
total 12
-rw-r--r-- 1 root root 1080 Dec 31 22:53 authz
-rw-r--r-- 1 root root 309 Dec 31 22:53 passwd
-rw-r--r-- 1 root root 2279 Dec 31 22:53 svnserve.conf
[[email protected] conf]#
[[email protected] conf]# vim svnserve.conf
anon-access = none ------------------->12行去掉注释
auth-access = write ------------------->13行去掉注释
password-db = /application/svn/svndata/svnpasswd/passwd ------------>18行去掉注释
authz-db = /application/svn/svndata/svnpasswd/authz ---------------->25行去掉注释
[[email protected] conf]#
提示:svnserve.conf中每个参数都要定格写,开头不能有空格
或者执行如下命令修改:
[[email protected] conf]# sed -i ‘s/# anon-access = read/anon-access = none/g‘ svnserve.conf
[[email protected] conf]# sed -i ‘s/# auth-access = write/auth-access = write/g‘ svnserve.conf
[[email protected] conf]# sed -i ‘s%# password-db = passwd%password-db = /application/svn/svndata/svnpasswd/passwd%g‘ svnserve.conf
[[email protected] conf]# sed -i ‘s%# authz-db = authz%authz-db = /application/svn/svndata/svnpasswd/authz%g‘ svnserve.conf
修改完之后可以运行如下命令进行检查
[[email protected] conf]# egrep "\-access|\-db =" svnserve.conf
anon-access = none
auth-access = write
password-db = /application/svn/svndata/svnpasswd/passwd
authz-db = /application/svn/svndata/svnpasswd/authz
[[email protected] conf]#
确认配置修改无误后,拷贝用户认证文件passwd和权限管理文件authz到刚才创建的目录下:
[[email protected] conf]# cp authz passwd /application/svn/svndata/svnpasswd/
[[email protected] conf]# tree /application/svn/svndata/svnpasswd/
/application/svn/svndata/svnpasswd/
├── authz
└── passwd
0 directories, 2 files
[[email protected] conf]#
(4)创建用户admin、user001并设置密码,格式:用户名 = 密码
[[email protected] svnpasswd]# cat 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.
[users]
# harry = harryssecret
# sally = sallyssecret
admin = admin
user001 = 123456
[[email protected] svnpasswd]#
访问权限:
[[email protected] svnpasswd]# cat authz
-----省略部分-------------
[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
users = admin,user001
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[/]
@users = rw
[[email protected] svnpasswd]#
说明:users= admin,user001将admin、user001两个用户赋值用户组users,@user = rw 是让用户组对跟目录有读写权限,也就是说用户admin、user001这两个用户对根目录有读写的权限。
到这里svn服务器算搭建完成。
(5)客户端安装
下面进行客户端的安装和操作
这里介绍安装过程,windows下安装客户端直接双击,然后下一步下一步即可。
(6)SVN的常用操作,提交、更新、删除文件
安装好之后,鼠标置于桌面右键会有如下图标出现 SVN Checkout和TortoiseSVN两个标签
这里我在桌面创建一个文件夹,输入写入一个文件,然后提交SVN Checkout,
会弹出一个登录对话框,此时点击OK
此时会提示输入用户名和密码:
输入刚才创建的用户admin或者user001登录即可,这里用user001登录即可。如果有文件要提交,这里直接把文件放入project001里,在文件夹上右击,弹出如下对话框,然后选择文件点击"确定"即可
提交后的结果为:
这里,就将本地的文件提价到svn上,如果有意外操作。比如不小心把本地文件删除了,可以在从svn上再拉取一份即可。
删除2.xlsx文件,然后再从svn上拉取一次,
输入用户名和密码
确定后,就从svn上拉取了一份2.xlsx文件
如果要删除SVN上的某个文件,需要将本地的文件删除,然后再执行cmmit(提交)
弹出如下对话框
确定后,即可完成SVN服务器上的2.xlsx文件的删除
(7)导入SVN原始的目录树
[[email protected] ~]# cd /application/tools/
[[email protected] tools]# mkdir -p branch tags trunk/
[[email protected] tools]# ll
total 12
drwxr-xr-x 2 root root 4096 Dec 31 21:02 branch
drwxr-xr-x 2 root root 4096 Dec 31 21:02 tags
drwxr-xr-x 2 root root 4096 Dec 31 21:02 trunk
[[email protected] tools]#
[[email protected] tools]# svn import /application/tools/ file:///application/svn/svndata/project001/
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no ‘editor-cmd‘ run-time configuration option was found
[[email protected] tools]#
报错,提示加参数 -m "xxxxx"
[[email protected] tools]# svn import /application/tools/ file:///application/svn/svndata/project001/ -m "import messages"
Adding /application/tools/trunk
Adding /application/tools/branch
Adding /application/tools/tags
Committed revision 5.
[[email protected] tools]#
导入成功,客户端检查一下
点击“版本库浏览器”
至此SVN原始目录树导入成功。
(8)打tags版本
如果我们有一个项目为ucode,开发完所有的基本功能之后,的版本问1.0,如下图所示:
以后的开发都是基于这个版本的开发,那么可以把这个版本锁定,然后定义为一个新的版本,操作如下:
选择"分支/标记(T)" 弹出如下对话框,输入"ucode_dev_1.0_release_v0001",如下图:
然后"确定"即可。
接下来可以在tags目录下看到刚才打的版本号: