centos 搭建svn(多仓库共用账户配置)(已使用)

1、下载安装 subversion

[root@CentOS var]# yum -y install subversion
测试安装是否成功

[root@CentOS var]# svnserve --version
2、创建 svn 版本库,初始化相关配置文件

[root@CentOS var]# mkdir -p /svn/demo
[root@CentOS var]# mkdir -p /svn/demo2
[root@CentOS var]# svnadmin create /svn/demo    # 创建源仓库
[root@CentOS var]# svnadmin create /svn/demo2     # 创建源仓库

般没使用可选择版本控制开发在demo2仓库下新建3个文件夹(也可以自己在本地checkout 目录后创建trunk branches tags 文件夹上传提交即可 都是一样的  )

[root@CentOS var]# svn mkdir file:///svn/demo/trunk -m "create"  # 创建主干
Committed revision 1.
[root@CentOS var]# svn mkdir file:///svn/demo/branches -m "create" # 创建分支
Committed revision 2.
[root@CentOS var]# svn mkdir file:///svn/demo/tags -m "create" # 创建标签 

如果删除版本库:   rm -rf  svnadmin create /svn/demo

3.进入demo目录下的conf文件夹。把authz与passwd文件复制到svn根目录(之后的配置都是配置公共的authz passwd ,仓库目录下的 authz passwd 不需要动, 只需要修改仓库下的svnserve.conf配置)

cd /svn/demo/conf

cp  authz /svn
 cp passwd /svn


修改deomo和demo2项目 conf文件夹下的svnserve.conf文件 除了realm指向不一样 其他配置都一样,

配置项名称一定不能有空格要靠近最左边要不配置文件不生效有问题 如下图  

### 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.apache.org/ 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 = none
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 = /data/svn/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 = /data/svn/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 = /data/svn/shop
### 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

编辑示例:

[general]
#禁止匿名用户访问
anon-access = no
#授权用户拥有读写权限
auth-access = write
# 使用公共的passwd
password-db = /svn/passwd
# 使用公共的authz
authz-db = /svn/authz
#指定版本库的认证域, demo仓库路径/svn/demo/ ,realm = /svn/demo/ , demo2仓库路径/svn/demo2 ,realm = /svn/demo2/
realm = /svn/demo/

配置项名称一定不能有空格要靠近最左边要不配置文件不生效有问题 上图

编辑svn用户配置文件

 vim /svn/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
admin = liuxinsgtc 
user = user!@123


编辑示例:

[users]
# harry = harryssecret
# sally = sallyssecret
# 用户名,密码
admin = admin 
user= user!@#123456
lisi= 123456
zhangsan = 123456
wangwu=123456
ligang=123456
 
编辑svn权限控制配置文件

vim /svn//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


[groups]
#用户组名=用户名
admin=admin
users=user

#表示根目录(/svn/),对全部版本库设置权限
[/] 
#表示admin组对根目录有读写权限,r为读,w为写
@admin=rw
 
#表示demo仓库根目录(/svn/demo/)
[shop:/] 
#表示users_demo组对根目录有读写权限,r为读,w为写
@users=rw

编辑示例:
[groups]
#用户组名=用户名
admin=admin
users=user
users_demo=lisi,zhangsan
users_demo2=wangwu,ligang
 
#表示根目录(/svn/),对全部版本库设置权限
[/] 
#表示admin组对根目录有读写权限,r为读,w为写
@admin=rw
 
#表示demo仓库根目录(/svn/demo/)
[demo:/] 
#表示users组对根目录有读写权限,r为读,w为写
@users=rw
 
#表示demo仓库下的test目录
[demo:/test] 
#表示quest组对根目录有读写权限,r为读
@users=r
 
#表示demo2仓库根目录(/svn/demo2/)
[demo2:/] 
#表示users_demo2组对根目录有读写权限,r为读,w为写
@users_demo2=rw
 
 启动svn

svnserve -d -r /svn
 

查看svn状态 

ps -ef | grep svn  或者   netstat -ln | grep 3690 //查看端口状态

重启 svn

ps 杀掉进程 然后再重新启动

svn://服务器ip/demo

post-commit 搭建自动同步版本库到服务器项目目录

1. cd /svn/demo/hooks

mv post-commit.tmpl post-commit

2.重点设置权限  chmod +x post-commit //赋予ex权限

vi post-commit

#!/bin/sh

REPOS="$1"
REV="$2"
export LANG=zh_CN.UTF-8
echo "Code Deployed at `date "+%Y-%m-%d %H:%M"`" >> /data/svn/deploy.log
/usr/bin/svn update /data/web/demo --username admin --password 123456



#说明 /data/web/demo 更新的项目目录

3.cd /data/web

执行 svn co svn://127.0.0.1/demo  (demo不存在 svn会自动创建)

