安装 Svn服务器

本文详细介绍如何在Linux环境下安装配置Subversion (SVN)服务器,包括检查版本、安装、配置服务、创建仓库、权限管理及开机启动流程。

1、检查svn版本是否有安装     

[root@huangkai200 ~]# rpm -qa subversion
[root@huangkai200 ~]# 

执行上面的命令,没有任何显示,表示没有安装,如果有,执行 yum remove subversion 删除。

2、执行安装

[root@huangkai200 ~]# yum -y install subversion

等待安装完成即可

3、配置和启动svn服务器

  创建目录 :   

[root@huangkai200 ~]# mkdir -p /data/svn/data   # svn数据保存目录 
[root@huangkai200 ~]# mkdir -p /data/svn/passwd   #svn公共用户密码与权限目录

  启动 svn服务:

 [root@huangkai200 ~]#svnserve -d -r /data/svn/data/ 

# -d 守护进程启动

# -r  指定svn目录

  查看服务进程:

[root@huangkai200 ~]# ps -ef|grep svn
root      1748     1  0 21:44 ?        00:00:00 svnserve -d -r /data/svn/data/
root      1771  1401  0 21:45 pts/0    00:00:00 grep --color=auto svn
[root@huangkai200 ~]# 

  查看端口号

    svn默认使用的端口号为 3690

[root@huangkai200 ~]# lsof -i:3690
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
svnserve 1748 root    3u  IPv4  24804      0t0  TCP *:svn (LISTEN)

[root@huangkai200 ~]# netstat -lntup|grep 3690
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      1748/svnserve       
[root@huangkai200 ~]#

 

4、创建svn仓库

[root@huangkai200 data]# svnadmin create hk   #创建仓库, hk 是仓库名称

[root@huangkai200 data]# ls  
hk
[root@huangkai200 data]# cd hk/
[root@huangkai200 hk]# ll  # 查看仓库目录结构
total 16
drwxr-xr-x 2 root root   51 Mar 12 21:58 conf   # svn仓库配置文件 
drwxr-sr-x 6 root root 4096 Mar 12 21:58 db   #数据存放文件
-r--r--r-- 1 root root    2 Mar 12 21:58 format 
drwxr-xr-x 2 root root 4096 Mar 12 21:58 hooks
drwxr-xr-x 2 root root   39 Mar 12 21:58 locks
-rw-r--r-- 1 root root  229 Mar 12 21:58 README.txt
[root@huangkai200 hk]# cd conf/ 
[root@huangkai200 conf]# ll 
total 12
-rw-r--r-- 1 root root 1080 Mar 12 21:58 authz    #权限管理文件 
-rw-r--r-- 1 root root  309 Mar 12 21:58 passwd    #用户与密码文件 
-rw-r--r-- 1 root root 3090 Mar 12 21:58 svnserve.conf  #主配置文件,包含上面authz 与 passwd文件
[root@huangkai200 conf]# 

5、修改 svnserver.conf 主配置文件 :

[root@huangkai200 conf]# vi svnserve.conf

1 ### This file controls the configuration of the svnserve daemon, if you
      2 ### use it to allow access to this repository.  (If you only allow
      3 ### access through http: and/or file: URLs, then this file is
      4 ### irrelevant.)
      5 
      6 ### Visit http://subversion.apache.org/ for more information.
      7 
      8 [general]
      9 ### The anon-access and auth-access options control access to the
     10 ### repository for unauthenticated (a.k.a. anonymous) users and
     11 ### authenticated users, respectively.
     12 ### Valid values are "write", "read", and "none".
     13 ### Setting the value to "none" prohibits both reading and writing;
     14 ### "read" allows read-only access, and "write" allows complete
     15 ### read/write access to the repository.
     16 ### The sample settings below are the defaults and specify that anonymous
     17 ### users have read-only access to the repository, while authenticated
     18 ### users have read and write access to the repository.
     19 # anon-access = read #将此项目默认配置改为 none,svn默认对未认证的用户有只读权限,我们要将此用户的权限设置为 none,然后将 20行 的 auth-access 的注解删除

      anon-access = none    
     20 auth-access = write
     21 ### The password-db option controls the location of the password
     22 ### database file.  Unless you specify a path starting with a /,
     23 ### the file's location is relative to the directory containing
     24 ### this configuration file.
     25 ### If SASL is enabled (see below), this file will NOT be used.
     26 ### Uncomment the line below to use the default password file.

