Centos搭建SVN服务

2 篇文章 0 订阅

为了在代码开发中能够更好的协调以及代码版本的维护,通常我们都会使用到版本控制工具。这里我们就要来介绍Subversion,他的简称就是SVN,一个开源的版本管理工具,用于多人开发同一个项目。

现在我们要在Centos7系统上安装

一、安装SVN

1,执行安装命令

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

    #查看是否安装成功

[root@moc1 ~]# svn --version

    #查看svn的安装位置

[root@moc1 ~]# rpm -ql subversion

2,新建目录,存放svn版本库

[root@moc1 ~]# mkdir /svn
[root@moc1 ~]# cd svn

3,创建svn版本库

[root@moc1 svn]# svnadmin create ./project

    #进入目录

[root@moc1 svn]# cd project

    #查看目录

[root@moc1 project]# ll

        总用量 8

        drwxr-xr-x. 2 root root  54 3月   6 14:47 conf

        drwxr-sr-x. 6 root root 233 3月   6 14:15 db

        -r--r--r--. 1 root root   2 3月   6 14:15 format

        drwxr-xr-x. 2 root root 231 3月   6 14:15 hooks

        drwxr-xr-x. 2 root root  41 3月   6 14:15 locks

        -rw-r--r--. 1 root root 229 3月   6 14:15 README.txt

    #目录和文件说明

        conf:版本库的配置文件,账户和权限都在这里设置

        db:放置版本库提交的数据

        format:这是一个文本文件,里面只存放一个整数,表示当前版本库的版本号

        hooks:放置钩子脚本文件的目录

        locks:放置subversion的db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端

    #进入conf目录

[root@moc1 project]# cd conf
[root@moc1 conf]# ll

    总用量 12

    -rw-r--r--. 1 root root 1135 3月   6 14:47 authz

    -rw-r--r--. 1 root root  333 3月   6 14:44 passwd

    -rw-r--r--. 1 root root 3080 3月   6 14:20 svnserve.conf

    #文件说明

        authz:权限控制文件

        passwd:账号密码文件

        svnserve.conf:svn服务配置文件

4,配置svn版本库

    #修改svnserve.conf文件

[root@localhost conf]# vim 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         #控制匿名用户访问版本库的权限,也可设置为read

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 = 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 = 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 = This is My First Test 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

保存退出

这里去掉被注释的参数,我用中文标记了,做了说明。划重点:去掉注释的参数前面不能有空格,否则会出错

 

    #配置访问版本库的账号和密码

[root@moc1 conf]# vim 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

test1 = 123456

test2 = 654321

保存退出

    #配置账号授权文件

[root@moc1 conf]# vim 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

admin = test1

user = test2

[/svn/project]

@admin = rw 

@user = r

保存退出

5,启动SVN服务

[root@moc1 conf]# svnserve -d -r /svn

-d表示在后台运行,-r指定svn服务目录,这样我们的SVN服务就搭建完成了

我们在自己的电脑上下载一个小乌龟(TortoiseSVN),输入检出地址:svn://192.168.0.3/project就可以吧版本库检出到我们的电脑了。

如果我们要停止SVN,查找到SVN相关京城

[root@moc1 ~]# ps -ef | grep svn

使用命令

[root@moc1 ~]# kill -9 进程号

或者使用命令

[root@moc1 ~]# killall svnserve

来停止SVN服务。

 

二、其他

这里额外介绍一下svn的其他相关配置和参数,说不定会用上。

1,启动svn服务的方式介绍

上面我们介绍的启动比较简单,但是这个也不难

语法结构:svnserve -d -r 版本库目录 --listen-port 端口号

--listen-port :指定SVN服务监听的端口,不叫这个参数则默认监听3690

2,单库和多库的启动方式

由于 -r 配置的版本库目录不一样,可以实现单库和多库

方式一: -r 直接指定到版本库(单库)

svnserve -d -r /svn/project

这条命令启动svn服务,则只能一个版本库在工作,通常适用于只有一个项目开发的时候。

同时authz配置文件中对版本库权限的配置应该这样:

admin = test1

user = test2

[/]

@admin = rw 

@user = r

小乌龟上直接使用svn服务器的IP就可以访问到版本库了。

方式二:指定到版本库的上级目录(多库)

svnserve -d -r /svn

这条命令就是我们前面启动的方式,可以通过目录访问指定版本库,适用于多个项目开发维护的时候。

同时authz配置文件中对版本库权限的配置应该这样:

admin = test1

user = test2

[project/]

@admin = rw 

@user = r

[project1/]

@admin = rw 

@user = rw

配置多个目录账号访问权限,这里使用[project/]表示对应目录。

使用svn://192.168.0.1/project,这个的地址就可以访问到peoject版本库了。

3,authz权限配置文件参数说明

admin=test1,test11    #创建admin组,组成员为:test1,test11

user=test2                 #创建use用户组,组成员为:test2

[project:/]      #赋予根权限,便于管理和权限控制,可以把权限细化到版本库中赌赢的目录

@admin=rw    #admin组有读写权限

@user=r    #user组只有读权限

*=     #表示出了上面设置的权限用户组之外,其他所有用户都设置空权限。空权限表示进制访问本目录,这个对权限要求高的话可以加上。

    #语法介绍

    [<版本库>:/项目/目录]

    @<用户组>=权限

    <用户名>=权限

    其中,中括号[]里面的内容有许多写法:

    [/],表示根目录机器以下目录,根目录是svn启动的时候指定好的,上述实例中我们指定的是:[/],表示对所有版本库设置权限。

    [project:/],表示对project版本库设置权限

    [project:/test1],表示对project版本库中的test1项目设置权限

    [project:/test1/first],表示对project版本库中的test1项目的first目录设置权限

    这样我们就可以对指定目录设置用户的访问权限了。

    权限的主体可以是用户组,用户或者*,用户组在前面要以@符号开头,*表示所有用户。权限分为:r,w,rw和null,null表示没有任何权限。

    温馨提示,authz配置文件中的参数.conf开头不能有空格。更改svnserve.conf文件需要重启SVN服务,另外两个文件则不用。

4,防火墙端口

    如果检出的时候发现svn服务器拒绝访问,那就可能是防火墙问题

    #查看svn使用的端口

    netstat -antp | grep svn 

    #增加允许访问端口

    firewall-cmd  --premanent --add-port=3690/tcp

    firewall-cmd --reload

    

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值