在centos7下安装svn

SVN的安装

yum install subversion

服务端命令

1. svnserver - 控制svn系统服务的启动等

2. svnadmin - 版本库的创建/导出/导入/删除等

3. svnlook - 查看版本库的信息等

客户端命令

1. svn - 版本库的检出/更新/提交/重定向等

创建版本库

1. svnadmin create /www/version_test_1;

2. cd /www; svnadmin create version_test_2;

注意:如果 cd /www/version_test_1; svnadmin create version_test_2 会抛出异常(svnadmin: E165002: '/www/version_test_1/version_test_2' is a subdirectory of an existing repository rooted at '/www/version_test_1'),故不能再已有版本库里面再次创建版本库。

3. 指定版本库数据保存类型: svnadmin create --fs-type fsfs(数据保存类型,还可以指定dbd) xxxx(版本库名称),如果想了解fsfs和dbd的区别可以自行百度,这里不过多阐述;推荐使用fsfs数据保存类型;

删除版本库

1. rm -rvf /www/version_test_1;使用linux自带的命令把整个版本库删除即可;

版本库配置

配置文件位于: /www/version_test_2/conf/

存在三个文件分别是:

  1. authz -- 配置用户组以及用户组权限

  2. passwd -- 配置用户名和密码

  3. svnserve.conf -- 配置默认权限、权限配置文件及密码配置文件

版本库权限分组

vim 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
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.
27 # password-db = 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 
32 [general]
33 ### The anon-access and auth-access options control access to the
34 ### repository for unauthenticated (a.k.a. anonymous) users and
35 ### authenticated users, respectively.
36 ### Valid values are "write", "read", and "none".
37 ### Setting the value to "none" prohibits both reading and writing;
38 ### "read" allows read-only access, and "write" allows complete 
39 ### read/write access to the repository.
40 ### The sample settings below are the defaults and specify that anonymous
41 ### users have read-only access to the repository, while authenticated
42 ### users have read and write access to the repository.
43 # anon-access = read
44 # auth-access = write
45 ### The password-db option controls the location of the password
46 ### database file.  Unless you specify a path starting with a /,
47 ### the file's location is relative to the directory containing
48 ### this configuration file.
49 ### If SASL is enabled (see below), this file will NOT be used.
50 ### Uncomment the line below to use the default password file.
51 # password-db = passwd
52 ### The authz-db option controls the location of the authorization
53 ### rules for path-based access control.  Unless you specify a path
54 ### starting with a /, the file's location is relative to the the
55 ### directory containing this file.  If you don't specify an
56 ### authz-db, no path-based access control is done.
57 ### Uncomment the line below to use the default authorization file.
58 # authz-db = authz
59 ### This option specifies the authentication realm of the repository.
60 ### If two repositories have the same authentication realm, they should
61 ### have the same password database, and vice versa.  The default realm
62 ### is repository's uuid.
63 # realm = My First Repository
64 ### The force-username-case option causes svnserve to case-normalize
65 ### usernames before comparing them against the authorization rules in the
66 ### authz-db file configured above.  Valid values are "upper" (to upper-
67 ### case the usernames), "lower" (to lowercase the usernames), and
68 ### "none" (to compare usernames as-is without case conversion, which
69 ### is the default behavior).
70 # force-username-case = none
71 
72 [sasl]
73 ### This option specifies whether you want to use the Cyrus SASL
74 ### library for authentication. Default is false.
75 ### This section will be ignored if svnserve is not built with Cyrus
76 ### SASL support; to check, run 'svnserve --version' and look for a line
77 ### reading 'Cyrus SASL authentication is available.'
78 # use-sasl = true
79 ### These options specify the desired strength of the security layer
80 ### that you want SASL to provide. 0 means no encryption, 1 means
81 ### integrity-checking only, values larger than 1 are correlated
82 ### to the effective key length for encryption (e.g. 128 means 128-bit
83 ### encryption). The values below are the defaults.
84 # min-encryption = 0
85 # max-encryption = 256

在19行: anon-access = read || write || none,表示没有用户名和密码的用户访问该版本库怎么操作

在20行: auth-access = write || read || none,表示通过用户名和密码的用户访问该版本库怎么操作

上述 read、write 、none 意思:

1. read 指允许更新代码

2. write 指允许更新代码,也允许提交代码

3. none 指什么都干不了

