抑郁症健康,内容丰富有趣,生活中的好帮手!
抑郁症健康 > Linux下安装SVN服务端 最详细的教程来啦~

Linux下安装SVN服务端 最详细的教程来啦~

时间:2024-08-05 04:16:31

相关推荐

创作不易,如果觉得这篇文章对你有帮助,欢迎各位老铁点个赞呗,您的支持是我创作的最大动力!

文章目录

前言1 安装2 配置svn2.1 创建svn仓库2.2 设置svn账号2.3 配置authz2.3.1 authz文件基础配置2.3.2 使用用户分组 2.4 svn服务端配置文件 3 启动svn服务4 设置svn开机自启动5 使用客户端连接

前言

前几天,没事搭建了一个svn服务器,虽然现在项目管理中,主流的是使用git仓库管理,这里笔者也把前几年使用的svn服务器搭建做一下总结,也算是一个美好的回忆。

1 安装

这里使用一种比较简单的方式,使用yum安装,执行以下命令,即完成了安装。

yum install subversion

2 配置svn

2.1 创建svn仓库

看个人习惯,我一般习惯把软件安装到/usr/local目录下,这里打算在/usr/local下建立一个名为svn的仓库(repository)。

第一步:

进入/usr/local目录,并且创建一个svn目录

使用命令:cd /usr/local && mkdir svn

第二步:

/usr/local下建立一个名为svn的仓库

使用命令:svnadmin create /usr/local/svn

以后所有代码都会放在这个svn仓库(repository)下面,创建成功后,在svn下面会产生一下几个文件夹。

在svn目录下,使用ls svn命令,查看svn仓库下的文件

主要文件夹说明:

db目录存放的是svn提交后的文件

conf这里特别关注一下conf文件夹,这个是存放配置文件的,conf目录下有以下几个文件:

authz是权限控制管理文件

passwd是svn帐号密码配置管理文件

svnserve.conf是svn服务端配置文件

下面,我们依次配置3个文件。

2.2 设置svn账号

passwd是svn帐号密码配置管理文件,所以需要配置passwd文件。

使用以下命令,编辑配置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 = sallyssecretzhangsan=123456lisi=123456

上面的例子中我们创建了张三用户和李四用户,并且设置了密码,下面,我们需要给用户配置读写权限。

2.3 配置authz

authz这个文件,是用来给svn用户配置权限的。

2.3.1 authz文件基础配置

版本库目录格式:

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

@<用户组名> = <权限>

<用户名> = <权限>

其中,方框号内部分可以有多种写法:

/,表示根目录(仓储目录)及以下。根目录是svnserve启动时指定的,我们指定/usr/local/svn,这样,/就是表示对全部版本库设置权限。

权限主体可以是用户组、用户或 * ,用户组在前面加@,* 表示全部用户。

权限可以是wrrw,空表示没有任何权限。

示例:

使用命令编辑配置文件: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# * =#这里[/]表示svn仓库,即/usr/local/svn/下所有文件[/]zhangsan=rwlisi=r*=# [repository:/baz/fuz]# @harry_and_sally = rw# * = r

主要修改如下框起来的内容:

上面配置的含义是:zhangsan用户对/usr/local/svn/(该目录即是svn仓库)下所有文件具有可读可写权限,lisi用户具有读的权限,其它用户均无任何权限。

最后一行*=很重要不能少。

*=含义

*” 是指所有人,“=” 后面为空,表示没有任何权限

连起来就表示所有人没有任何权限

注:

=”后面有3种情况

:表示没有任何权限

r:表示只读权限

rw:表示读写权限

2.3.2 使用用户分组

authz权限管理文件中,有个groups,细心地你应该发现了,这个就是用来配置组的,一般来说,开发团队比较大,项目小组比较多的时候,会使用这个分组功能。

groups格式:

<用户组名> = <用户1>,<用户2>

其中,1个用户组可以包含1个或多个用户,用户间以逗号分隔

配置示例:

[groups]group1 = zhangsangroup2 = lisi,wangwu[/]@group1 = rw@group2 = r* =

上面配置中创建了2个分组,分组1的用户具有读写权限,可以提交代码,分组2的用户只读权限,不能提交代码。

2.4 svn服务端配置文件

svnserve.conf是svn服务端的配置文件。

使用命令编辑配置文件: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 / for more information.[general]### The anon-access and auth-access options control access to the### repository for unauthenticated (a.k.a. anonymous) users and### authenticated users, respectively.### Valid values are "write", "read", and "none".### Setting the value to "none" prohibits both reading and writing;### "read" allows read-only access, and "write" allows complete ### read/write access to the repository.### The sample settings below are the defaults and specify that anonymous### users have read-only access to the repository, while authenticated### users have read and write access to the repository.anon-access = noneauth-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 = /usr/local/svn### The force-username-case option causes svnserve to case-normalize### usernames before comparing them against the authorization rules in the### authz-db file configured above. Valid values are "upper" (to upper-### case the usernames), "lower" (to lowercase the usernames), and### "none" (to compare usernames as-is without case conversion, which### is the default behavior).# force-username-case = none[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

