Linux安装配置SVN服务

来源:互联网 发布:美加净防晒霜 知乎 编辑:程序博客网 时间:2024/05/16 08:31

linux环境:ubuntu 12.04

一、安装SVN(Subversion)

1、检查SVN软件程序是否安装
darker@darker:~$ svn --versionsvn,版本 1.6.17 (r1128011)   编译于 Aug 20 2015,15:17:45版权所有 (C) 2000-2009 CollabNet。Subversion 是开放源代码软件,请参阅 http://subversion.apache.org/ 站点。此产品包含由 CollabNet (http://www.Collab.Net/) 开发的软件。
2、安装SVN
darker@darker:~$ sudo apt-get install subversion[sudo] password for darker: 正在读取软件包列表... 完成正在分析软件包的依赖关系树       正在读取状态信息... 完成     

二、配置并启动SVN

1、建立svn版本库数据存储跟目录(svndata)以及用户、密码权限目录(svnpasswd)
darker@darker:~$ mkdir -p /home/darker/work/svn/application/svndata
darker@darker:~$ mkdir -p /home/darker/work/svn/application/svnpasswd
2、启动svn服务指定svn数据存储跟目录:
启动svn使用svnserve命令,通过svn+Tab键查看svn其他服务命令:
darker@darker:~$ svnsvn                              svndumpfilter                    svn-populate-node-origins-index  svnversionsvnadmin                         svnlook                          svnserve                         svnauthz-validate                svnmucc                          svnsync
启动SVN服务:
darker@darker:~$ svnserve -d -r /home/darker/work/svn/application/svndata/
可以查看svnserve命令帮助,了解相关启动参数:
darker@darker:~$ svnserve --help用法: svnserve [-d | -i | -t | -X] [options]有效选项:  -d [--daemon]            : 后台模式  -i [--inetd]             : inetd 模式  -t [--tunnel]            : 隧道模式  -X [--listen-once]       : 监听一次方式(调试用)  -r [--root] ARG          : 服务的根目录  -R [--read-only]         : 强制只读;覆盖版本库配置文件  --config-file ARG        : 从文件 ARG 读取配置  --listen-port ARG        : 监听端口                             [方式: daemon, listen-once]  --listen-host ARG        : 监听主机名称或IP地址                             [方式: daemon, listen-once]  -T [--threads]           : 使用线程代替进程 [方式: daemon]  --foreground             : 在前台运行(调试用)                             [方式: daemon]  --log-file ARG           : svnserve 日志文件  --pid-file ARG           : 写进程 PID 到文件 ARG                             [方式: daemon, listen-once]  --tunnel-user ARG        : 隧道用户名(默认是当前UID对应的用户名)                             [方式: tunnel]  -h [--help]              : 显示本帮助  --version                : 显示程序版本信息
3、查看SVN进程
darker@darker:~$ ps -ef|grep svn darker    2199     1  0 20:13 ?        00:00:00 svnserve -d -r /home/darker/work/svn/application/svndata/darker    2211  1688  0 20:18 pts/0    00:00:00 grep --color=auto svndarker@darker:~$ ps -ef|grep svn|grep -v grepdarker    2199     1  0 20:13 ?        00:00:00 svnserve -d -r /home/darker/work/svn/application/svndata/
4、检测SVN端口
darker@darker:~$ netstat -lnt|grep 3690tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN     darker@darker:~$ netstat -lntup|grep svn(并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      2199/svnserve   darker@darker:~$ netstat -lntup|grep 3690(并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      2199/svnserve   darker@darker:~$ lsof -i tcp:3690COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEsvnserve 2199 darker    3u  IPv4  11153      0t0  TCP *:svn (LISTEN)darker@darker:~$ lsof -i :3690COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEsvnserve 2199 darker    3u  IPv4  11153      0t0  TCP *:svn (LISTEN)

三、建立项目版本库

创建一个新的Subversion项目sadoc,其实,类似sadoc这样的项目可以创建多个,每个项目对应不同的代码。
1、创建项目版本库,不能直接创建,使用的是svn服务命令:svnadmin
darker@darker:~$ svnadmin create /home/darker/work/svn/application/svndata/sadoc
darker@darker:~$ ll /home/darker/work/svn/application/svndata总用量 16drwxrwxr-x 4 darker darker 4096  4月 23 19:38 ./drwxrwxr-x 4 darker darker 4096  4月 19 21:52 ../drwxrwxr-x 6 darker darker 4096  4月 19 22:28 sadoc/
2、显示版本库目录结构:
darker@darker:~$ tree /home/darker/work/svn/application/svndata/home/darker/work/svn/application/svndata├── sadoc│   ├── conf│   │   ├── authz│   │   ├── passwd│   │   └── svnserve.conf│   ├── db│   │   ├── current│   │   ├── format│   │   ├── fsfs.conf│   │   ├── fs-type│   │   ├── min-unpacked-rev│   │   ├── rep-cache.db│   │   ├── revprops│   │   │   └── 0│   │   │       ├── 0│   │   │       ├── 1│   │   │       └── 2│   │   ├── revs│   │   │   └── 0│   │   │       ├── 0│   │   │       ├── 1│   │   │       └── 2│   │   ├── 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
3、显示版本库sadoc的操作权限
darker@darker:~$ ls -ld /home/darker/work/svn/application/svndata/sadoc/drwxrwxr-x 6 darker darker 4096  4月 19 22:28 /home/darker/work/svn/application/svndata/sadoc/
4、查看svnadmin命令帮助的方法
查看全部的命令:
darker@darker:~$ svnadmin help一般用法: svnadmin SUBCOMMAND REPOS_PATH  [ARGS & OPTIONS ...]使用“svnadmin help <subcommand>” 得到子命令的帮助信息。使用“svnadmin --version”查看程序的版本号和文件系统模块。可用的子命令:   crashtest   create   deltify   dump   help (?, h)   hotcopy   list-dblogs   list-unused-dblogs   load   lslocks   lstxns   pack   recover   rmlocks   rmtxns   setlog   setrevprop   setuuid   upgrade   verify
查看指定的子命令:查看子命令create的用法
darker@darker:~$ svnadmin help createcreate: 用法: svnadmin create REPOS_PATH在 REPOS_PATH 创建一个新的空版本库。有效选项:  --bdb-txn-nosync         : 在提交事务时禁用fsync [BDB]  --bdb-log-keep           : 禁用自动删除日志文件 [BDB]  --config-dir ARG         : 从目录 ARG 读取用户配置文件  --fs-type ARG            : 版本库类型: “fsfs”(默认)或“bdb”  --pre-1.4-compatible     : 使用与1.4之前版本兼容的格式  --pre-1.5-compatible     : 使用 Subversion 1.5 之前版本的格式  --pre-1.6-compatible     : 使用与 1.6 之前版本兼容的格式

四、调整SVN配置文件及权限文件

darker@darker:~$ cd /home/darker/work/svn/application/svndata/sadoc/conf/darker@darker:~/work/svn/application/svndata/sadoc/conf$ ll总用量 20drwxrwxr-x 2 darker darker 4096  4月 19 23:59 ./drwxrwxr-x 6 darker darker 4096  4月 19 22:28 ../-rw-rw-r-- 1 darker darker 1080  4月 19 22:28 authz-rw-rw-r-- 1 darker darker  309  4月 19 22:28 passwd-rw-rw-r-- 1 darker darker 2359  4月 19 23:59 svnserve.confdarker@darker:~/work/svn/application/svndata/sadoc/conf$ cp svnserve.conf svnserve.conf.ori  在修改配置文件前,必须先要备份
为什么必须要备份,这里主要做一下两点说明:
1)、防止配置错误,方便恢复。
2)、进行比对,配置完成后,比对进行了哪些修改。
1、修改svnserve.conf配置文件
进行如下的修改:红色的为必须要修改的
方式一:使用vi命令,打开配置文件进行修改
darker@darker:~/work/svn/application/svndata/sadoc/conf$ vi svnserve.conf### This file controls the configuration of the svnserve daemon, if you### use it to allow access to this repository.  (If you only allow### access through http: and/or file: URLs, then this file is### irrelevant.)### Visit http://subversion.tigris.org/ for more information.[general]### These options control access to the repository for unauthenticated### and authenticated users.  Valid values are "write", "read",### and "none".  The sample settings below are the defaults.anon-access = none   取消匿名访问,必须使用用户名密码进行访问auth-access = write  ### The password-db option controls the location of the password### database file.  Unless you specify a path starting with a /,### the file's location is relative to the directory containing### this configuration file.### If SASL is enabled (see below), this file will NOT be used.### Uncomment the line below to use the default password file.password-db = /home/darker/work/svn/application/svnpasswd/passwd  指定项目的密码文件,这里指定的是整个版本库的密码文件,方便将密码进行统一的管理### The authz-db option controls the location of the authorization### rules for path-based access control.  Unless you specify a path### starting with a /, the file's location is relative to the the### directory containing this file.  If you don't specify an### authz-db, no path-based access control is done.### Uncomment the line below to use the default authorization file.authz-db = /home/darker/work/svn/application/svnpasswd/authz  指定项目的权限文件  同上### This option specifies the authentication realm of the repository.### If two repositories have the same authentication realm, they should### have the same password database, and vice versa.  The default realm### is repository's uuid.# realm = My First Repository[sasl]### This option specifies whether you want to use the Cyrus SASL### library for authentication. Default is false.### This section will be ignored if svnserve is not built with Cyrus### SASL support; to check, run 'svnserve --version' and look for a line### reading 'Cyrus SASL authentication is available.'# use-sasl = true### These options specify the desired strength of the security layer### that you want SASL to provide. 0 means no encryption, 1 means### integrity-checking only, values larger than 1 are correlated### to the effective key length for encryption (e.g. 128 means 128-bit### encryption). The values below are the defaults.# min-encryption = 0# max-encryption = 256
注意:svnserve.conf中每个参数都要顶格写,开头不能有空格。
方式二:快速修改替换方法
darker@darker:~/work/svn/application/svndata/sadoc/conf$ sed -i 's/# 修改前的内容/修改后的内容' 指定修改的文件
最后,做一下比对,看修改了哪些内容:命令如下
方式一: diff 备份的文件 修改后的配置文件
darker@darker:~/work/svn/application/svndata/sadoc/conf$ diff svnserve.conf.ori svnserve.conf
方式二:
darker@darker:~/work/svn/application/svndata/sadoc/conf$ egrep "\-access|\-db =" svnserve.confanon-access = noneauth-access = writepassword-db = /home/darker/work/svn/application/svnpasswd/passwdauthz-db = /home/darker/work/svn/application/svnpasswd/authz
2、把密码、认证文件拷贝到版本库相关目录中(这里只是为了快速创建,自己创建也可以)
darker@darker:~/work/svn/application/svndata/sadoc/conf$ cp authz passwd /home/darker/work/svn/application/svnpasswd/
拷贝完成后,修改权限,使用root用户进行修改(修改成只有root用户修改或指定的用户进行修改)
我们这里使用的darker用户,因此需要切换用户,命令如下,这里就不进行权限的修改
darker@darker:~/work/svn/application/svndata/sadoc/conf$ chmod 700 /home/darker/work/svn/application/svnpasswd/
注意:在实际应用中,必须进行权限的修改。
3、修改版本库密码、认证文件:
darker@darker:~/work/svn/application$ cd /home/darker/work/svn/application/svnpasswd/darker@darker:~/work/svn/application/svnpasswd$ ll总用量 16drwx------ 2 darker darker 4096  4月 20 00:00 ./drwxrwxr-x 4 darker darker 4096  4月 19 21:52 ../-rw-rw-r-- 1 darker darker 1160  4月 19 23:52 authz-rw-rw-r-- 1 darker darker  347  4月 19 23:55 passwd
1)、修改密码文件
记住:在修改前进行备份
darker@darker:~/work/svn/application/svnpasswd$ vi 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 = sallyssecretdarker = darker   xiaoqiang = xiaoqiang    这里指定了两个用户   用户名 = 密码~  
注意:
a、等号前为SVN帐号,等号后为SVN密码,密码是明文的,注意密码文件的权限控制
b、更改svnserve.conf时,需要重启SVN,更改authz,passwd时不需要重启。
2)、修改认证文件
darker@darker:~/work/svn/application/svnpasswd$ vi authz### This file is an example authorization file for svnserve.### Its format is identical to that of mod_authz_svn authorization### files.### As shown below each section defines authorizations for the path and### (optional) repository specified by the section name.### The authorizations follow. An authorization line can refer to:###  - a single user,###  - a group of users defined in a special [groups] section,###  - an alias defined in a special [aliases] section,###  - all authenticated users, using the '$authenticated' token,###  - only anonymous users, using the '$anonymous' token,###  - anyone, using the '*' wildcard.###### A match can be inverted by prefixing the rule with '~'. Rules can### grant read ('r') access, read-write ('rw') access, or no access### ('').[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# [/foo/bar]# harry = rw# &joe = r# * =# [repository:/baz/fuz]# @harry_and_sally = rw# * = rsagroup = darker,xiaoqiang   创建用户组[sadoc:/]     指定svn版本库,/:指定这个版本库,也可以指定某个分支darker = rw   指定某个用户的操作权限,这里指定的用户必须是在密码文件中进行定义的xiaoqiang = r@sagroup = r   指定组的操作权限,使用@指定,这里的组也是在上面创建的。
3)、重启SVN服务
darker@darker:~/work/svn/application/svnpasswd$ pkill svnservedarker@darker:~/work/svn/application/svnpasswd$ svnserve -d -r /home/darker/work/svn/application/svndata

五、客户端软件:TortoiseSVN

在windows上安装,这里就不说了,网上资料一堆。
安装完成后,连接测试我们在Linux上搭建的SVN服务:
1)、在任意盘符新建文件夹。比如:在桌面创建svntest1
2)、选择svntest1,右击,点击check out。将出现如下界面:


3)、在URL of repository中添加svn服务路径:
svn://192.168.xxx.xxx/sadoc
4)、点击Finish,将出现用户名、密码界面,表示我们SVN服务搭建基本成功

5)、输入用户名,密码后点击OK。

则,SVN服务搭建成功。












0 0
原创粉丝点击