服务器版本 CentOS Linux 7.6.1810 (Core)
1. 安装SVN
- yum update 更新yum
- yum install subversion 安装svn
2. 建立svn仓库
- 建立svn目录:mkdir /home/.svn
- cd /home/.svn
- 建立仓库目录:mkdir python
- 创建仓库python: svnadmin create /home/.svn/python
3. 配置和管理svn
- 以python仓库为例;配置文件在 /home/.svn/python/conf 目录下
- 修改 svnserver.conf
- anon-access:匿名用户的权限,可以为read,write和none,默认值read。不允许匿名用户访问:anon-access = none
- password-db:密码数据库的路径,去掉前边的#
- authz-db:认证规则库的路径,去掉前边的#。
- realm = /home/.svn/python (你的仓库目录)
- 例:
- 配置passwd文件 添加用户名和密码? 例:user1 = user1
- 配置authz 文件
- [groups] section:为了便于管理,可以将一些用户放到一个组里边,比如:users=user1,user2
- groups下边的sections表示对一个目录的认证规则,比如对根目录的认证规则的section为[/]
- 设置单用户的认证规则时一个用户一行,如 [/]
user1=rw #allen对根目录的权限为rw
user2=r #ellen对根目录的权限为r
如果使用group,需要在group名字前加@,如
@users=rw #group owner中的用户均为rw,等价于上边的两句话 - 例:
4. 启动和停止svn
- 启动(svn默认使用3690端口)请开放端口
- 从python目录启动 svnserve -d -r /home/.svn/python 访问方式则为 svn://服务器IP/
- 从.svn目录启动 svnserve -d -r /home/.svn 访问方式则为 svn://服务器IP/python(推荐)
- 如果需要svn自启动,把命令加入/etc/rc.local中
- 停止 killall svnserve
- 检查svn服务器是否已经启动:netstat -an | grep 3690
5. 实现SVN与WEB同步
- 我的web目录为 /www/wwwroot/python
- 建立同步脚本
- cd /home/.svn/python/hooks/
- cp post-commit.tmpl post-commit
- 修改 post-commit 文件
- 在末尾添加 export LANG=zh_CN.UTF-8
- 在末尾添加 svn co svn://localhost/python /www/wwwroot/python/
- 执行 chmod +x post-commit
- 执行 svn co svn://localhost/python /www/wwwroot/python/
- 如果在svn上传时发生 错误 mailer.py common not found 请将 /home/.svn/python/hooks/post-commit 中50行左右 mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf 注释或删除掉