这里面只需要配置以下5个内容即可:

禁止匿名用户访问:anon-access = none

授权用户可写:auth-access = write

使用哪个文件作为账号配置文件:password-db = passwd

使用哪个文件作为权限配置文件:authz-db = authz

指定版本库所在目录,即svn仓库:realm = /usr/local/svn,这里的realm即是你设置的svn仓库的目录

说明:

匿名用户权限(none:拒绝,write:读写,read:只读权限)

匿名用户可读:anon-access = read,这种安全级别不高,别人可以访问你的资源,不推荐使用

anon-access 属性对目录权限的影响

你想将你的代码库开放给所有人访问,于是你就开放了匿名访问权限,在 svnserve.conf 文件中添加一行:anon-access=read

可是对于部分目录,你又不希望别人看到,于是针对那些特别目录,你在 authz.conf 里面进行配置,添加了授权访问的人,并添加了* =标记。你认为一切OK了,可是你缺发现,那个特别目录却无法访问了,总是提示Not authorized to open root of edit operation或者未授权打开根进行编辑操作。你再三检查你配置的用户名与密码,确认一切正确,还是无法解决问题。

原来,Subversion 有个小 bug ,当anon-access=read并且某个目录有被设置上* =标记,则会出现上述问题。这个 bug 在当前最新版本上(v1.4)还存在,也许在下一版本内可以被改正吧。

解决的办法是,在 svnserve.conf 中,将anon-access 设置成 none 。

3 启动svn服务

启动svn服务端:svnserve -d -r /usr/local/svn

停止svn服务:killall svnserve

上述启动命令中,-d表示守护进程,-r表示在后台执行。

出现以下服务,说明svn服务启动成功。

4 设置svn开机自启动

笔者之前都是很偷懒,启动命令太长,不好记,就配置了systemcl去启动svn服务。

一般来说,svn服务端都是配置在Linux服务器,笔者这里以Linux为例,设置svn开机自启动。

查看systemd 里svn的配置文件:cat /lib/systemd/system/svnserve.service

[Unit] Description=Subversion protocol daemon After=syslog.target network.target [Service] Type=forking EnvironmentFile=/etc/sysconfig/svnserve ExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid $OPTIONS [Install] WantedBy=multi-user.target

通过查看svn配置文件,可以找到 svn服务的配置文件:/etc/sysconfig/svnserve

使用以下命令,编辑配置文件:

vi /etc/sysconfig/svnserve

# OPTIONS is used to pass command-line arguments to svnserve.# # Specify the repository location in -r parameter:OPTIONS="-r /usr/local/svn"

将 OPTIONS="-r /var/svn" 改为 svn 版本库存放的目录即可。

如:我的svn仓库是/usr/local/svn,修改之后,OPTIONS="-r /usr/local/svn"

使用命令,设置自启动:systemctl enable svnserve.service

出现以下内容,说明设置svn自启动成功:

Created symlink from /etc/systemd/system/multi-user.target.wants/svnserve.service to /usr/lib/systemd/system/svnserve.service.

启动服务:

systemctl start svnserve.service

查看svn服务启动状态

ps -aux | grep svn或者ps -ef | grep svnserve或者systemctl status svnserve或者service svnserve status

这四种命令都可以查看svn服务启动的状态。

5 使用客户端连接

博主这里比较喜欢使用小乌龟(TortoiseSVN)客户端,连接svn服务端,当然啦,实际开发中,多半是会使用开发工具,比如Eclipse或者Idea。

输入服务地址:svn://ip即可,输入用户名和密码就能连接成功了。

svn服务安装时,默认端口3690,如果你修改了端口,那么要记得加上修改后的端口号。

注意:有可能访问不到,如果是阿里云服务,需要配置安全组:

如果你的服务器或者虚拟机开启了防火墙,需要开放3690端口:

开启3690防火墙端口

firewall-cmd --zone=public --add-port=3690/tcp --permanent

重新加载防火墙配置

firewall-cmd --reload

参考资料:/liuxianan/p/linux_install_svn_server.html

写博客是为了记住自己容易忘记的东西,另外也是对自己工作的总结,希望尽自己的努力,做到更好,大家一起努力进步!

如果有什么问题,欢迎大家一起探讨,代码如有问题,欢迎各位大神指正!

给自己的梦想添加一双翅膀,让它可以在天空中自由自在的飞翔!

如果觉得《Linux下安装SVN服务端 最详细的教程来啦~》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。