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

1、下载安装 subversion

[[email protected] var]# yum -y install subversion
测试安装是否成功

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

[[email protected] var]# mkdir -p /svn/demo
[[email protected] var]# mkdir -p /svn/demo2
[[email protected] var]# svnadmin create /svn/demo
[[email protected] var]# svnadmin create /svn/demo2 

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

进入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指向不一样 其他配置都一样,配置项名称一定不能有空格要靠近最左边要不配置文件不生效有问题 如下图  

 

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

编辑示例:

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

 

编辑svn用户配置文件

 vim /svn/passwd
编辑示例:

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

vim /svn//authz

[groups]
#用户组名=用户名
admin=admin
quest=quest
users_demo=lisi,zhangsan
users_demo2=wangwu,ligang
 
#表示根目录(/svn/),对全部版本库设置权限
[/] 
#表示admin组对根目录有读写权限,r为读,w为写
@admin=rw
 
#表示demo仓库根目录(/svn/demo/)
[demo:/] 
#表示users_demo组对根目录有读写权限,r为读,w为写
@users_demo=rw
 
#表示demo仓库下的test目录
[demo:/test] 
#表示quest组对根目录有读写权限,r为读
@quest=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 杀掉进程 然后再重新启动

 

下面配置操作未测试使用

https://blog.****.net/weixin_42231507/article/details/81149568
4.在 /etc/init.d 目录下,创建脚本 svnd

[[email protected] init.d]# touch svnd
[[email protected] 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 服务

[[email protected] init.d]# service svnd start
Starting svnserve…
Finished!
[[email protected] 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
[[email protected] 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服务默认端口)

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

如code仓库svn地址   

svn://192.168.2.2/code

如custom仓库svn地址

svn://192.168.2.2/custom

 

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

[[email protected] init.d]# chkconfig --add svnd
[[email protected] 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