linux的SVN搭建与同步

linux的SVN搭建与同步

以下的配置文件,开头都不能有空格

安装:
yum install subversion

验证:
svnserve --version

代码库创建:(类似,可以建立多个仓库)[repo]
mkdir -p 绝对路径
svnadmin create 绝对路径/仓库名称
as:
mkdir -p /opt/svn/repositories
svnadmin create /opt/svn/repositories
执行上面的命令后,自动建立repositories库,
查看/opt/svn/repositories 文件夹发现包含了conf, db,format,hooks, locks, README.txt等
文件,说明一个SVN库已经建立。


配置代码库:
进入上面生成的文件夹conf下,进行配置
cd 绝对路径/conf
as:
cd /opt/svn/repositories/conf

用户密码passwd配置:
[root@localhost password]# cd /opt/svn/repositories/conf
[root@admin conf]# vim passwd
[users]
# harry = harryssecret
# sally = sallyssecret
#增加对,用户名=密码
#as:
lin3615=lin3615
fuck=fuck

权限控制authz配置:
[root@admin conf]# vim authz
#设置[/]代表根目录下所有的资源
[/]
#用户名=权限 as
lin3615=rw
fuck=rw
服务svnserve.conf配置:
[root@admin conf]# vim /绝对路径/svnserve.conf
[general]
#匿名访问的权限,可以是read,write,none,默认为read
anon-access=none
#使授权用户有写权限
auth-access=write
#密码数据库的路径
password-db=passwd
#访问控制文件
authz-db=authz
#认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字
# realm=/仓库绝对路径/仓库名
#as:
realm=/opt/svn/repositories

配置防火墙端口:
[root@localhost conf]# vim /etc/sysconfig/iptables
添加以下内容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
保存后重启防火墙
[root@localhost conf]# service iptables restart

启动SVN:
#svnserve -d -r /绝对路径/仓库名 [--listen-port 端口号]
#as:
svnserve -d -r /opt/svn/repositories --listen-port 3690
同理,可以启动多个指定的仓库,只要端口不同即可

查看SVN进程:
[root@localhost conf]# ps -ef|grep svn|grep -v grep

停止重启SVN:
[root@localhost password]# killall svnserve //停止
启动:
# svnserve -d -r /绝对路径/仓库名
#as:
[root@localhost password]# svnserve -d -r /opt/svn/repositories // 启动

测试:(可以从这里导入项目,方法一)
客户端连接地址:svn://ip:端口号
用户名/密码: lin3615/lin3615

如果连接失败,则
关闭防火墙
1) 临时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
2) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off

方法二导入项目:(从svn服务器本身导入,即把别的文件[夹]导入到svn仓库中去)
svn import 项目绝对路径 svn://ip[:端口号] -m "comment"
as:
svn import /var/www/html/test svn://192.168.0.8:3690 -m "从目录test导入到svn仓库"

把svn仓库项目导出到指定的目录
svn co svn://ip /绝对路径/目录/
as
svn co svn://192.168.0.8:3690 /var/www/html/test/

svn仓库与指定的目录同步,(如web目录)
打开仓库目录中的hooks目录,建立 post-commit:
as:
打开 /opt/svn/repositories/hooks下的 post-commit,即建立这样的文件
加入
#!/bin/sh

export LANG=zh_CN.UTF-8 #如果是 GB2312,则为 zh_CN.GB2312,这里统一下文件编码
cd /var/www/html/test #要与同步的目录绝对路径
/usr/bin/svn cleanup # svn路径
/usr/bin/svn up /var/www/html/test --username "用户名" --password "密码"
#用户和密码是在 passwd指定的
若出现:post-commit错误代码255,应该是post-commit脚本权限不对,赋予777权限即可

如果在本地上传代码时,出现类似
svn: Can't convert string from 'UTF-8' to native encoding:
svn: ?230?150?176?229?187?186?\163.txt
svn: Working copy '/var/www/html/test' locked
svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)

则:
export LC_CTYPE="zh_CN.UTF-8"
根据你的系统字符集设置变量,如果 zh_CN.UTF-8 不行,有可能要改成 GB2312:
也有可能为:
export LANG="zh_CN.UTF-8"

接着执行 svn cleanup,要先切换到指定的目录,即要同步的目录,如 /var/www/html/test中
这样就可以了