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