CentOS SVN服务器安装配置

SVN的安装

安装很简单,尤其对于CentOS这种,直接:

# yum install subversion

不同发行版的Package安装方法参见http://subversion.apache.org/packages.html,当然,某些发行版下或者不闲麻烦可以直接源码编译安装,但是,灭霍霍霍霍~

安装完检查一下是否成功了

# svnserve --version

能正常显示版本信息就大功告成啦~

在挂载的数据盘下建立一个名为svn的仓库

 # cd /mnt/data_10G

 # mkdir svn

 # svnadmin create /mnt/data_10G/svn/

SVN配置

进入所建立仓库的配置目录/mnt/data_10G/svn/conf修改文件svnserve.conf

[general]
anon-access = none ## 匿名用户默认是read 但因无法查看log 所以改为none
auth-access = write ## 授权用户可写
password-db = passwd ## 使用哪个文件作为账号文件
authz-db = authz ## 使用哪个文件作为权限文件
realm = /mnt/data_10G/svn  ## 认证空间名,版本库所在目录

配置用户名密码

修改与配置文件同目录的passwd文件

[users]
zbx = z001
zzk = z002
wfx = w003

启动SVN服务器

# svnserve -d -r /mnt/data_10G/svn

-d表示守护进程, -r表示在后台执行

使用以下命令可以查看正在运行的SVN进程

# ps -ef | grep svn

使用命令

# killall svnserve

# kill -9 xxx(pid)

来停止SVN服务器。

到此的话,在服务器上执行co应该就没什么问题了。可是其他终端通过svn可能还访问不了咱的服务器ΦωΦ

防火墙配置

SVN的默认端口是3609,要在防火墙上开放这个端口才行

# /sbin/iptables -A INPUT -i eth0 -p tcp --dport 3690 -j ACCEPT
# /sbin/service iptables save

唉,我就是栽在这了。。。最好看下eth0这个参数,如果你的服务器刚好像我的一样有很多网卡,而且那个再用的不是eth0的话。。就要修改一下了恩。ΦωΦ

查看网络参数可以使用

# ifconfig

到此为止咱就应该能够成功地连上远程的SVN服务器了恩,checkout可以使用

# svn co svn://ip地址

然后按提示输入之前配置过的用户名和密码就好了。

更多的SVN命令就不在这粘贴了~

下面贴出我的配置文件
authz

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe

# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

[groups] 
[/] 
zbx = rw
zzk = rw
wfx = rw

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
zbx = z001
zzk = z002
wfx = w003

svnserve.conf

### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)

### Visit http://subversion.tigris.org/ for more information.

### [general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
# anon-access = read
# auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
# password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
# authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
# realm = My First Repository

[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256

[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = /mnt/svn

安装好的svn服务端,默认是不会开机自启动的,每次开机自己启动会很麻烦,我们可以把它设成开机启动

首先:编写一个启动脚本svn_startup.sh,我放在/root/svn_startup.sh

#!/bin/bash
/usr/bin/svnserve -d -r /mnt/svn/

这里的svnserve路径保险起见,最好写绝对路径,因为启动的时候,环境变量也许没加载。
绝对路径怎么查?

which svnserve

这里还有可能碰到一个问题,如果你在windows下建立和编写的脚步,拿到linux下,用vi或者vim修改后可能会无法执行,这是文件格式的问题
(也可以用UE打开,将下列脚本复制进去,脚本的编码格式在window上编码放在linux可能不识别,可以用UltraEdit转换下格式“文件–>转换–>DOS 转 UNIX“)

vi svn_startup.sh

输入:set ff 回车

如果显示的结果不是fileformat=unix

再次输入

set ff=unix

就OK了

然后修改该脚本的执行权限

chmod ug+x svn_startup.sh

或者万能的

chmod 777 svn_startup.sh

最后:加入自动运行

vi /etc/rc.d/rc.local
在末尾添加脚本的路径,如:
/root/svn_startup.sh

接下来可以重启测试是否开机自启动成功

ps -ef|grep svnserve

本人入坑 dos格式的.sh文件没有转unix linux没有识别 各种重启都没成功 如果不成功一定要检查下这里!!!