Centos7.X搭建svn server以及windows用户commit和checkout以及各种问题汇总

1.搭建svn server

(1)yum安装subversion

yum install subversion

(2) 查看安装版本

svnserve --version

(3)查看安装路径

rpm -ql subversion

2.创建版本库

(1)创建用于存放版本库的目录

mkdir 目录
//我创建的目录:mkdir /opt/svn/repository

(2)创建svn版本库

svnadmin create /opt/svn/repository

此时,库目录下会生成一下文件
在这里插入图片描述
dav目录等后面讲到apache的使用会提到。
在这里插入图片描述

3.配置svn的基本信息

在conf目录下
authz :创建svn组和组用户的权限
passwd:设置组中用户的账号和密码
svnserve.conf :配置版本库信息、用户文件和用户密码文件的路径、版本库路径
(如果是多个仓库通用相同权限、账号和密码控制,则可以将authz,passwd文件放到svn目录下)

在这里插入图片描述
(1)在authz 中创建svn组和组用户的权限
该文件由[groups]配置段和若干版本库路径权限段组成
[groups]配置段格式:<用户组>=<用户列表>
用户列表由若干个用户组或用户名构成,用户组或用户名之间用逗号",“分隔,引用用户组时要使用前缀”@"
版本库路径权限段格式:
[<版本库名>:<路径>]如版本库abc路径/tmp的版本库路径权限段的段名为"[abc:/tmp]"。
可省略段名中的版本库名。若省略版本库名,则该版本库路径权限段对所有版本库中相同路径的访问控制都有效。如:[/tmp]
版本库路径权限段中配置行格式有如下三种:
<用户名> = <权限>
<用户组> = <权限>

  • = <权限>
    其中,"*"表示任何用户;权限的取值范围为’’、‘r’和’rw’,’'表示对该版本库路径无任何权限,'r’表示具有只读权限,'rw’表示有读写权限。
    配置:
[groups]
test = user1,hhh //创建test用户组,并添加user1 user2用户

[/]    //指定根目录的权限
@test = rw  //设置test组的权限为可读可写

(2)在passwd中设置组中用户的账号和密码
该文件由一个[users]配置段组成,格式:<用户名>=<口令> 注:口令为未经过任何处理的明文。

[users]

user1 = 111 //用户名就是组添加成员是的用户     
hhh = hhh

(3)svnserve.conf
该文件由一个[general]配置段组成。格式:<配置项>=<值>
配置项分为以下5项:
1.anon-access 控制非鉴权用户访问版本库的权限。取值范围为"write"、“read"和"none”。即"write"为可读可写,"read"为只读,“none"表示无访问权限。缺省值:read
2.auth-access 控制鉴权用户访问版本库的权限。取值范围为"write”、“read"和"none”。即"write"为可读可写,"read"为只读,"none"表示无访问权限。缺省值:write
3.password-db 指定用户名口令文件名。除非指定绝对路径,否则文件位置为相对conf目录的相对路径。缺省值:passwd
4.authz-db 指定权限配置文件名,通过该文件可以实现以路径为基础的访问控制。除非指定绝对路径,否则文件位置为相对conf目录的相对路径。缺省值:authz
5.realm 指定版本库的认证域,即在登录时提示的认证域名称。若两个版本库的认证域相同,建议使用相同的用户名口令数据文件。缺省值:一个UUID(Universal Unique IDentifier,全局唯一标示)。
配置详解如下

### 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.
 
### 对于授权用户与未被授权用户的访问级别控制:read,write,write
anon-access = 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.
 
### 密码数据文件的保存位置,默认为相对路径,如果以/开头则为绝对路径
### 如果SASL开启的话,那么就不会验证该文件
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.
 
### 指定验证的范围,如果两个repo的realm属性一样,那么它们就应该使用同一个password数据库,反之亦然
### 默认的realm就是repo的唯一标示符
realm = 0.1
 