下面配置操作未测试使用

Centos7搭建SVN服务(多个仓库)_centos svn服务器创建多仓库_天~嘿的博客-CSDN博客
4.在 /etc/init.d 目录下,创建脚本 svnd

[root@CentOS init.d]# touch svnd
[root@CentOS init.d]# chmod u+x svnd
编辑后的 svnd 脚本如下所示

#!/bin/sh
# chkconfig: 2345 10 90
# description: svn server
SVN_HOME=/opt/svnrepos
if [ ! -f "/usr/bin/svnserve" ]
then
echo "svnserver startup: cannot start"
exit
fi
case "$1" in
start)
echo "Starting svnserve…"
/usr/bin/svnserve -d --listen-port 3690 -r $SVN_HOME
echo "Finished!"
;;
stop)
echo "Stoping svnserve…"
killall svnserve
echo "Finished!"
;;
restart)
$0 stop
$0 start
 
;;
*)
echo "Usage: svn { start | stop | restart } "
exit 1
esac
 

5.启动 svn 服务

[root@CentOS init.d]# service svnd start
Starting svnserve…
Finished!
[root@CentOS init.d]# ps -ef | grep 'svnserve'
root       4225      1  0 23:33 ?        00:00:00 /usr/bin/svnserve -d --listen-port 3690 -r /opt/svnrepos
root       4230   3505  0 23:33 pts/0    00:00:00 grep --color=auto svnserve
[root@CentOS init.d]# 
安装好 svn 服务后,默认是没有随系统启动自动启动的, CentOS 7 的 /etc/rc.d/rc.local 是没有执行权限的, 系统建议创建 systemd service 启动服务

查看svnserve.service位置:systemctl enable svnserve.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
重启服务器:shutdow -r now

输入

ps -aux | grep 'svn'


6.开放 3690 端口 (svn服务默认端口)

[root@CentOS init.d]# firewall-cmd --zone=public --add-port=3690/tcp --permanent
success
[root@CentOS init.d]# firewall-cmd --reload
success
[root@CentOS init.d]# 
7.在 windows 下使用TortoiseSVN进行测试

如code仓库svn地址   

svn://192.168.2.2/code

如custom仓库svn地址

svn://192.168.2.2/custom

8.将 svn 添加为系统服务,并设置为开机启动

[root@CentOS init.d]# chkconfig --add svnd
[root@CentOS init.d]# chkconfig svnd on
9.配置httpd访问方式

 安装httpd服务:

$ sudo yum install httpd
检查httpd是否安装成功:

 httpd -version
Server version: Apache/2.4.6 (CentOS)
Server built:   Jul 18 2016 15:30:14
安装mod_dav_svn,mod_dav_svn是apache服务器访问svn的一个模块。通过yum安装:

sudo yum install mod_dav_svn
安装成功后,会有mod_dav_svn.so和mod_authz_svn.so两个文件。

$ sudo find / -name mod_dav_svn.so
/usr/lib64/httpd/modules/mod_dav_svn.so
 
$ sudo find / -name mod_authz_svn.so
/usr/lib64/httpd/modules/mod_authz_svn.so
修改svn仓库的用户组为apache

$ sudo chown -R apache:apache /opt/svnrepos
创建用户文件passwd_httpd(httpd方式密码为md5加密,需重新配置用户名密码),示例如下:

$ sudo touch /opt/svnrepos/passwd_http  #创建用户文件
$ sudo htpasswd /opt/svnrepos/passwd_httpd admin  #创建用户admin
$ sudo htpasswd /opt/svnrepos/passwd_http guest  #创建用户gues
 

配置httpd

$ sudo touch /etc/httpd/conf.d/subversion.conf
 
$ cat /etc/httpd/conf.d/subversion.conf 
<Location /svn>  
    DAV svn
    #SVNPath定义到具体仓库位置
    #SVNPath /opt/svnrepos/code
    
    #SVNParentPath 定义多个仓库
    SVNParentPath /opt/svnrepos            
    AuthType Basic  
    AuthName "Subversion repos"
    #用户名密码(密码为md5加密)
    #AuthUserFile /opt/svnrepos/passwd_httpd
    AuthzSVNAccessFile /opt/svnrepos/authz
    Require valid-user  
</Location>
启动httpd服务

