版本控制SVN在CentOS系统的部署

SVN简介,作用

SVN是颠覆的简称,是一个开放源代码的版本控制系统,它采用了分支管理系统,说得简单一点SVN就是用于多个人共同开发同一个项目,共用资源的目的,它主要在于解决以下几个问题

  • 多人参与同一项目,每人都有一份代码,上线难统一
  • 如果代码编辑中出错,代码量较大一时找不到问题,便于快速回退到上一正确版本
  • 项目负责人可以方便查看到项目进度,不用找到每个节点责任人

下面开始部署流程

背景:

目前有shop及blog两个项目,alice负责html页面,tom负责php后端,此次实验用shop项目演示基本操作,blog项目中添加了权限控制,且本文不涉及防火墙相关相识,故所有主机均关闭各防火墙

环境

3台centos7主机

关闭防火墙

SVN Server IP : 10.8.8.102

alice:HTML Client IP : 10.8.8.150

tom:PHP  Client IP : 10.8.8.65


shop项目

Server端

[root@server ~]# yum -y install subversion             //安装svn程序
[root@server ~]# mkdir /svn/{shop,blog} -p
[root@server ~]# svnadmin create /svn/shop             //创建shop svn库
[root@server ~]# ls /svn/shop                          //创建库之后目标目录下会新增以下文件
conf  db  format  hooks  locks  README.txt
#conf:配置
#db: 存放数据
[root@server ~]# svnserve -d -r /svn                   //启动库,并指定用户访问根目录
[root@server ~]# netstat -antpu | grep svn
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      1251/svnserve

Client端(软件同server)

[root@tom-client ~]# svn checkout svn://10.8.8.102/shop              //连接svn库
Checked out revision 0.
[root@tom-client ~]# ls                                              //连接成功之后当前目录下会自动创建目录
anaconda-ks.cfg  shop
[root@tom-client ~]# cd shop                                 
[root@tom-client shop]# echo "this is first commit" >index.php       //在本地创建一个文件(模拟php代码文件)
[root@tom-client shop]# svn add index.php                            //将此文件加入上传队列
[root@tom-client shop]# svn commit -m "first commit" index.php       //提交至服务器,发现报错,原因为没有权限 -m 对此次更新的备注,必填
svn: E170001: Commit failed (details follow):
svn: E170001: Authorization failed
[root@server ~]# vim /svn/shop/conf/svnserve.conf                    //在server端此文件加入匿名用户的权限
anon-access = write
[root@tom-client shop]# svn commit -m "first commit" index.php       //再次尝试提交,成功
Adding         index.php
Transmitting file data .
Committed revision 1.
[root@server shop]# ll /svn/shop/db/revs/0                           //server端查看库列表
total 8
-r--r--r-- 1 root root 115 Jan 20 10:32 0
-r--r--r-- 1 root root 441 Jan 20 11:28 1
[root@tom-client shop]# echo "The second submission" >index.php      //客户端对此文件进行修改
[root@tom-client shop]# svn commit -m "the second commit" index.php  //提交
Adding         index_update.php
Transmitting file data .
Committed revision 2.
[root@server shop]# ll /svn/shop/db/revs/0          //提交后库文件列表增加,旧文件不会被覆盖,便于后期版本回退
total 12
-r--r--r-- 1 root root 115 Jan 20 10:32 0
-r--r--r-- 1 root root 441 Jan 20 11:28 1
-r--r--r-- 1 root root 497 Jan 20 11:41 2


权限控制

背景:

Blog项目

alice只对blog项目下的html目录有读写权限

tom只对blog项目下的php目录有读写权限,对html目录有读权限

Server端

[root@server conf]# svnadmin create /svn/blog                       //创建blog库
[root@server ~]# vim /svn/blog/conf/svnserve.conf                   //修改svnserve.conf配置文件,开启认证功能
password-db = passwd
authz-db = authz
[root@server ~]# vim /svn/blog/conf/passwd                         //此文件存放用户名及密码
[users]
alice = 654321
tom = 123456
admin = 000000

authz文件用于限定用户对指定目录的权限,上层目录的权限会递归到下层目录,除非在下层目录另有指定,比如以下配置除admin外,tom及alice对根目录都有读的权限,结合要求,alice对php目录没有读的权限,所以在[/php]下将alice上层目录继承下来的权限重新指定

[root@server ~]# vim /svn/blog/conf/authz                           
[/]                                                                  //此处的’/’为blog根目录
admin = rw
tom = r
alice = r
[/html]
alice = rw
[/php]
tom = rw
alice =
[root@server blog]# mkdir /blog_admin                              //在server端另建一目录,用于连接svn server,用admin账户创建php及html目录(tom,alice账户无根下权限)
[root@server blog]# cd /blog_admin
[root@server blog_admin]# svn checkout svn://localhost/blog         //首次会提示输入账号及密码,输入passwd配置文件中admin的密码,其它账户无权限,并且会提示是否保存,保存之后就不会再提示输入密码
[root@server blog_admin]# cd blog
[root@server blog]# svn mkdir php                                  //创建php目录
A         php
[root@server blog]# svn commit -m "php directory" php             // 提交
Adding         php
[root@server blog]# svn mkdir html                                 //创建html目录
A         html
[root@server blog]# svn commit -m "html directory" html            //提交
Adding         html
[root@server blog]# ls
html  php


验证

对主目录的权限                                         //tom对html 及 php 目录都有读的权限
tom:
[root@tom-client ~]# mkdir /blog
[root@tom-client blog]# svn checkout svn://10.8.8.102/blog
[root@tom-client blog]# ls blog
html  php
alice:                                               //因去除了alice对于php目录的权限,所以不显示
[root@alice-client ~]# mkdir /blog
[root@alice-client blog]# svn checkout svn://10.8.8.102/blog
[root@alice-client blog]# ls blog
html
对各自工作目录的权限
alice:                                               //alice对html有读写权限,可以正常提交
[root@alice-client html]# vim index.html                    
htmltest
[root@alice-client html]# svn add index.html 
A         index.html
[root@alice-client html]# svn commit -m "test" index.html 
Adding         index.html
tom:                                                 //tom对php有读写权限,可以正常提交
[root@tom-client php]# vim index.php
phptest
[root@tom-client php]# svn add index.php 
A         index.php
[root@tom-client php]# svn commit -m "phptest" index.php 
Adding         index.php
Transmitting file data .
Committed revision 5.

对其它目录的权限 
tom:                                                  //tom对html有读权限,可以正常读取
[root@tom-client blog]# svn update
Updating '.':
A    html/index.html
Updated to revision 4.
[root@tom-client blog]# cat html/index.html 
Htmltest
tom                                                  //tom对html无写权限,无法正常提交
[root@tom-client blog]# cd html
[root@tom-client html]# vim test.php
[root@tom-client html]# svn add test.php 
A         test.php
[root@tom-client html]# svn commit -m "test" test.php
Adding         test.php
Transmitting file data .svn: E220004: Commit failed (details follow):
svn: E220004: Access denied

END





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值