在27行: password-db = passwd,表示指定用户名和密码的文件路径(既支持相对路径,又支持绝对路径)

在58行: authz-db = authz,表示指定权限分组的文件路径(既支持相对路径,又支持绝对路径)

最终将svnserve.conf文件修改为:

anon-access = none

auth-access = write

password-db = passwd

authz-db = authz

:wq 保存退出即可。

vim passwd :

1 ### This file is an example password file for svnserve.
2 ### Its format is similar to that of svnserve.conf. As shown in the
3 ### example below it contains one section labelled [users].
4 ### The name and password for each user follow, one account per line.
5 
6 [users]
7 # harry = harryssecret
8 # sally = sallyssecret

在7、8行已经给出了用户和密码的格式,则现只需要在9行添加:

jiangbo = 123456

随后再可以添加其他人来操作该版本库:

zhangsan = 123456
lisi = 123456
wangwu = 123456

:wq 保存退出即可。

vim authz:

 1 ### This file is an example authorization file for svnserve.
 2 ### Its format is identical to that of mod_authz_svn authorization
 3 ### files.
 4 ### As shown below each section defines authorizations for the path and
 5 ### (optional) repository specified by the section name.
 6 ### The authorizations follow. An authorization line can refer to:
 7 ###  - a single user,
 8 ###  - a group of users defined in a special [groups] section,
 9 ###  - an alias defined in a special [aliases] section,
10 ###  - all authenticated users, using the '$authenticated' token,
11 ###  - only anonymous users, using the '$anonymous' token,
12 ###  - anyone, using the '*' wildcard.
13 ###
14 ### A match can be inverted by prefixing the rule with '~'. Rules can
15 ### grant read ('r') access, read-write ('rw') access, or no access
16 ### ('').
17 
18 [aliases]
19 # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
20 
21 [groups]
22 # harry_and_sally = harry,sally
23 # harry_sally_and_joe = harry,sally,&joe
24 
25 # [/foo/bar]
26 # harry = rw
27 # &joe = r
28 # * =
29 
30 # [repository:/baz/fuz]
31 # @harry_and_sally = rw
32 # * = r

在18行:别名配置

在21行:用户组配置,格式是(组名 = 用户1,用户2,...,用户n)

示例:

[groups]
# 产品经理组
pm = jiangbo
# 开发人员组
dev = zhangsan,wangwu
# 菜鸟组
rookie = lisi

在25行:表示版本库的目录,例如 [/] 表示版本库的根目录,[/foo/bar] 表示版本库根目录下的 foo 文件夹下面的 bar 文件夹

示例:

[/]
# 表示项目径路组有更新和提交的权限
@pm = rw
# 表示开发组只有更新的权限
@dev = r
# 表示 李四 这个用户自由更新的权限
lisi = r
#需要增加“* = r”,否则其他用户连跟目录都进不来、就认证失败了
* = r

在30行:表示repository版本库下目录,例如 [repository:/] 表示repository版本库的根目录,[repository:/baz/fuz] 表示repository版本库目录下的 baz 文件夹下面的 fuz 文件夹

示例:

[version_test_n:/]
# 表示该版本库下面所有用户都有更新和提交的权限
* = rw

:wq 保存退出即可。

版本库的访问

服务端和客户端的关系(svn服务端 :svn客户端 = 1 : n )

运行svn服务端: svnserve -d -r /www/version_test_2/ ,如果没有什么异常消息则证明svn服务端运行成功!

个人定义的版本库的访问两种形式:

  1. 命令行的形式访问

    $ mkdir svntest

    $ cd svntest

    /svntest$ svn checkout(co) svn://192.168.0.104 (--username jiangbo --password 123456)

  2. 图像界面的形式访问

    下载tortoisesvn进行svn检出

SVN服务自启动

vim /etc/rc.local:

 1 #!/bin/bash
 2 # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
 3 #
 4 # It is highly advisable to create own systemd services or udev rules
 5 # to run scripts during boot instead of using this file.
 6 #
 7 # In contrast to previous versions due to parallel execution during boot
 8 # this script will NOT be run after all other services.
 9 #
10 # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
11 # that this script will be executed during boot.
12 
13 touch /var/lock/subsys/local

在13行下面加上 svn 服务自启动:

svnserve -d -r /www/version_test_2/

特别注意:

安装好 svn 服务后,默认是没有随系统启动自动启动的, CentOS 7 的 /etc/rc.d/rc.local 是没有执行权限的, 系统建议创建 systemd service 启动服务

于是查看 systemd 里 svn 的配置文件 /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 的 service 配置文件 /etc/sysconfig/svnserve 编辑配置文件

vi /etc/sysconfig/svnserve

将 OPTIONS="-r /var/svn" 改为 svn 版本库存放的目录,:wq 保存退出

然后在提示符下输入

systemctl enable svnserve.service  

重启服务器,输入

ps -aux | grep 'svn'  

看 svn 服务启动了没有。。。

****************************************************************************************************************

常见 SVN 客户端命令

###
### 基础操作
###
svn checkout(co) - 检出
    # 检出一个版本库(/目录) (并且带有用户名和密码)
    ex : svn co svn://127.0.0.1(/dir) (--username jiangbo --password 123456)
svn add - 添加到版本控制
    # 添加一个index.php二进制文件到版本控制(并未提交到版本库)
    ex : svn add index.php
    # 添加一个pic.png树文件到版本控制(并未提交到版本库)
    ex : svn add pic.png
    # (递归)添加一个css目录及下面所有文件夹和文件到版本控制(并未提交到版本库)
    ex : svn add css
    # (未递归)仅仅添加js目录(未包含下面任何文件夹和文件)到版本控制(并未提交到版本库)
    ex : svn add js --non-recursive
svn commit(ci) - 提交修改到服务端(创建一个新版本号)
    # 提交一个index.php二进制文件到版本库并添加注释
    ex : svn ci -m "this is index.php" index.php
    # 提交一个index.php二进制文件到版本库但不想添加注释,由于 svn ci 命令必须包含注释,只能将注释留 "" 来到达这个需求了
    ex : svn ci -m "" index.php
    # 提交一个pic.png树文件到版本库并添加注释
    ex : svn ci -m "this is pic.png" pic.png
    # (递归)提交一个css目录及下面所有文件夹和文件到版本版本库并添加注释
    ex : svn ci -m "this is css dir" css
    # 提交当前目录版本控制下的所有文件目录及文件
    ex : svn ci -m "" *
svn update(up) - 更新工作副本
    # 更新当前目录的工作副本
    ex : svn up
    # 将index.php二进制文件更新至版本1
    ex : svn up -r 1 index.php
    # 强制更新当前目录到最新版本
    ex : svn up *
svn delete(del,remove,rm) - 从版本库中删除文件和目录
    # 删除index.php二进制文件到版本控制(并未提交到版本库)
    ex : svn rm index.php
    # 删除pic.png树文件到版本控制(并未提交到版本库)
    ex : svn rm pic.png
    # (递归)删除css目录及下面所有文件夹和文件到版本控制(并未提交到版本库)
    ex : svn rm css
svn diff(di) - 比较当前工作副本和最新版本库之间的差异
    # 比较当前工作副本中的index.php和最新版本库中的index.php之间的差异
    ex : svn di index.php
    # 比较当前工作副本中的index.php和版本库版本2中的index.php之间的差异
    ex : svn di -r 2 index.php
    # 比较版本库版本2中的index.php和版本库版本3中的index.php之间的差异
    ex : svn di -r 2:3 index.php
    # 比较当前工作副本和最新版本库所有文件目录和文件之间的差异
    ex : svn di
svn mkdir - 创建一个文件夹到版本控制中
    # 创建 doc 文件夹到版本控制中
    ex : svn mkdir doc
        ->1- mkdir doc
        ->2- svn add doc
svn cat - 在不检出的情况查看文件内容
    # 查看 svn://ip/index.php 文件内容
    ex : svn cat svn://ip/index.php
svn revert - 工作副本进行还原操作
    # 工作副本中的index.php还原至最新版本库中的index.php
    ex : svn revert index.php
    # 将工作副本所有文件目录和文件还原至最新版本库
    ex : svn revert *
    # (递归)将工作副本所有文件目录下文件和文件还原至最新版本库
    ex : svn revert --recursive *