# svn默认每个仓库会指定密码文件 ,为了多个仓库统一密码管理 ,将此选项设置为公共的密码文件
     27 password-db = /data/svn/passwd/passwd
     28 ### The authz-db option controls the location of the authorization
     29 ### rules for path-based access control.  Unless you specify a path
     30 ### starting with a /, the file's location is relative to the the
     31 ### directory containing this file.  If you don't specify an
     32 ### authz-db, no path-based access control is done.
     33 ### Uncomment the line below to use the default authorization file.
     34 authz-db = /data/svn/passwd/authz  #和密码一样,将此选项设置为公共的权限文件
     35 ### This option specifies the authentication realm of the repository.
     36 ### If two repositories have the same authentication realm, they should
     37 ### have the same password database, and vice versa.  The default realm
     38 ### is repository's uuid.
     39 # realm = My First Repository

6、拷贝authz  和 passwd 文件 到 公共用户与密码的目录 

[root@huangkai200 hk]# cp authz passwd /data/svn/passwd

[root@huangkai200 passwd]# ll # 可以看到,如下两个文件的权限为 644(文件所有者可读可写,所在组可读,其它组可读,这样,其它用户就可以看到这两个文件 ,文件的安全性就降低了)
total 8
-rw-r--r-- 1 root root 1080 Mar 12 22:27 authz
-rw-r--r-- 1 root root  329 Mar 12 22:25 passwd
[root@huangkai200 passwd]# 

 修改文件权限:

[root@huangkai200 passwd]# chmod 600 * #(给文件所有者可读写权限,其它用户没有权限)
[root@huangkai200 passwd]# ll
total 8
-rw------- 1 root root 1080 Mar 12 22:27 authz
-rw------- 1 root root  329 Mar 12 22:25 passwd
[root@huangkai200 passwd]# 

 

7、svn添加账户

在 passwd文件中[users]下按例子添加账户

[root@huangkai200 passwd]# 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 = sallyssecret
huangkai = huangkai  #添加账号,等号前为用户名,等号后为 密码

8、修改authz配置文件

[root@huangkai200 passwd]# 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
# * = r

[hk:/]

huangkai = rw

#权限配置规则
#[版本库:/项目/目录]
#用户名 = rw(可写可读) | r (只读)
#也可以指定组,一个组对应一个或多个用户多个用户用 逗号隔开
# gruop_1 = huangkai,...
#为组配置权限规则,如 : @ 组名
# @gruop_1 = rw

 

修改 authz 与 passwd文件 不需要重启svn服务器,但修改 svnserver.conf 必须重启使配置生效,

authz 与 passwd 配置文件不能写错,否则服务可能不能正常启动。

启动服务
[root@huangkai200 passwd]# lsof -i:3690
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
svnserve 1748 root    3u  IPv4  24804      0t0  TCP *:svn (LISTEN)

root@huangkai200 passwd]# kill -9 1748
[root@huangkai200 passwd]# ps -ef|grep svn
root      3252  1401  0 22:58 pts/0    00:00:00 grep --color=auto svn
[root@huangkai200 passwd]# svnserve -d -r /data/svn/data/

9、svn 开机启动

首先:编写一个启动脚本svn_startup.sh,我放在/data/svn/svn_startup.sh

#!/bin/bash
/usr/bin/svnserve -d -r /data/svn/data/

这里的svnserve路径保险起见,最好写绝对路径,因为启动的时候,环境变量也许没加载。
绝对路径怎么查?使用 which svnserve查看

[root@huangkai200 hk]# which svnserve 
/usr/bin/svnserve
[root@huangkai200 hk]# 

然后修改该脚本的执行权限

[root@huangkai200 svn]# chmod 700 svn_startup.sh

最后:加入自动运行

[root@huangkai200 svn]#vi /etc/rc.d/rc.local

在末尾添加脚本的路径,如:/data/svn/svn_startup.sh

看看 /etc/rc.d/rc.local的权限,如果没有可执行权限,则需要设置 , chmod 711 /etc/rc.d/rc.local

 现在,你可以重启一下试试了

10、svn 客户端连接 :

svn://ip地址:3690/hk

 

 

转载于:https://my.oschina.net/hkai/blog/857226

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值