centos 6.5 轻松部署 apache+svnmanager+svn

svnmanager   svnmanager汉化   系统服务  
环境配置

系统环境: CentOS 6.5 X64
仓库路径: /data/svnroot/repos
相关软件: apache+php+mysql+svnmanager+subversion

yum 安装简单省事
cd /etc/yum.repos.d && mv CentOS-Base.repo CentOS-Base.repo.bak && wget http://mirrors.163.com/.help/CentOS6-Base-163.repo  
yum install mysql mysql-server http mod_dav_svn  php php-pear php-mysql subversion php-mbstring -y  
创建仓库
mkdir -p /data/svnroot/repos  
svnadmin create /data/svnroot/repos/test  
chown apache.apache /data/svnroot/ -R  
配置apache (/etc/httpd/conf/httpd.conf)
  • 加载svn模块
LoadModule dav_svn_module modules/mod_dav_svn.so  
LoadModule authz_svn_module modules/mod_authz_svn.so  
  • 增加虚拟主机配置
AddDefaultCharset GB2312  
AddType application/x-httpd-php .php  
DirectoryIndex index.html index.php  
<Location /svn/>  
        DAV svn
        SVNListParentPath on
        SVNParentPath /data/svnroot/repos             #仓库路径
        AuthType Basic
        AuthName "My SVN"
        AuthUserFile /data/svnroot/repos/passwdfile
        AuthzSVNAccessFile /data/svnroot/repos/accessfile
        Require valid-user
</Location>  
<Directory "/var/www/html/svnmanager/">  
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from all
</Directory>  
  • 创建认证文件
touch /data/svnroot/repos/passwdfile  
touch /data/svnroot/repos/accessfile  
chown apache.apache /data/svnroot/repos/ -R  
  • 启动apache并验证svn
service httpd configtest                                     #测试配置文件  
service httpd start                                          #启动  
访问 http://ip/svn/                                          #看是否有提示输入用户名密码
安装配置svnmanager
  • 下载安装
wget http://liquidtelecom.dl.sourceforge.net/project/svnmanager/svnmanager/1.10/svnmanager-1.10.tar.gz  
wget http://softimdst.oss-cn-beijing.aliyuncs.com/svn%2Fsvnmanager_cn.tar.gz  
#汉化
tar zxf svnmanager-1.10.tar.gz && tar zxf svn%2Fsvnmanager_cn.tar.gz  
\cp -fr svnmanager svnmanager-1.10
mv svnmanager-1.10 /var/www/html/  
  • 安装VersionControl_SVN
cd /usr/share/pear/  
rm -fr .channels/  
pear update-channels  
pear install --alldeps VersionControl_SVN-0.4.0  

Starting to download VersionControlSVN-0.5.1.tgz (31,121 bytes)
.........done: 31,121 bytes
install ok: channel://pear.php.net/VersionControl
SVN-0.5.1
出现如上提示,表示安装成功

  • 创建数据库
service mysqld start  
mysql -uroot -p  
mysql> create database svnmanager;  
mysql> grant all on svnmanager.* to svn@'localhost' identified by '123456';  
mysql> flush privileges;  
  • 更改svnmanager的配置文件
cd /var/www/html/svnmanager/  
cp config.php.linux config.php  

vim config.php

<?php  
$lang                                           = "en_US.UTF-8";
$htpassword_cmd                         =       "/usr/bin/htpasswd";
$svn_cmd                                =       "/usr/bin/svn";
$svnadmin_cmd                           =       "/usr/bin/svnadmin";
$svn_config_dir                         =       "/data/svnroot/repos";
$svn_repos_loc                          =       "/data/svnroot/repos";
$svn_passwd_file                        =       "/data/svnroot/repos/passwdfile";
$svn_access_file                        =       "/data/svnroot/repos/accessfile";
$svn_trash_loc                          =       "";
$svnserve_user_file="";
$dsn                                    =       "mysqli://svn:123456@localhost/svnmanager";
$smtp_server                    =       "smtp.imdst.com";
$admin_name                                             =       "admin";
$admin_temp_password                    =       "admin";
?>
  • 测试是否成功
    http://ip/svnmanager
    默认用户密码 admin/admin

  • 如果出现 403 Forbidden,请关闭Selinux

setenforce 0  
  • 第一次登陆看不到其他选项,添加一个新的管理员用户就可以使用了
SVN 提交强制写注释勾子
  • 项目团队开发期间,总是有人忘记写注释
    • 导致其他人员不知道提交的是什么代码,给回滚带来不必要的麻烦
    • 总是需要有人提醒提交时添加注释
  • 进入项目仓库对应目录的hooks
    cd /data/svnroot/repos/project/hooks
  • 修改 pre-commit.tmpl
    mv pre-commit.tmpl pre-commit && chmod +x pre-commit
#!/bin/sh
REPOS="$1"  
TXN="$2"  
RES="OK"  
SVNLOOK=/usr/bin/svnlook  
$SVNLOOK log -t "$TXN" "$REPOS" \
| egrep  "[^[:space:]]+" >/dev/null  || unset RES
if [ "$RES" != "OK" ] ; then  
 echo "欢迎你不写,欢迎你不填,别人吃饭你掏钱" 1>&2
 exit 1
fi  
# All checks passed, so allow the commit.
exit 0  
如果客户端出现Error: [Error output could not be translated from the native locale to UTF-8.] 无法显示中文的情况
  • Subversion 升级到 1.8 有一个新特性 SVNUseUTF8 On
  • 具体升级操作
cat > /etc/yum.repos.d/wandisco-svn.repo <<EOF  
[WandiscoSVN]
name=Wandisco SVN Repo  
baseurl=http://opensource.wandisco.com/centos/6/svn-1.8/RPMS/\$basearch/  
enabled=1  
gpgcheck=0  
EOF  
yum install subversion  
  • 修改httpd.conf并重启httpd
<IfModule mod_dav_fs.c>  
    # Location of the WebDAV lock database.
    DAVLockDB /var/lib/dav/lockdb
    SVNUseUTF8 On
</IfModule>

/etc/init.d/httpd graceful

Nginx 反向代理apache

  • apache User和Group要和nginx一致
  • 如果为本机Listen地址改成内网如10.104.235.118:8080
  • mysql.sock和php session目录权限
upstream apachephp  {  
    server 10.104.235.118:8080;
}

server {  
    listen 80;
    server_name  svn.ops.linksdk.cn;

    root   html;
    index  index.html index.htm index.php;
    error_log   /data/logs/svn.09games.com.err.log;
    access_log  /data/logs/svn.09games.com.acc.log;
    ## send request back to apache ##
    location / {
        proxy_pass  http://apachephp;

        #Proxy Settings
        proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
}

SVN备份和还原

SVN常用指令

补充

  • 如果出现 403 Forbidden
  • 检查 selinux /etc/sysconfig/selinux
    SELINUX=disabled
  • 不重启生效
    setenforce 0

  • 出现require_once(VersionControl/SVN.php): failed to open stream: No such file or directory错误

  • 请确定VersionControl_SVN是否安装成功