(1) Install needed packages
yum install mod_dav_svn subversion
In my PC, packages that were installed are
mod_dav_svn-1.6.11-10.el6_5.x86_64 and subversion-1.6.11-10.el6_5.x86_64
Note: if you are going to visit SVN repository via http, you shall have apache HTTP server installed firstly.
yum install –y httpd
httpd-2.2.15-30.el6.centos.x86_64 and
httpd-tools-2.2.15-30.el6.centos.x86_64 were installed automatically.
mkdir /home/svn
cd /home/svn
svnadmin create prjnameAfter the preceding commands were conducted, your first SVN project with name of prjname would have been created. You need to configure access permissions for the project.
cd /home/svn/prjname/conf
vi svnerve.conf
vi passwd
vi authzA good sample of these files can be found below.
[general]
anon-access = none
auth-access = write
password-db = /home/svn/conf/passwd
authz-db = /home/svn/conf/authz
#FILE passwd
[users]
username = password
#FILE authz
[groups]
admin = username, username1, username2
[prjname:/]
@admin = rw
* =
The conf files let username with password have access to the project. Use the below command to start SVN server.
svnserve –d –r /home/svn
svnserve –d –r /home/svn
Note: if you are going to visit SVN repository via http, you need to configure the http SVN user separately.
vi /etc/httpd/conf.d/subversion.conf
vi /etc/httpd/conf.d/subversion.conf
A good sample of the file can be found below.
LoadModule authz_svn_module modules/mod_authz_svn.so
# The /svn is according to the repository that you created before.
# The DAV svn shall be just DAV svn no matter the repository name of your SVN server.
<Location /svn>
DAV svn
SVNParentPath /home/svn
AuthType Basic
AuthName "the project name that you want it to be displayed"
AuthUserFile /etc/svn-auth-users
Require valid-user
</Location>
As you can see, the AuthUserFile was specified to be /etc/svn-auth-users. This is because that the http will require a cipher-texted password for the user, which is different from the former …/svn/prjname/conf/passwd file. You can use htpasswd command to create that file for http login user.
htpasswd -cm /etc/svn-auth-users username
After you input the password for the user, you will find a new file svn-auth-users was created with some cipher text inside.
And to let Apache server have access to the SVN server, you have to do some more configuration.
chown -R apache.apache prjname
## If you have SELinux enabled (you can check it with "sestatus" command) ##
## then change SELinux security context with chcon command ##
chcon -R -t httpd_sys_content_t /home/svn/prjname
## Following enables commits over http ##
chcon -R -t httpd_sys_rw_content_t /home/svn/prjname
At last, please restart the apache server to let the configuration come effect.
Service httpd restart
Go to http://SVN_SERVER_IP:port/svn/prjname/ to visit SVN repository.
It’s not necessary to have any of trunk, branches and tags files under the project home, but usually we can find these there files in most famous open source projects. Developers develop and submit under the trunk directory. For some uncertain requirements or a stage release version, it is better to save them in the branches directory. At last tags is read-only which is used to save phased production version for archiving. A tree like structure of the project will be similar as below.
- Project_svn_home
+ trunk
++ main.cpp (latest version which is under developing)
++ common.h
+
+ branches
++ -- r1.0
++ -- + main.cpp (Latest of 1.x version)
++ -- + common.h
++ -- r2.0
++ -- + main.cpp (Latest of 2.x version)
++ -- + common.h
+
+ tags (read-only)
++ -- r1.0
++ -- + main.cpp (version 1.0 release)
++ -- + common.h
++ -- r1.1
++ -- + main.cpp ( version 1.1 release)
++ -- + common.h
++ -- r1.2
++ -- + main.cpp ( version 1.2 release)
++ -- + common.h
...
++ -- r2.0
++ -- + main.cpp ( version 2.0 release)
++ -- + common.h
++ -- r2.1
++ -- + main.cpp ( version 2.1 release)
++ -- + common.h
...
There are two ways to create trunk, branches and tags directory structure.
1) Use the svn mkdir command to either make your directory structure without a working directory.
svn mkdir -m "structure-trunk" svn://localhost/prjname/trunk
svn mkdir -m "structure-branches" svn://localhost/prjname/branches
svn mkdir -m "structure-tags" svn://localhost/prjname/tags
OR
svn mkdir -m "structure-trunk" file:///home/svn/prjname/trunk
svn mkdir -m "structure-branches" file:///home/svn/prjname/branches
svn mkdir -m "structure-tags" file:///home/svn/prjname/tags
It may be possible that you have to write some comment to the log file when you are adding these directories without '-m' option.
2) Or, you can checkout a copy of the repository in into a working directory and do everything from there.
svn co svn://localhost/prjname
cd prjname
svn mkdir trunk tags branches
svn commit -m "Creating basic directory structure"Notice that you will not see the directories directly inside your repository. However, you can use the svn ls command to see the structure.
svn ls -R svn://localhost/prjname
OR
svn list svn://localhost/prjname
(4) Now you can connect prjname with any type of project in a reachable URI, or you can just check it out and then expand it as your like.
To checkout current developing codes in the trunk directory, you can use the following commands in a shell.
cd /home/user/projects/
svn co svn://localhost/prjname/trunk prjname -username your_user_name
After authentication your user name and password, you will find the project is checkout with the project name that you specified.
However, it’s very possible we want to use some IDE to initialize the project. As with me, I would create a dynamic WEB project by Eclipse and then share it to SVN.
For example, you can create a Dynamic Web Project with the Eclipse.
Then you can right click the home folder of the project and select the Team menu. You can take use the share project function to connect your project with SVN prjname.
svn://svnserver_IP:port/prjname
[Use specified folder name] trunk/
The default SVN port is 3690.
If the hosts of Eclipse and the SVN server are in different private LAN, then port mapping in router can be taken use of to connect the hosts.
I will going to discuss more aspects about SVN such as auto commit in a next article.
Note: It usually can be more comprehensive and helpful to refer to the subversion manual page http://svnbook.red-bean.com/ if you have questions.
本文详细介绍了如何在本地计算机上安装并配置SVN服务器,包括安装所需软件、创建和配置SVN仓库、设置访问权限以及创建项目结构。同时,提供了通过HTTP访问SVN仓库的方法,并解释了如何使用Eclipse进行项目初始化。最后,概述了SVN的基本目录组织形式,包括主干、分支和标签的管理。

4767

被折叠的 条评论
为什么被折叠?



