本文主要介绍如何在CentOS7环境下集成Apache和SVN,完成后可以通过浏览器访问SVN仓库.
1.查看系统环境,关闭防火墙和SELinux.
1 [root@Docker /]# systemctl status firewalld.service 2 ● firewalld.service - firewalld - dynamic firewall daemon 3 Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) 4 Active: inactive (dead) 5 Docs: man:firewalld(1) 6 [root@Docker /]# getenforce 7 Disabled 8 [root@Docker /]# uname -a 9 Linux Docker 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 10 [root@Docker /]# cat /etc/redhat-release 11 CentOS Linux release 7.4.1708 (Core) 12 [root@Docker /]#
2.安装软件包和Apache SVN模块.
1 yum install httpd mod_dav_svn subversion
3. 验证安装结果.
1 [root@Docker /]# httpd -version 2 Server version: Apache/2.4.6 (CentOS) 3 Server built: Apr 20 2018 18:10:38 4 [root@Docker /]# svnserve --version 5 svnserve, version 1.7.14 (r1542130) 6 compiled Apr 11 2018, 02:40:28
4.验证Apache SVN模块是否安装成功,需要检查mod_dav_svn.so和mod_authz_svn.so文件.
1 [root@Docker modules]# pwd 2 /etc/httpd/modules 3 [root@Docker modules]# ll | egrep "mod_dav_svn.so|mod_authz_svn.so" 4 -rwxr-xr-x 1 root root 19504 Apr 11 10:44 mod_authz_svn.so 5 -rwxr-xr-x 1 root root 181344 Apr 11 10:44 mod_dav_svn.so
5.使用svnadmin命令创建SVN仓库repos.
1 [root@Docker /]# mkdir /var/www/svn 2 [root@Docker /]# cd /var/www/svn/ 3 [root@Docker svn]# svnadmin create repos 4 [root@Docker svn]# tree -d repos/ 5 repos/ 6 ├── conf 7 ├── db 8 │ ├── revprops 9 │ │ └── 0 10 │ ├── revs 11 │ │ └── 0 12 │ ├── transactions 13 │ └── txn-protorevs 14 ├── hooks 15 └── locks 16 17 10 directories
6.修改repos目录属主和属组为apache.
1 [root@Docker svn]# chown -R apache:apache repos/ 2 [root@Docker svn]# ll 3 total 4 4 drwxr-xr-x 6 apache apache 4096 May 15 16:57 repos
7.复制/var/www/svn/repos/conf 下的权限管理文件authz到 /var/www/svn下,并创建用户认证文件passwd,并且设置隐藏属性.
1 [root@Docker svn]# cp /var/www/svn/repos/conf/authz /var/www/svn/ 2 [root@Docker svn]# cd /var/www/svn/repos 3 [root@Docker repos]# touch .passwd
8.通过htpasswd命令建立SVN用户svnuser并将用户信息保存在passwd文件中.
1 [root@Docker repos]# htpasswd ./.passwd svnuser 2 New password: 3 Re-type new password: 4 Adding password for user svnuser 5 [root@Docker repos]# cat .passwd 6 svnuser:$apr1$ThE7aO2O$CQo.OIs.8TOqUFaFr7b3H0
9.修改authz文件并设置相应权限:
在[groups]下添加组
[/] 相当于/var/www/svn这个目录,赋予权限给用户组
[repos:/] 是指repos库
[repos:/desgin]是repos下的desgin目录
rw是指可读写权限
1 [root@Docker svn]# vim authz 2 [root@Docker svn]# grep -v "^#" authz 3 4 [groups] 5 admin_group=svnuser,svnuser2 6 project_group=svnuser3,svnuser4 7 project2_group=svnuser5,svnuser6 8 9 [/] 10 @admin_group=rw 11 12 [repos:/] 13 @project_group=rw 14 15 [repos:/desgin] 16 @project_group=rw 17 18 [repos2:/] 19 @project2_group=rw
10.关联Apache与SVN,创建subversion.conf文件.Locaion后的名字可以自定义,不需要与仓库名一致,这里我们定义为/documents,这样后面访问时直接输入http://x.x.x.x/documents即可打开仓库
[root@Docker /]# vim /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 /documents> DAV svn SVNParentPath /var/www/svn SVNListParentPath On AuthType Basic AuthName "Project SVN" AuthUserFile /var/www/svn/repos/.passwd Require valid-user AuthzSVNAccessFile /var/www/svn/authz </Location>
11.启动Apache,在浏览器中输入http://x.x.x.x/documents弹出认证窗口,输入用户认证信息即可看到SVN仓库repos.
1 [root@Docker /]# systemctl start httpd.service