[root@centos02 ~]# yum install -y subversion
1.新建一个目录用于存储SVN所有文件
[root@centos02 ~]# mkdir /svn
2. 新建一个资源仓库
[root@centos02 ~]# svnadmin create /svn/project
[root@centos02 ~]# tree /svn /svn └── project ├── 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 11 directories, 28 files
[root@centos02 project]# ls conf db format hooks locks README.txt
目录用途说明: l hooks目录:放置hook脚本文件的目录 l locks目录:用来放置subversion的db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端 l format文件:是一个文本文件,里面只放了一个整数,表示当前文件库配置的版本号 l conf目录:是这个仓库的配置文件(仓库的用户访问账号、权限等) 3. 配置svn服务的配置文件svnserver.conf文件
[root@centos02 project]# vi /svn/project/conf/svnserve.conf
[general] anon-access = read auth-access = write password-db = /svn/project/conf/passwd authz-db = /svn/project/conf/authz realm = clnking
[root@centos02 project]# vi /svn/project/conf/passwd
[users] # harry = harryssecret # sally = sallyssecret chenlin = 123456 test1 = 123 test2 = 123
注意:对用户配置文件的修改立即生效,不必重启svn服务。
[root@centos02 project]# vim /svn/project/conf/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 admin = chenlin user = test2,test1 # [/foo/bar] # harry = rw # &joe = r # * = [/] @admin = rw
格式说明: 版本库目录格式: [<版本库>:/项目/目录] @<用户组名> = <权限> <用户名> = <权限> / 表示对根目录(即/svn/project目录)下的所有子目录范围设置权限; [/abc] 表示对资料库中abc项目设置权限; 创建一个admin组,组成员包括chenlin 创建一个user组,成员只有test2,test1; admin组对目录有读写权限; 单个用户test2有读写权限; *=表示除了上面设置的权限用户组以外,其他所有用户都设置空权限,空权限表示禁止访问本目录,这很重要一定要加上。 注意:对权限配置文件的修改立即生效,不必重启svn。
启动svn服务
[root@centos02 project]# svnserve -d -r /svn/project/
[root@centos02 project]# ps -ef |grep svn root 3809 1 0 05:29 ? 00:00:00 svnserve -d -r /svn/project/ root 3811 3707 0 05:30 pts/1 00:00:00 grep svn
[root@centos02 project]# netstat -lnutp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 3809/svnserve tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1767/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1571/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1334/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1424/master tcp 0 0 :::22 :::* LISTEN 1334/sshd tcp 0 0 ::1:25 :::* LISTEN 1424/master udp 0 0 0.0.0.0:68 0.0.0.0:* 3521/dhclient
[root@localhost hooks]# ls post-commit post-lock.tmpl post-unlock.tmpl pre-lock.tmpl pre-unlock.tmpl post-revprop-change.tmpl pre-commit.tmpl pre-revprop-change.tmpl start-commit.tmpl
#!/bin/sh REPOS="$1" REV="$2" export LANG=zh_CN.UTF-8 SVN_PATH=/usr/bin/svn WEB_USER=daemon LOG_PATH=/tmp/svn.log /usr/bin/svn update --username ecuser1 --password ecuser1 /opt/redmine-3.2.0-1/apache2/htdocs/test --no-auth-cache >> /tmp/svn.log #/usr/bin/svn update --username ecuser1 --password ecuser1 /opt/redmine-3.2.0-1/apache2/htdocs/test2 --no-auth-cache >> /tmp/svn.log /usr/bin/svn update --username ecuser1 --password ecuser1 /opt/redmine-3.2.0-1/apache2/htdocs/mobile --no-auth-cache >> /tmp/svn.log /usr/bin/svn update --username ecuser1 --password ecuser1 /opt/redmine-3.2.0-1/apache2/htdocs/framework --no-auth-cache >> /tmp/svn.log chown daemon.daemon -R /opt/redmine-3.2.0-1/apache2/htdocs/test
svn checkout svn://192.168.1.17/ecshop/PHP/mbshunfeng2015273 test