Build svn version control in ubuntu environment

There are two types of svn version control under ubuntu, one is only svn, and the other is used in combination with apache2 application server. What we do today is only svn.

1. The first is to install the software package of the svn version controller first. The installation command is as follows:

 

sudo apt-get install subversion

2. Add a user group and add the current system user to the created user group. The user group I created is subversion. The add command is as follows

 

sudo addgroup subversion #Create user group
sudo addgroup zhangsan subversion #Add zhangsan to the subversion user group, zhangsan is the current system user

3. Create a repository, the command is as follows (it is best to create a repository in the home directory and create a new file)

 

sudo mkdir svn #create new folder
sudo mkdir repository #Create a repository folder
sudo svnadmin create repository #Use the svnadmin command to create a repository

 The directory structure after creation is as follows



 4. The next step is to attach permissions to the files, otherwise the files cannot be saved during the project development process, because the folders created in the non-user directory under the home directory have only read permissions but no write and delete permissions. The commands for additional permissions are as follows :

 

sudo chown -R www-data:subversion repository

sudo chmod -R g+rws repository

 After adding the command, you can verify the permissions of this folder as follows:

ls -l repository/db/txn-current-lock

# The result is as follows
-rw-rwSr-- 1 www-data subversion 0 11月 11 17:15 repository/db/txn-current-lock

 

5. The next step is to access, the access rules are as follows:

Mode Access Method
file:/// Directly access the file repository on the local hard disk
http://	         通过 WebDAV 协议访问支持 Subversion 的 Apache 2 Web 服务器
https://	 类似 http://,支持 SSL 加密
svn://	         通过自带协议访问 svnserve 服务器
svn+ssh://	 类似 svn://,支持通过 SSH 通道

 因为本文没有配置apache以及ssh安全访问因此可以使用直接访问或者通过自带协议访问

直接访问格式如下:

 

svn co file:///home/svn/myproject
#结果如下
取出版本 0。#因为里面没有任何文件所以是0

6.接下来就是访问的设置了,为svn添加用户,修改配置,在repository文件夹下面的conf目录下有这么三个文件夹 authz  passwd  svnserve.conf

 

svnserve.conf文件中将下面三行的前面的注释去掉,不能有空格

anon-access = read //匿名只能读 

auth-access = write//验证后才能有写的权限

password-db = passwd//密码都在passwd文件中

 

passwd文件中在[users]下添加用户以及密码,以下面的格式

zhangsan=123456

lisi=123456

 

在authz文件中对这些用户限定权限

在[groups]下面修改这些用户的操作权限

#创建两种用户组,等号后面的用户都分属这个组内,这些用户必须在passwd文件中存在

admin=zhangsan 

development=lisi

 

#为这些用户创建能够操作的目录以及操作权限,*代表匿名的,没有任何权限

[repository:/]

@admin = rw

* = 

[repository:/develop]

@development = rw

* = 

 

 

7.就是启动服务,启动服务的命令如下:

 

sudo svnserve -d -r /home/svn

 

-d 表示svnserver以“守护”进程模式运行
-r 指定文件系统的根位置(版本库的根目录),这样客户端不用输入全路径,就可以访问版本库

查看svn这个服务是否已经开启

ps -aux |grep svn

若是开启则显示结果类似与下面

warning: bad ps syntax, perhaps a bogus '-'?
See http://gitorious.org/procps/procps/blobs/master/Documentation/FAQ
root     20333  0.0  0.0  12276   696 ?        Ss   17:37   0:00 svnserve -d -r /home/svn
zhangsan  20366  0.0  0.0   5888   824 pts/0    S+   17:39   0:00 grep --color=auto svn

8.最后就是将这个svn这个服务设置成开机启动

(1).创建执行脚本svn.sh(/root路径下)

#!/bin/bash

svnserve -d -r /home/svn

(2).添加可执行权限

#chmod ug+x /root/svn.sh

(3).添加自动运行

#vim /etc/init.d/rc.local

在最后添加一行内容如下:

/root/svn.sh

(4).检查

 重启服务器,使用ps -aux |grep svn看看svn进程是否启动了

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326723482&siteId=291194637