Linux下搭建SVN服务器及自动更新项目文件到web发布目录(www)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下搭建SVN服务器及自动更新项目文件到web发布目录(www)相关的知识,希望对你有一定的参考价值。
一、linux服务器端配置
[[email protected] ~]# rpm -qa | grep sub
subversion-libs-1.7.14-10.el7.x86_64
subversion-1.7.14-10.el7.x86_64
[[email protected] ~]# ps -ef | grep svn
root 21019 20613 0 21:57 pts/0 00:00:00 grep --color=auto svn
[[email protected] ~]# mkdir -p /opt/svn/repo
[[email protected] ~]# svnserve --version
svnserve, version 1.7.14 (r1542130)
compiled Nov 20 2015, 19:25:09
Copyright (C) 2013 The Apache Software Foundation.
This software consists of contributions made by many people; see the NOTICE
file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository back-end (FS) modules are available:
* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.
Cyrus SASL authentication is available.
[[email protected] ~]# svnadmin create /opt/svn/repo/
[[email protected] ~]# cd /opt/svn/repo/
[[email protected] repo]# pwd
/opt/svn/repo
[[email protected] repo]# ls
conf db format hooks locks README.txt
[[email protected] repo]# cd conf/
[[email protected] conf]# pwd
/opt/svn/repo/conf
[[email protected] conf]# ls
authz passwd svnserve.conf
[[email protected] conf]# vim authz
注:authz最后加上以下两行(这两行解决了 SVN客户端解决authorization failed问题)
[/]
* = rw
[[email protected] conf]# vim passwd
注:passwd修改为:
[users]
admin = 123456 //这里的username和password自己设置
[[email protected] conf]# vim svnserve.conf
注:配置如下:
anon-access = none #匿名访问的权限,可以是read,write,none,默认为read
auth-access = write #使授权用户有写权限
password-db = passwd #密码数据库的路径
authz-db = authz #访问控制文件
realm = /opt/svn/repo #认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存 #的关键字
[[email protected] conf]# cd
[[email protected] ~]# svnserve -d -r /opt/svn/
-d 表示后台运行
-r 指定根目录是 /opt/svn/
[[email protected] ~]# ps -ef | grep svn
root 21122 1 0 22:21 ? 00:00:00 svnserve -d -r /opt/svn/
root 21124 20613 0 22:21 pts/0 00:00:00 grep --color=auto svn
[[email protected] ~]# netstat -antlp | grep svn
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 21122/svnserve
二、linux客户端使用介绍
1、将文件checkout到本地目录
[[email protected] home]# cd
[[email protected] ~]# cd /home/
[[email protected] home]# ls
[[email protected] home]# svn checkout svn://127.0.0.1/repo #简写:svn co
Checked out revision 0.
[[email protected] home]# ls
repo
2、往版本库中添加新的文件
[[email protected] home]# cd repo/
[[email protected] repo]# ls
[[email protected] repo]# touch test.txt
[[email protected] repo]# ls
test.txt
[[email protected] repo]# svn add test.txt
A test.txt
3、将改动的文件提交到版本库
svn commit -m “LogMessage“ [-N] [--no-unlock] PATH(如果选择了保持锁,就使用–no-unlock开关)
[[email protected] repo]# svn commit -m "add testing" test.txt #简写:svn ci
Adding test.txt
Transmitting file data .
Committed revision 1.
[[email protected] repo]# ls
test.txt
[[email protected] repo]# vim test.txt
[[email protected] repo]# cat test.txt
testing
testing
testing
testing
testing
testing
testing
testing
[[email protected] repo]# svn commit -m "add testing something" test.txt
Sending test.txt
Transmitting file data .
Committed revision 2.
4、删除文件
svn delete path -m “delete test fle“
例如:第一步:svn delete svn://192.168.10.151/pro/domain/test.php -m “delete test file”
第二步:svn commit
第三步:svn update
或者直接svn delete test.php 然后再svn ci -m ‘delete test file‘,推荐使用这种
简写:svn (del, remove, rm)
5、更新到某个版本
svn update -r m path
例如:
svn update如果后面没有目录,默认将当前目录以及子目录下的所有文件都更新到最新版本。
svn update -r 200 test.php(将版本库中的文件test.php还原到版本200)
svn update test.php(更新,于版本库同步。如果在提交的时候提示过期的话,是因为冲突,需要先update,修改文件,然后清除svn resolved,最后再提交commit)
简写:svn up
6、恢复本地修改
svn revert: 恢复原始未改变的工作副本文件 (恢复大部份的本地修改)。revert:
用法: revert PATH…
注意: 本子命令不会存取网络,并且会解除冲突的状况。但是它不会恢复
被删除的目录
7、解决冲突
svn resolved: 移除工作副本的目录或文件的“冲突”状态。
用法: resolved PATH…
注意: 本子命令不会依语法来解决冲突或是移除冲突标记;它只是移除冲突的
相关文件,然后让 PATH 可以再次提交。
8、加锁/解锁
svn lock -m “LockMessage“ [--force] PATH
例如:svn lock -m “lock test file“ test.php
svn unlock PATH
9、查看文件或者目录状态
1)svn status path(目录下的文件和子目录的状态,正常状态不显示)
【?:不在svn的控制中;M:内容被修改;C:发生冲突;A:预定加入到版本库;K:被锁定】
2)svn status -v path(显示文件和子目录状态)
第一列保持相同,第二列显示工作版本号,第三和第四列显示最后一次修改的版本号和修改人。
注:svn status、svn diff和 svn revert这三条命令在没有网络的情况下也可以执行的,原因是svn在本地的.svn中保留了本地版本的原始拷贝。
简写:svn st
10、查看日志
svn log path
例如:svn log test.php 显示这个文件的所有修改记录,及其版本号的变化
11、查看文件详细信息
svn info path
例如:svn info test.php
12、比较差异
svn diff path(将修改的文件与基础版本比较)
例如:svn diff test.php
svn diff -r m:n path(对版本m和版本n比较差异)
例如:svn diff -r 200:201 test.php
简写:svn di
13、将两个版本之间的差异合并到当前文件
svn merge -r m:n path
例如:svn merge -r 200:205 test.php(将版本200与205之间的差异合并到当前文件,但是一般都会产生冲突,需要处理一下)
14、SVN 帮助
svn help
svn help ci
三、自动更新项目文件到web发布目录(www)
1、检出(checkout)到本地目录是/home/repo
[[email protected] repo]# ls
index.php test.txt
[[email protected] repo]# cd ..
[[email protected] home]# ls
repo
[[email protected] home]# mv repo/ www/ #将检出到本地的版本目录更名为web发布目录
[[email protected] home]# ls
www
[[email protected] home]# cd www/
[[email protected] www]# ls
index.php test.txt
2、通过脚本文件实现自动更新
使用SVN中post-commit实现自动实时从svn中检出文件并同步到Web站点根目录
[[email protected] ~]# cd /opt/svn/repo/
[[email protected] repo]# ls
conf db format hooks locks README.txt
[[email protected] repo]# cd hooks/
[[email protected] hooks]# pwd
/opt/svn/repo/hooks
[[email protected] hooks]# ls
post-commit.tmpl post-unlock.tmpl pre-revprop-change.tmpl
post-lock.tmpl pre-commit.tmpl pre-unlock.tmpl
post-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl
[[email protected] hooks]# cp post-commit.tmpl post-commit
[[email protected] hooks]# ls
post-commit post-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl
post-commit.tmpl post-unlock.tmpl pre-revprop-change.tmpl
post-lock.tmpl pre-commit.tmpl pre-unlock.tmpl
[[email protected] hooks]# cp post-commit.tmpl post-commit
[[email protected] hooks]# vim post-commit
[[email protected] hooks]# > post-commit
[[email protected] hooks]# vim post-commit
******************************************************************************************
输入:
#!/bin/sh
export LC_CTYPE="zh_CN.UTF-8"
SVN=/usr/bin/svn
WEB_PATH=/home/www #要强制更新的目录
SVN_USER=admin
SVN_PASS=123456
$SVN update $WEB_PATH --username $SVN_USER --password $SVN_PASS #执行更新
******************************************************************************************
[[email protected] hooks]# ll post-commit
-rw-r--r--. 1 root root 220 Apr 13 00:21 post-commit
[[email protected] hooks]# chmod a+x post-commit #给予执行权限
[[email protected] hooks]# ll post-commit
-rwxr-xr-x. 1 root root 220 Apr 13 00:21 post-commit
[[email protected] hooks]# cat post-commit
#!/bin/sh
export LC_CTYPE="zh_CN.UTF-8"
SVN=/usr/bin/svn
WEB_PATH=/home/www #要强制更新的目录
SVN_USER=admin
SVN_PASS=123456
$SVN update $WEB_PATH --username $SVN_USER --password $SVN_PASS #执行更新
[[email protected] hooks]# pwd
/opt/svn/repo/hooks
注:文件/opt/svn/repo/hooks(俗称钩子)/post-commit属于自动执行。
本文出自 “MQ_douer” 博客,请务必保留此出处http://douer.blog.51cto.com/6107588/1915293
以上是关于Linux下搭建SVN服务器及自动更新项目文件到web发布目录(www)的主要内容,如果未能解决你的问题,请参考以下文章
Linux下搭建SVN服务器及自动更新项目文件到web发布目录(www)