SVN 安装和搭建,自动更新。
1.安装svn
yum install subversion
2. 配置服务
mkdir -p /data/wwwsvn/myrepo #创建svn仓库的目录
这里可以自定义创建的目录,注意不是网站的文件目录。
svnadmin create /data/wwwsvn/myrepo #与上面的目录相同。
3. 进入conf修改配置文件
vim passwd 添加在末尾
[users]# harry = harryssecret# sally = sallyssecretyouname = yourpassword #你的用户和密码vim authz 添加在末尾
[/]yourname = rwvim svnserve.conf 关闭注释及修改变量
anon-access = read #匿名用户可读auth-access = write #授权用户可写password-db = passwd #使用哪个文件作为账号文件authz-db = authz #使用哪个文件作为权限文件realm = /data/www/myrepo # 认证空间名,版本库所在目录,和之前的一样4.打开端口
iptables -I INPUT -i eth0 -p tcp --dport 3690 -j ACCEPT #开放3690端口
>/etc/init.d/iptables save #保存配置
service iptables save #保存iptable规则
上面设置了开放3690端口,所以要在阿里云对应的实例安全组添加开放3690端口的规则,否则在本地checkout会失败!!
5.开启和关闭服务
svnserve -d -r /data/wwwsvn #开启killall svnserve #关闭
ps aux | grep svnserve #查看是否运行6.返回要部署的项目checkout。
cd /data/wwwroot/project
svn checkout svn://服务器ip:端口/xxx [xxxx为前文创建的版本库名称]
... #根据提示完成checkout
7.自动部署:
cd /data/wwwsvn/myrepo/hooks #你的版本仓库目录 cp post-commit.tmpl post-commit chmod -R 777 post-commit
vim post-commit把末尾的全注释掉,在末尾添加如下:
export LANG=zh_CN.UTF-8 #必须要这行 echo "hello world" >> /tmp/svn.log #用来测试钩子是否有执行,调试使用,如果正常就不需要这行了 /usr/bin/svn update /data/wwwroot/yourWebDir --username autoweb --password autoweb --no-auth-cache #也可以用其他方法,总之要保证web目录能正常update增加脚本执行权限
chmod +x post-commit
killall svnserve
开启svn:
svnserve -d -r /data/wwwsvn
8.检出本地
svn checkout svn://服务器ip:端口/xxxxx #xxx为你创建的版本库名称myrepo
9.把线上的项目拉到本地即可,此后每一次commit到服务器都会自动更新内容了。
浙公网安备 33010602011771号