检查是否已经有svn
svnserve --version
在Linux下安装的是subversion,直接用yum 安装即可。
yum install -y subversion
创建svn资源仓库
配置文件就是在这一步生成。
[root@localhost ~] svnadmin create /svndir
[root@localhost ~] cd /svndir/
[root@localhost svndir] ls
conf db format hooks locks README.txt
[root@localhost svndir] cd conf/
[root@localhost conf] ls
authz passwd svnserve.conf
新增用户及密码,配置权限
已经看到在仓库下面生成了三个文件
authz #权限配置文件
passwd #用户名密码文件
svnserve.conf #资源库配置文件
备份这三个文件,以备不时之需
[root@localhost conf] ls
authz passwd svnserve.conf
[root@localhost svndir] scp authz authz.bak
[root@localhost svndir] scp passwd passwd.bak
[root@localhost svndir] scp svnserve.conf svnserve.conf.bak
添加新用户
[root@localhost conf]# vim passwd
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
[users]
# harry = harryssecret
# sally = sallyssecret
newuser = 123456
编辑服务配置
[root@localhost conf] vim svnserve.conf
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
realm = My First Repository
配置用户权限
[root@localhost conf] vim authz
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
[/]
# harry = rw
# &joe = r
# * =
newuser = rw
[repository:/]
# @harry_and_sally = rw
# * = r
newuser = rw
启动或者重启服务
[root@localhost conf] /etc/init.d/svnserve start
查看是否已监听端口
[root@localhost svndir] netstat -antlp | grep svn
如果无法连接svn服务,则请检查防火墙,访问的地址和相关配置文件。
在从机上checkout 根目录
[root@localhost ~] svn checkout svn://192.168.1.65/svndir/
[root@localhost ~] cd svndir/
[root@localhost svndir] ls
[root@localhost svndir] touch xiao
[root@localhost svndir] ls
xiao
[root@localhost svndir] pwd
/root/svndir
[root@localhost svndir] ls
xiao
[root@localhost svndir] svn add /root/svndir/xiao
A /root/svndir/xiao
[root@localhost svndir] svn commit /root/svndir/xiao -m 1
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: ^Csvn: Commit failed (details follow):
n: Caught signal
[root@localhost svndir] svn commit /root/svndir/xiao -m 1
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Password for 'root':
Authentication realm: <svn://192.168.1.65:3690> My First Repository
Username: yunwei
Password for 'yunwei':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://192.168.1.65:3690> My First Repository
can only be stored to disk unencrypted! You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible. See the documentation for details.
You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Adding xiao
Transmitting file data .
Committed revision 1.
注意:
1、提交代码前,必须先cd到/root/svndir/(就是checkout下来的)目录里;
2、服务器上没有的文件,在客户端需要先add预提交,再commit,如果服务器端已有的文件,直接commit
预提交的命令:
svn add /root/svndir/xiao
提交的命令:
svn commit /root/svndir/xiao -m 1
出现committed revision 1 提交成功了。
14. svnserve -d -r /var/svn/default-repo/ #启动svn server (默认端口3690)
注:同一台服务器可以运行多个svnserver,只需要启动时换一个端口即可:svnserve -d -r /var/svn/another-repo/ --listen-port 3691