yum install subversion
4.配置版本库(添加用户和配置权限,以下配置均需顶格写,否则出错):
vi /data/svn/default/conf/authz
vi /data/svn/default/conf/passwd
##############################
[users]
centos = 123456 #用户centos
##############################
vi /data/svn/default/conf/svnserve.conf
##############################
anon-access = none #匿名用户访问权限,无
auth-access = write #普通用户访问权限,读 写
password-db = passwd #用户密码文件
authz-db = authz #权限配置文件
realm = /data/svn/default #版本库所在目录
##############################
vi /data/svn/default2/conf/authz
vi /data/svn/default2/conf/passwd
##############################
[users]
centos = 123456 #用户centos
##############################
vi /data/svn/default2/conf/svnserve.conf
##############################
anon-access = none #匿名用户访问权限,无
auth-access = write #普通用户访问权限,读 写
password-db = passwd #用户密码文件
authz-db = authz #权限配置文件
realm = /data/svn/default2 #版本库所在目录
##############################
5.启动svn服务:
svnserve -d -r /data/svn/
如果报错则需要关闭进程并重新启动
ps aux | grep svn
kill -9 14268
svnserve -d -r /data/svn/
7.防火墙放开3396端口允许外部访问:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
8.测试,在linux WEB目录下 checkout:
[root@localhost conf]# cd /www/
[root@localhost www]# svn checkout svn://localhost/default www
Authentication realm: /data/svn/default
Password for 'root':
Authentication realm: /data/svn/default
Username: centos
Password for 'centos':
Store password unencrypted (yes/no)? y
Skipped '.'
Summary of conflicts:
Skipped paths: 1
[root@localhost www]# touch 1.php
[root@localhost www]# svn add 1.php
A 1.php
[root@localhost www]# svn commit -m "add" 1.php
Adding 1.php
Transmitting file data .
Committed revision 2.
[root@localhost www]#
============其他操作===========
cd /www/wwwroot/default/www 更新版本
svn update 更新版本
svn cleanup 解除锁定
rm -rf ~/.subversion/auth 忘记账号
============================
9.用6的方法checkout 版本库2
10. PC上测试 checkout是否正常:
windows 下载 TortoiseSVN=》
D:/www/default/目录下,右键SVN checkout=》
URL填写:svn://xxxxx.com/default=》
点击OK,填写账号centos/123456
确定后 开始更新线上版本库文件
11.用同样方法 在D:\www\default2\目录下checkout 版本库2
12.加钩子,实现 有新提交时,站点目录自动更新版本:
//添加新web目录作为开发测试站点
/www/wwwroot/default_test/www (Apache需要添加对应子站点,子域名需要解析过来)
//添加用户
[root@localhost hooks]# useradd -u 1000 webserver -d /www/wwwroot/
[root@localhost hooks]# passwd webserver
Changing password for user webserver.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
//添加文件post-commit
[root@localhost hooks]# vim post-commit
//文件post-commit中加入以下脚本
#!/bin/sh
export LANG=zh_CN.UTF-8
SVN=/usr/bin/svn
WEB=/www/wwwroot/default_test/www
$SVN update $WEB --username webserver --password ******
//赋权限
[root@localhost hooks]# chown webserver post-commit
[root@localhost hooks]# chmod 755 post-commit
//版本库conf/authz,conf/passwd文件中添加账号
webserver / ******
//关闭svn进程,重新开启
svnserve -d -r /data/svn
//切换到测试站点目录
cd /www/wwwroot/default_test/
//用账号 webserver / ****** 检出
svn checkout svn://localhost/default www
//PC端提交新文件后,若测试站点目录下是否已出现新添加的文件就OK了
ls /www/wwwroot/default_test/www