[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.'
 
### 是否开启SASL验证,默认是false的
### 此选项会默认svn服务器支持Cyrus,检查的方法是,运行'svnserve --version'命令,查看输出是否有'Cyrus SASL authentication is available.'
# use-sasl = false
  
### 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

配置:

[general]
anon-access = none        //不允许匿名用户访问
auth-access = write         //设置authz中用户的权限为可写
password-db = passwd     //指向passwd文件
authz-db = authz             //指向authz文件
realm = /opt/svn/repository   //认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字(版本库的认证域)

到此,初步配置完毕

4.关闭 开启svn

killall svnserver //杀死svn所有进程
systemctl start svnserve //开启

5.windows用户checkout和commit

在windows上安装TortoiseSVN客户端
(1)checkout
在checkout之前,先要关闭防火墙或者加入3690端口(svnserver监听端口),如果用的是阿里云,别忘了打开3690端口。否则会出现连接失败。然后将建立好的repository仓库拉取下来,再将代码放入仓库文件夹中,通过添加文件方式add 后再commit ,项目就会同步到服务器中。
在这里插入图片描述
(2)commit
会发现出现错误如下。
在这里插入图片描述
同步失败 ,是因为post-commit文件的配置以及权限原因。
(3)使用post-commit 实现同步代码
代码同步需要使用到hooks文件目录下的post-commit勾子文件,在hooks下很多tmpl文件,这些文件都是勾子的模板来的,如果需要使用的时候copy 一份去掉.tmpl后缀便可使用。
在这里插入图片描述
然后vim打开post-commit,添加如下内容

export LANG=en_US.UTF-8
svn update /opt/svn/repository--username hhh --password hhh --no-auth-cache //#svn update 自动检出的目录 
REPOS="$1"
REV="$2"

#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf //注释掉

设置post-commit的权限

chomd 777 post-commit

(4)重启svnserve,重新commit
在这里插入图片描述

6.commit的文件在svn服务器中如何查看

上传的文件被SVN自己处理成一个数据库文件,只有Repo-browser检索(TortoiseSVN中)时才能看到原文件目录。
在这里插入图片描述

7.svn在centos上的检出 更新 提交

(1)checkout到centos本地

svn checkout svn://你的ip/repository --username hhh--password hhh

提示密码默认为非加密存储在磁盘上,建议修改配置文件加密存储。并且,你可以通过修改配置文件避免提示。
在这里插入图片描述
(2)修改111.txt然后commit

svn commit -m svn://localhost/repository --username hhh --password hhh

在这里插入图片描述
(3)添加333.txt后提交

svn add 333.txt

在这里插入图片描述
(4)更新

svn update

在这里插入图片描述
此时,在windows上利用TortiousSVN更新,可以得到333.txt
在这里插入图片描述

8.配置Apache支持HTTP方式访问

当使用TortiousSVN的时候,使用的是svn协议,也可以使用http协议,这需要apahce的支持
(1)安装apahce

yum install httpd//在CentOS和RHEL上,Apache软件包和服务称为httpd

(2)安装apache的svn模块
安装成功后,会有mod_dav_svn.so和mod_authz_svn.so两个文件
查找:find / -name mod_dav_svn.so

yum install mod_dav_svn

(3)修改配置文件/etc/httpd/conf.d/subversion.conf

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so
 
<Location /svn>
    DAV svn
    SVNListParentPath on
    SVNPath /opt/svn/repository
    AuthType Basic
    Satisfy Any
    AuthName "Authorization SVN"
    AuthUserFile /opt/svn/repository/conf/passwd
    AuthzSVNAccessFile /opt/svn/repository/conf/authz
    Require valid-user
</Location>

(4)创建用户文件passwd

touch /opt/svn/passwd              #创建用户文件
htpasswd  /opt/svn/passwd admin	 #创建用户admin

//htpasswd命令是Apache的Web服务器内置工具,用于创建和更新储存用户名、域和用户基本认证的密码文件

(5)创建权限文件authz

cp /opt/svn/repository/conf/authz  /opt/svn/authz

(6)配置apache对SVN目录权限

chown -R apache:apache /opt/svn/repository

(7)配置httpd
vim打开/etc/httpd/conf/httpd.conf
修改AllowOverride None为AllowOverride All
(8)启动apache

httpd -v	      #查看已经安装的httpd的版本
rpm -qa | grep httpd  #查看是否已经安装了httpd
ps -ef | grep httpd   #查看httpd的进程
service httpd status  #查看httpd的运行状态
service httpd stop    #可以停止httpd
service httpd start   #可以启动httpd

到此,就可以使用http代理svn协议。

9.其他有关svn的命令

ps -ef|grep svn|grep -v grep //查看svn进程
netstat -ln |grep 3690 //检测svn端口
netstat -ntlp //查看使用端口
killall svnserve //停止svn
systemctl start svn //开启svn
systemctl status svn //查看svn运行状态
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值