$ service httpd start
客户端使用http://192.168.2.2/svn/code就可以访问刚才建立的svn仓库了。 如果返回403错误,可能是防火墙问题。增加防火墙规则:

 
//永久的添加该端口
$ firewall-cmd --permanent --zone=public --add-port=80/tcp 
//加载配置,使得修改有效 
$ firewall-cmd --reload 
//查看开启的端口
$ firewall-cmd --permanent --zone=public --list-ports  
 
 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 要在CentOS上离线搭建SVN服务器,需要按照以下步骤进行操作: 1. 首先,在CentOS服务器上安装必要的软件包和依赖项。由于是离线环境,需要先将相关的软件包下载到一个可访问的计算机上,然后通过U盘或其他外部介质将它们传输到CentOS服务器上。在CentOS服务器上使用以下命令安装软件包: ``` rpm -ivh svn-server-rpm包 ``` 2. 创建一个用于存储SVN仓库的目录,并为其分配合适的权限: ``` mkdir /svn-repo chown -R apache.apache /svn-repo ``` 3. 初始化SVN仓库: ``` svnadmin create /svn-repo/myrepo ``` 4. 配置SVN服务。在`/etc/httpd/conf.d/`目录下创建一个新的配置文件,例如`svn.conf`,并添加以下内容: ``` # SVN 配置 <Location /svn> DAV svn SVNPath /svn-repo/myrepo </Location> ``` 5. 重启Apache服务以应用配置更改: ``` systemctl restart httpd ``` 6. 确保防火墙允许通过HTTP访问SVN服务。可以使用以下命令开放端口80: ``` firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload ``` 7. 完成上述步骤后,即可通过浏览器或相应的SVN客户端从其他计算机访问SVN仓库了。 请注意,这只是一个简单的离线搭建SVN服务器的示例步骤。实际操作中可能涉及到更多的细节和配置,具体的步骤可能会有所不同。建议根据自己的实际情况和需求进行相应的调整。 ### 回答2: 要离线搭建CentOS下的SVN服务器,需要以下步骤: 1. 下载SVN软件包:在网络连接正常的环境中,下载最新版本的Subversion软件包,并将其保存到本地或移动存储设备中。 2. 安装CentOS系统:在目标服务器上安装CentOS操作系统,确保操作系统的版本和架构与下载的软件包相匹配。 3. 安装Subversion:将下载的SVN软件包复制到目标服务器,解压并安装。执行相关的安装命令,如使用yum命令安装:sudo yum install subversion。 4. 创建SVN仓库使用命令行工具,创建一个SVN仓库。在指定的目录中执行命令:svnadmin create /path/to/repository。 5. 配置访问权限:为SVN仓库设置访问权限,确保只有授权的用户可以访问。创建一个authz文件,用于配置用户和组的权限。编辑文件并添加相应的权限规则。 6. 配置SVN服务器:编辑svnserve.conf文件,配置SVN服务器的各项参数。例如,设置SVN服务器监听的端口、启用身份验证等。 7. 启动SVN服务器:执行启动命令,启动SVN服务器。例如,通过命令svnserve -d -r /path/to/repository启动并使其在后台运行。 8. 测试SVN服务器:使用SVN客户端工具,例如TortoiseSVN等,在另一台计算机上测试连接SVN服务器。尝试进行检出、更新和提交等操作,验证服务器是否正常工作。 通过以上步骤,就可以在CentOS服务器上离线搭建一个SVN版本控制系统。 ### 回答3: 要在CentOS上离线搭建SVN服务器,您需要按照以下步骤进行操作: 1. 安装CentOS:首先,确保您已经在离线环境中安装了CentOS操作系统。您可以使用官方的CentOS ISO镜像进行安装。 2. 安装SVN服务器软件:在离线环境中,您需要将SVN服务器软件的安装包下载到离线机器上。您可以从Subversion官方网站或其他可信的软件下载站点下载最新版本的SVN服务器软件安装包。将安装包复制到离线机器上,并使用命令行工具(如yum)安装。 3. 配置SVN服务器:一旦安装了SVN服务器软件,您需要进行相关配置。在离线环境中,您可以编辑SVN服务器的配置文件,通常是在/etc/httpd/conf.d目录下的svn.conf文件。您可以根据实际需求进行配置,如指定版本库的存储位置、访问控制等。 4. 创建SVN版本库:在SVN服务器上创建版本库以存储项目代码。您可以使用svnadmin命令创建版本库,如在命令行中运行"svnadmin create /path/to/repository"来创建名为repository的版本库。 5. 配置访问权限:为了保护SVN版本库中的代码,您需要为其设置访问权限。在离线环境中,您可以在每个项目的conf目录中的svnserve.conf文件中进行配置。通过编辑该文件,您可以控制用户及其对版本库的访问权限。 6. 启动SVN服务器:在离线环境中,您可以启动SVN服务器以便用户可以访问版本库。在命令行中运行"svnserve -d -r /path/to/repository"命令来启动SVN服务器,并将其绑定到指定的版本库路径。 这些步骤将帮助您在CentOS上离线搭建SVN服务器。需要注意的是,在离线环境中,您需要提前准备好所需的软件包及其依赖关系,并保存在本地供安装使用

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值