系统:vmware11 centos6.5
svn全名subversion
官网:http://subversion.apache.org/
centos中的防火墙和selinux会影响非本机的正常访问svn,本文仅仅是测试,所以首先关闭selinux和防火墙
关闭selinux:
[root@localhost Desktop]# vim /etc/selinux/config
将SELINUX配置项设为disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
之后重启系统
之后查看selinux状态
[root@localhost Desktop]# getenforce
Disabled
selinux关闭了
关闭防火墙:
[root@localhost Desktop]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
防火墙关闭完成
开始安装svn
[root@localhost Desktop]# yum install subversion -y
提示
Installed:
subversion.x86_64 0:1.6.11-15.el6_7
Dependency Installed:
perl-URI.noarch 0:1.40-2.el6
Complete!
安装成功
yum安装后,svn命令会被加到环境变量中,可以直接使用。
创建一个svn版本库,我这里讲版本库放在/mydata/svn中
[root@localhost Desktop]# mkdir -p /mydata/svn
[root@localhost Desktop]# svnadmin create /mydata/svn/
之后进入/mydata/svn,可以看到版本库的一些文件
[root@localhost Desktop]# cd /mydata/svn/
[root@localhost svn]# ls
conf db format hooks locks README.txt
我们这里要对版本库进行配置,配置文件都在conf文件夹下
[root@localhost svn]# cd conf/
[root@localhost conf]# ls
authz passwd svnserve.conf
看到conf目录下有3个配置文件
svnserver.conf 系统配置文件,包括权限配置文件位置,用户配置文件位置等,具体可查看官网文档
authz 权限配置文件
passwd 用户配置文件
注意:svn配置文件的配置项都需要去掉行前面的空格,就是行的第一个字符就是配置项内容,否则配置会无效
首先配置svnserver.conf文件
[root@localhost conf]# vim svnserve.conf
[general] 下有这几个配置选项,配置为如下参数
anon-access = none //匿名用户权限,none为没有权限,默认是read可读权限
auth-access = write //用户权限,可写
password-db = passwd //用户配置文件位置,省略路径表示svnserver.conf文件同路径下
authz-db = authz //权限配置文件位置,省略路径表示svnserver.conf文件同路径下
退出保存:wq
配置用户文件
[root@localhost conf]# vim passwd
在[users]项下配置用户及账号
这里配置3个账号,user1、user2、user3,密码都是123123
[users]
# harry = harryssecret
# sally = sallyssecret
#
user1=123123
user2=123123
user3=123123
退出保存 :wq
配置权限文件
[root@localhost conf]# vim authz
做如下配置
[groups]
g_user1=user1 //定义user1在g_user1用户组下,下同理
g_user2=user2
g_user3=user3
[/]
@g_user1=rw //定义g_user1用户组在svn根目录下的权限为可读可写,下同理。
@g_user2=rw
@g_user3=rw
保存退出:wq
到这里配置完成,启动svn服务
[root@localhost conf]# svnserve -d -r /mydata/svn/
验证svn服务是否正常启动
查看进程
[root@localhost conf]# ps -ef|grep svn|grep -v grep
root 3909 1 0 23:29 ? 00:00:00 svnserve -d -r /mydata/svn/
检测端口
[root@localhost conf]# netstat -ln |grep 3690
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN
PS:重启svnserve需要把原来的进程杀了,然后在执行启动命令,杀进程可以用如下命令
[root@localhost conf]# killall svnserve
svn服务启动完成后,就可以开始我们的代码部署了。
我们先在根目录下建有个叫trunk的文件
svn mkdir -m 'create trunk' file:///mydata/svn/trunk
创建完成了trunk之后,我们开始正式测试版本库的运行,这里现在centos本地测试,
[root@localhost Desktop]# mkdir -p /mycode/trunk
[root@localhost Desktop]# cd /mycode/trunk/
checkout svn服务器的trunk目录到/mycode/trunk ,第一次使用svn服务,系统会将svn用户和系统用户进行绑定,之后就不用一直输svn的用户名和密码了。
[root@localhost trunk]# svn co svn://localhost/trunk
出现如下提示
[root@localhost trunk]# svn co svn://localhost/trunk .
//这里不要漏掉最后的一个点(.),点的意思是svn目录trunk下的所有文件,不写会把trunk文件夹拉下来。co是checkout的缩写,也可以直接用checkout
Authentication realm: <svn://localhost:3690> f49a908a-a810-43b1-9efb-4959e8c91db5
Password for 'root':
输入root账号密码,之后出现如下提示:
Authentication realm: <svn://localhost:3690> f49a908a-a810-43b1-9efb-4959e8c91db5
Username:
输入你的svn用户名,我这里用user1
之后出现如下提示,要求输入user1的密码
Password for 'user1':
输入密码后,会有如下提示,意思是问你不加迷存放user1的密码,输入yes就好
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://localhost:3690> f49a908a-a810-43b1-9efb-4959e8c91db5
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)?
之后出现Checked out revision 1.
这里就checkout成功了,可以试一下弄个文件,然后传到svn上
[root@localhost trunk]# vim helloworld.php
<?php
echo "helloworld";
?>
[root@localhost trunk]# ls
helloworld.php
之后helloworld.php cimmit到svn服务器上
[root@localhost trunk]# svn add helloworld.php
A helloworld.php
[root@localhost trunk]# svn ci -m 'first ci' helloworld.php
Adding helloworld.php
Transmitting file data .
Committed revision 2.
到这里本地测试完成。
下面我们来测试svn用户组及个svn目录的权限配置
首先删除掉刚刚对user1用户的缓存,不然本系统用户一直会默认用user1用户操作svn
[root@localhost trunk]# rm -fr ~/.subversion/auth/svn.simple/*
进入/mydata/svn/conf目录进行配置
配置authz文件
[groups]
g_user1=user1
g_user2=user2
g_user3=user3
[/]
@g_user1=r //这里把W去掉,g_user1用户组只有读权限
@g_user2=rw
@g_user3=rw
重启svn
[root@localhost conf]# killall svnserve
[root@localhost conf]# svnserve -d -r /mydata/svn/
[root@localhost conf]#
我们继续进入刚刚的/mycode/trunk目录,试试改变helloworld.php并上传
[root@localhost trunk]# vim helloworld.php
<?php
echo "helloworld";
echo "helloworld has changed";
?>
尝试上传
[root@localhost trunk]# svn ci -m 'hellowrold has changed'
helloworld.php
Authentication realm: <svn://localhost:3690> f49a908a-a810-43b1-9efb-4959e8c91db5
Password for 'root':
Authentication realm: <svn://localhost:3690> f49a908a-a810-43b1-9efb-4959e8c91db5
Username: user1
Password for 'user1':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://localhost:3690> f49a908a-a810-43b1-9efb-4959e8c91db5
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
svn: Commit failed (details follow):
svn: Authorization failed
这里尝试上传,在输入用户user1用户密码后,系统报错说没有权限,说明配置成功,我们user1用户实在g_user1用户组下,但是g_user1用户组只有读权限。
本文就暂时写到这里,之后的其他配置,如各个目录的权限配置等可以查看官网文档。另外读完本文后请去官网看看,哪里说明文档是最全的,同时可以学学英文。