现实开发少不了svn或者git相关的代码管理工具,现在先说一下svn的服务器搭建,亲测可用,整理出来方便大家使用!
一、实验环境:
[root@node02 ~]# 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
[root@node02 ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@node02 ~]#
[root@node02 ~]# ifconfig eth0
二、SVN Apache安装
这里我直接用yum安装
[root@node02 ~]# yum install subversion apr apr-util mod_dav_svn httpd
[root@node02 ~]#
[root@node02 ~]# 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
[root@node02 ~]#
查看目录结构:
[root@node02 ~]# 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
[root@node02 ~]#
目录配置:
(1)svn目录配置
[root@node02 ~]# mkdir -p /application/svn/svndata
[root@node02 ~]# mkdir -p /application/svn/svndata/svnpasswd/
[root@node02 ~]#
[root@node02~]# touch /application/svn/svndata/svnpasswd/authz
[root@node02 ~]# touch /application/svn/svndata/svnpasswd/passwd
注意:这里的/application/svn/svndata是SVN的项目目录,该目录下就是我们平常的项目存放位置
目录/application/svn/svndata/svnpasswd/是用用户认证和权限文件存放路径,结构如下:
[root@node02 ~]# tree /application/svn/svndata/svnpasswd/
/application/svn/svndata/svnpasswd/
├── authz
└── passwd
0 directories, 2 files
[root@node02 ~]#
(2)启动SVN
[root@node02 ~]# svnserve -d -r /application/svn/svndata/
[root@node02 ~]# 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
[root@node02 ~]# netstat -lnput|grep svn
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 13512/svnserve
[root@node02 ~]#
(3)创建项目
[root@node02 ~]# svnadmin create /application/svn/svndata/project001
[root@node02 ~]# 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
[root@node02 ~]#
(3)修改项目配置文件
[root@node02 ~]# cd /application/svn/svndata/project001
[root@node02 project001]# ls
conf db format hooks locks README.txt
[root@node02 project001]#
[root@node02 project001]# cd conf/
[root@node02 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
[root@node02 conf]#
[root@node02 conf]# vim svnserve.conf
anon-access = none ------------------->12行去掉注释,并修改read为none
auth-access = write ------------------->13行去掉注释
password-db = /application/svn/svndata/svnpasswd/passwd ------------>18行去掉注释
authz-db = /application/svn/svndata/svnpasswd/authz ---------------->25行去掉注释
[root@node02 conf]#
提示:svnserve.conf中每个参数都要顶格写,开头不能有空格
或者执行如下命令修改:
[root@node02 conf]# sed -i 's/# anon-access = read/anon-access = none/g' svnserve.conf
[root@node02 conf]# sed -i 's/# auth-access = write/auth-access = write/g' svnserve.conf
[root@node02 conf]# sed -i 's%# password-db = passwd%password-db = /application/svn/svndata/svnpasswd/passwd%g' svnserve.conf
[root@node02 conf]# sed -i 's%# authz-db = authz%authz-db = /application/svn/svndata/svnpasswd/authz%g' svnserve.conf
修改完之后可以运行如下命令进行检查
[root@node02 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
[root@node02 conf]#
确认配置修改无误后,拷贝用户认证文件passwd和权限管理文件authz到刚才创建的目录下:
[root@node02 conf]# cp authz passwd /application/svn/svndata/svnpasswd/
[root@node02 conf]# tree /application/svn/svndata/svnpasswd/
/application/svn/svndata/svnpasswd/
├── authz
└── passwd
0 directories, 2 files
[root@node02 conf]#
(4)创建用户admin、user001并设置密码,格式:用户名 = 密码
[root@node02 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
[root@node02 svnpasswd]#
访问权限:
[root@node02 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
zhangpeng=rw
[root@node02 svnpasswd]#
说明:users= admin,user001将admin、user001两个用户赋值用户组users,@user = rw 是让用户组对跟目录有读写权限,也就是说用户admin、user001这两个用户对根目录有读写的权限。
最好在最后加上
zhangpeng=rw
这样是指对某个单独的用户放开了读写权限,然后重启服务,在客户端连接即可。
到这里svn服务器算搭建完成。如有疑问请留言!