搭建svn服务项目并且同步代码到项目目录
随着项目的增大,需要更多的人参与到同一个项目的开发中。其中SVN就是用于多个人共同开发同一个项目,达到公用资源的目的。
SVN服务器有2中运行方式:一是作为独立服务器,另一种是借助apache运行。两种方式各有利弊,这个用户可以自己去选择。在这里我们只讨论第一种方式:作为独立服务器。
创建SVN仓库
首先我们需要安装SVN应用程序。这里我们选择的操作系统是centos。安装SVN应用程序在linux系统下其实是很简单的。使用如下命令
# yum install svn
接着就会出现安装的过程。安装完成以后,我们来新建SVN仓库reptest。为了便于管理,我们新建一个文件夹,专门用来存放所有的仓库 /repos
# mkdir /repos
# svnadmin create /repos/reptest
创建完成以后,我们进入该仓库,会发现在该目录下存在几个文件和目录
# cd /repos/reptest
# ls
conf db format hooks locks README.txt
这样我们就创建了一个SVN的仓库。
配置用户权限
创建完成仓库以后,如果想作为一个独立的服务器,当然得需要配置用户的权限。这里需要用到的有三个文件svnserve.conf、authz和passwd。
svnserve.conf
使用vim打开svnserve.conf文件 修改以下几项。
anon-access = read //去掉开头的#
auth-access = write //去掉开头的#
password-db = passwd //去掉开头的# 默认为passwd 这个文件可以自定义
authz-db = authz //去掉开头的# 默认为authz 这个文件可以自定义
保存退出
passwd
该文件作用是设定可以访问服务的用户和密码,在该文件内的用户可以访问SVN服务。在该文件中添加如下内容
[users]
svnuser = svnuser123
保存退出以后,我们就设定了一个可以访问该服务的用户svnuser,其密码为svnuser123
authz
该文件是验证用户对相应目录的权限。我们在文件内容的末尾添加如下内容
[/]
svnuser = rw
对于SVN服务的整个根目录,svnuser都有读写的权限。
对于以上三个文件都编辑完成以后,下面就开始使用该服务了。
开启SVN服务
接下来我们开始开启SVN服务,这里服务由两种方式:一种是单仓库,另一种是多仓库的。
单仓库
对于单仓库的服务其实很简单。还记得我们刚开始新建的存放仓库的目录 /repos吗?这里我们在这个目录里面新建了一个svntest仓库,如果是单仓库的形式我们只需要在开启服务的时候将这个仓库名称接在/repos后面——/repos/svntest
# svnserve –d –r /repos/svntest
执行完上面的命令,这样我们就开启SVN服务了。
对于这种单仓库的访问形式可以使用如下的命令
# svn checkout svn://ip –username svnuser –password svnuser123 /目标目录
这样我们检出的就是svntest仓库的内容了。
多仓库
对于多仓库的服务的开启方式其实和但仓库的形式没有太大的区别。主要的区别就在于我们开始新建的存放仓库的目录/repos 了。这样我们在开启服务的时候就不要加上目录名称了。直接使用/repos即可
# svnserve –d –r /repos
开启服务以后访问的形式就变了
# svn checkout svn://ip/svntest –username svnuser –password svnuser123
在访问的时候需要在svn地址后面加上svntest仓库名称。
当然,如果说只是保存我们开发的代码的话,到这里已经完成了。但是有时候我们需要将我们提交的代码同步到web目录下面。那这时我们还需要借助svn的钩子 post-commit来实现我们的需求。
post-commit 同步代码
首先要明确我们的应用项目的目录。这里我们使用/web作为我们web应用项目的目录。
然后我们进入/web目录,并在仓库中检出一份代码。
# cd /web
# svn checkout svn://ip/svntest –username svnuser –password svnuser123
//这里我们假设用的是多仓库的形式
接下来编辑shell脚本post-commit。
# vim /repos/svntest/hooks/post-commit
在打开的post-commit 的编辑界面添加如下脚本
#!/bin/bash
export LANG=zh_CN.UTF-8 #文件编码
REPOS="$1" #仓库路径
REV="$2" # 刚刚提交的代码的版本号
SVN=/usr/bin/svn # svn命令
WEB=/web/svntest # web目录
LOG=/data/home/auto_svn.log #日志文件
$SVN update $WEB --username react --password react123 #最后更新的命令
保存退出。然后修改post-commit的用户权限。使用户对其有执行的权限
# chmod u+x /repos/svntest/hooks/post-commit
最后重启SVN服务
# ps –ef | grep svn //首先检测当前的进程id
root 4888 1 0 Mar25 ? 00:00:00 svnserve -d -r /repos
# kill -9 4888 //4888是进程id,使用kill命令杀死该进程
# svnserve –d –r /repos //重新开启服务
# ps –ef | grep svn
root 17957 1 0 19:38 ? 00:00:00 svnserve -d -r /repos
//服务已被启动成功,其进程id为17957
此时当我们提交新的代码或者修改的代码以后,这些代码都会自动同步到/web/svntest目录中。
但是这样有一个问题,就是在/web/svntest目录中会有检出的.svn目录。这样对web的安全存在隐患。当然这样的问题可以通过nginx或者apache的重写功能来消除隐患。具体实现我们可以自行查阅。
希望上面的简单的搭建svn服务的过程,对大家在实际工作中有所帮助。
相关文章
Git list remote branches
发布时间:2025/04/20 浏览次数:55 分类:OPERATING SYSTEM
-
This article will show you how to list remote repositories from your local branch. A remote repository is a project hosted on a server, such as Github/Gitlab. git remote Allows us to use short names (aliases) to execute commands instead of
Rename Git repository
发布时间:2025/04/20 浏览次数:100 分类:OPERATING SYSTEM
-
In this article, we will discuss renaming Git repositories. We can explain this in different ways. It can rename the displayed name, the repository on GitHub, or the folder of the repository. We will discuss these and go through the steps w
Creating tags in a Git repository
发布时间:2025/04/20 浏览次数:118 分类:OPERATING SYSTEM
-
In this tutorial, we will discuss how to create tags in a Git repository. Creating tags in a Git repository In Git, we may want to mark certain commits or specific points in the history of the project repository. To do this, we can use the
Push Git tags to remote repositories
发布时间:2025/04/20 浏览次数:177 分类:OPERATING SYSTEM
-
If you create a git tag locally, your intention must be to share your changes with your team for easy tracking. Commit is one of the common operations to share changes. But another sharing and tracking idea added to it is Git Tags. This art
Git merge repository
发布时间:2025/04/20 浏览次数:161 分类:OPERATING SYSTEM
-
When working on a project with multiple team members having separate repositories for each team, at some point in time we come across a situation where we want to combine these separate repositories into one master repository to deploy all
Network Interfaces in Linux
发布时间:2025/04/20 浏览次数:131 分类:OPERATING SYSTEM
-
/etc/network/interfaces This article will look at the complete syntax explanation in Debian and its derivatives . The file /etc/network/interfaces allows you to assign static and dynamic IP addresses to interfaces, configure routing informa
How to use the Linux file remote copy command scp
发布时间:2025/04/08 浏览次数:151 分类:OPERATING SYSTEM
-
Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u
Linux server svn remote code synchronization
发布时间:2025/04/08 浏览次数:79 分类:OPERATING SYSTEM
-
In the article "Building SVN Service Project and Synchronizing Code to Project Directory" , we briefly introduced how to use SVN to synchronize submitted code to the working directory. But there is a problem here, that is, the SVN service a
Nodejs automatically restarts after modifying the code
发布时间:2025/04/08 浏览次数:93 分类:OPERATING SYSTEM
-
NodeJs can automatically restart after modifying the code, saving us the trouble of ctr+c and then using node. But in terms of time, if the project is already online and running normally, and there are not many modifications, then we can do