###
### 冲突及冲突解决办法
###
svn resolve - 弹出冲突解决选项
    # 现有index.php冲突了,必须解决它,弹出选项
    ex : svn resolve index.php
        -> Select: (p) postpone(推迟), (df)show diff(显示差异), (e) edit file(编辑文件), (m) merge(合并), (mc) my side of conflict(采用我的文件), (tc) their sidee of conflict(采用他的文件), (s) show all options(显示所有选项):  mc(并且告知svn服务器冲突已处理)
        -> Resolved conflicted state of 'index.php'(冲突已解决,采用我的文件)
        # 需要提交解决了的冲突文件至版本库中
        svn ci -m "" index.php 
        ->Sending index.php
        ->Transmitting file data .
        ->Committed vevision 6(old+1).
        # 冲突已经完美解决了,但是我们需要避免冲突,再编写程序或者其他什么操作之前更新至最新版本
###
### 加锁和解锁机制(不推荐使用)
###
svn lock - 加锁
    # 将当前工作副本中的index.php加锁至版本控制中
    ex : svn lock index.php
        # 此时别人不能操作文件
        # 如果修改index.php提交至版本库中,则会自动解锁。但是如果一直未改变该文件也未去解锁的话就会造成项目组其他人一直不能操作该文件,比如该人员辞职了,那么后果你可以想想,所以建议避免使用
svn unlock - 解锁
    # 将当前工作副本中的index.php解锁至版本控制中
    ex : svn unlock index.php
        # 提交解锁文件
        # svn ci -m "" --no-unlock index.php

 多项目管理配置方案

常见 SVN 客多项目

# 步骤1: 创建svn多项目管理配置文件目录
mkdir /var/svn
# 步骤2: 创建svn配置文件目录
mkdir /var/svn/svnconfig
# 步骤3: 创建第一个项目
svnadmin create /var/svn/pigeonfan
# 步骤3: 创建第二个项目
svnadmin create /var/svn/mall
# 步骤3: 创建第三个项目
svnadmin create /var/svn/hardware
# 步骤4: 拷贝任意一个项目conf文件目录下所有文件至svn配置文件目录
cp /var/svn/pigeonfan/conf/* /var/svn/svnconfig/
# 步骤5: 删除svn配置文件目录的svnserve.conf
rm -f svnserve.conf
# 步骤6: 修改/var/svn/svnconfig/passwd文件
# 步骤7: 修改/var/svn/svnconfig/authz文件
# [groups]
# admin_group=admin
# [pigeonfan:/]
# @admin_group=rw
# *=
# [mall:/]
# @admin_group=rw
# *=
# [hardware:/]
# @admin_group=rw
# *=
vim /var/svn/svnconfig/authz
# 步骤8: 修改pigeonfan、mall、hardware下面的svnserve.conf,统一修改成
# anon-access = none
# auth-access = write
# password-db = /var/svn/svnconfig/passwd
# authz-db = /var/svn/svnconfig/authz
# 建议修改一个进行覆盖替换即可
# cp -f /var/svn/pigeonfan/svnserve.conf /var/svn/mall/svnserve.conf
# cp -f /var/svn/pigeonfan/svnserve.conf /var/svn/hardware/svnserve.conf
vim /var/svn/pigeonfan/svnserve.conf
vim /var/svn/mall/svnserve.conf
vim /var/svn/hardware/svnserve.conf
# 步骤9: 重启svn服务器
svnserve -d -r /var/svn

 如果继续添加版本库或者后续工作需要添加版本库,请按下面步骤操作就OK了:

### 如果后续有需要继续添加更多版本库的话
# 步骤1: 创建一个新的版本库
svnadmin create /var/svn/newrule
# 步骤2: 复制覆盖掉新的版本库中的svnserve.conf文件
cp /var/svn/pigeonfan/conf/svnserve.conf /var/svn/newrule/conf/svnserve.conf
# 步骤3: 将/var/svn/svnconfig/authz文件添加权限
# [newrule:/]
# @admin_group = rw
# * =

ok!后续会将基础操作写入博客,敬请期待!!

****************************************************************************************************************

写到最后:

### 可能会用到一些常用指令
# 查看服务
netstat -tnlp
# 查看svn服务启动没有
ps -aux|grep svn
# 如何清除SVN保存的用户和密码
rm ~/.subversion/auth/svn.simple/*
# kill掉svn进程(-9强制的意思)
kill -9 1131
# 重启svn服务(-d作为服务后台进行运行)(-r将后面的目录作为svn运行的根目录)
kill -9 1131 # 先强制kill调svn进程
svnserve -d -r /var/svn # 然后启动svn服务进程

转载至https://www.cnblogs.com/jiangxiaobo/p/8228216.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值