设为首页 收藏本站
查看: 661|回复: 0

[经验分享] 征服 Apache + SVN

[复制链接]

尚未签到

发表于 2016-12-30 06:51:19 | 显示全部楼层 |阅读模式
实在是不知道这个帖子在JE上放到哪个分类里合适,跟SVN有关,那就是项目咯,姑且放到项目管理中吧!
SVN用了很久,不过一直没有机会配置。以前工作的时候都是技术总监、部门经理搞定,自己很少有机会尝试。更别说基于svn方式、http方式,亦或是https方式访问svn了,只有用的份,没有了解的份。最近,配置Apache开窍,索性再深入一步,搭建基于HTTPS平台的Apache+SVN平台。


相关内容:
征服 Apache + SSL
征服 Apache + SVN
征服 Apache + SVN +  LDAP
征服 Apache + Tomcat
征服Nginx
征服 Nginx + Tomcat

选用Ubuntu Server 10.04,Apache 2.2.14,Subversion 1.6.6。
步骤:

  • 安装SVN相关模块
  • 配置SVN版本库
  • 配置APACHE
  • 简单测试

1.安装SVN相关模块
这里主要用到的是Subversion 以及Apache与SVN相关的模块(DAV_SVN)!
执行命令,安装:
sudo apt-get install subversion libapache2-svn
注意观察安装后的结果:
引用
Considering dependency dav for dav_svn:
Enabling module dav.
Enabling module dav_svn.
Run '/etc/init.d/apache2 restart' to activate new configuration!

如果看到这样的提示,那说明DAV_SVN模块已经成功安装,可以重启Apache看看是否正常启动:
sudo /etc/init.d/apache2 restart
或者,使用sudo service apache2 restart
以我本机为例,正常启动了:
引用
zlex@localhost:~$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2                 
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

当然,稍后你可能需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库等。
2.配置SVN版本库
完成上述操作,只是为Apache获知SVN给出了一种途径,最关键的还是要配置SVN相关部分!
首先,我们要创建subversion组并把www-data作为subversion中的一员。因为,apache是通过www-data账户启动的,我们需要让它能够访问subversion组的文件!
sudo addgroup subversion
sudo usermod -G subversion -a www-data
然后,我们要配置版本库:
我们可以在/var/lib目录下构建一个svn目录,作为SVN版本库根目录:

cd /var/lib
sudo mkdir svn
假设我们要创建版本库zlex:
cd svn
sudo svnadmin create zlex
更改版本库所属用户、组:
sudo chown -R root:subversion zlex
赋予组成员对所有新加入文件仓库的文件拥有相应的权限:
sudo chmod -R g+rws zlex

试试svn co file://localhost/var/lib/svn/zlex,这时候应该可以访问了!
3.配置Apache
接下来,我们需要修改/etc/apache2/mods-available/dav_svn.conf文件,配置SVN版本库:
sudo vi /etc/apache2/mods-available/dav_svn.conf
DSC0000.jpg
打开红框中的注释,

# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.
# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
<Location /svn>
# Uncomment this to enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/lib/svn
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods.  A "Basic Auth" section is commented out
# below.  (2) Apache <Limit> and <LimitExcept>, also commented out
# below.  (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository.  (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.)  Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.
# Basic Authentication is repository-wide.  It is not secure unless
# you are using https.  See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
# To enable authorization via mod_authz_svn
AuthzSVNAccessFile /etc/apache2/dav_svn.authz
# The following three lines allow anonymous read, but make
# committers authenticate themselves.  It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>

分述:
<Location /svn></Location>成对儿出现!
DAV svn开启DAV模块支持!
SVNPath /var/lib/svnSVNParentPath /var/lib/svn选其一,不可同时出现!建议使用SVNParentPath,可以在SVN根目录下创建多个SVN版本库!
引用
  AuthType Basic
  AuthName "Subversion Repository"
  AuthUserFile /etc/apache2/dav_svn.passwd
定义了授权类型、并指定了密码文件(/etc/apache2/dav_svn.passwd)。
AuthzSVNAccessFile /etc/apache2/dav_svn.authz授权配置文件,规定了路径访问权限!
引用
#<LimitExcept GET PROPFIND OPTIONS REPORT>
   Require valid-user
#</LimitExcept>
建议只使用Require valid-user,打开<LimitExcept />注释,将允许匿名访问!
现在通过命令设置SVN账户:
sudo htpasswd -c /etc/apache2/dav_svn.passwd <username>
这里用到参数-c,是因为/etc/apache2/dav_svn.passwd文件不存在,如果文件存在,则无需该参数!否则,将覆盖掉原有密码文件!
形如:
引用
sudo htpasswd -c /etc/apache2/dav_svn.passwd snowolf
New password:
Re-type new password:
Updating password for user snowolf

可以追加多个账户!
引用
sudo htpasswd /etc/apache2/dav_svn.passwd zlex
New password:
Re-type new password:
Updating password for user zlex

现在,需要设置路径访问权限文件AuthzSVNAccessFile /etc/apache2/dav_svn.authz
我们先做一个默认的配置,当前这个文件还不存在:
sudo vi /etc/apache2/dav_svn.authz
然后追加:
引用

[zlex:/]
* = r


这样,所有授权用户就都能够看到zlex项目了! DSC0001.gif
然后访问http://localhost/svn/zlex:
DSC0002.jpg
试试检出:
svn co http://localhost/svn/zlex --username snowolf

我们通过组方式管理项目,修改/etc/apache2/dav_svn.authz 文件:
sudo vi /etc/apache2/dav_svn.authz  
我们定义一个超级用户组admin,组中成员为snowolf;开发组developer,组中成员为snowolf,zlex,多个用户用逗号分隔。
引用

[groups]
admin = snowolf
developer = snowolf, zlex


让admin和developer组成员有创建项目版本库的权限,其余用户只有查看权限:
引用

[zlex:/]
*=r
@admin = rw
@developer = rw


给出一个完整配置:
引用

[groups]
admin = snowolf
developer = zlex
[zlex:/]
@admin = rw
@developer = rw
* =


有关Subversion详细配置,参照Subversion官方中文文档!
修改这个配置文件时,不需要重启apache!
4.简单测试
我们之前构建了一个项目仓库——zlex,现在项目有了,我们需要构建相应的版本库管理,及trunk、tags以及branches!
用命令创建:
svn mkdir "http://localhost/svn/zlex/branches" "http://localhost/svn/zlex/tags" "http://localhost/svn/zlex/trunk" -m "create a new project zlex" --username "snowolf"   

DSC0003.jpg

这时,我们用zlex账号提交一个docs目录:
svn mkdir "http://192.168.49.132/svn/zlex/docs" -m "文档目录" --username zlex
系统会提示输入密码:
DSC0004.jpg
192.168.49.132是我本机的IP地址!
我们可以使用命令将项目签出:
svn checkout "http://localhost/svn/zlex/trunk@HEAD" -r HEAD --depth infinity zlex-svn --username zlex

我们随便修改一个文件:
DSC0005.jpg
提交修改:
DSC0006.jpg

如果你参照征服 Apache + SSL完成了HTTPS平台搭建,这时候,也可以使用HTTPS方式访问了:
DSC0007.jpg


相关内容:
征服 Apache + SSL
征服 Apache + SVN
征服 Apache + SVN +  LDAP
征服 Apache + Tomcat
征服Nginx
征服 Nginx + Tomcat

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-321205-1-1.html 上篇帖子: Apache MIna 之旅 下篇帖子: apache mina 2 .
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表