你的浏览器不支持canvas

做你害怕做的事情,然后你会发现,不过如此。

Docker搭建svn服务器

时间: 作者: 黄运鑫

本文章属原创文章,未经作者许可,禁止转载,复制,下载,以及用作商业用途。原作者保留所有解释权。


说明

  • 服务器版本CentOS Linux 7
  • 常用的Docker镜像有两个garethflowers/svn-serverelleflorio/svn-server,本文使用的是elleflorio/svn-server,因为集成了管理界面并且支持http协议

安装Docker

  1. 执行curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun安装docker,其他安装方式参考 CentOS Docker 安装
  2. 执行sudo systemctl start docker启动docker
  3. 执行sudo systemctl enable docker添加docker开机启动
  4. 执行docker -v查看是否安装成功
     [root@localhost ~]# docker -v
     Docker version 23.0.4, build f480fb1
    
  5. 执行systemctl stop firewalld.service关闭防火墙
  6. 执行systemctl disable firewalld.service关闭防火墙开机启动

安装svn

  1. 在宿主机中创建目录,用于存放svn的相关文件
    • 执行mkdir -p /home/svndata/repository创建目录,用来存放svn的仓库
    • 执行mkdir -p /home/svndata/subversion创建目录,用来存放subversion-access-controlpasswd文件
    • 执行mkdir -p /home/svndata/svnadmin/data创建目录,用来存放管理界面的配置文件
    • 执行mkdir -p /home/svndata/apache2创建目录,用来存放/etc/apache2/httpd.conf,解决svn启动报错AH00558: httpd
  2. 启动容器,先不要挂载目录
    • 执行docker run -d --name svn-server -p 8080:80 -p 3690:3690 elleflorio/svn-server:latest启动容器
    • 执行docker logs --tail 500 svn-server查看日志,启动成功日志如下,日志中的报错AH00558: httpd后续再处理

        [root@localhost ~]# docker logs --tail 500 svn-server
        [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
        [s6-init] ensuring user provided files have correct perms...exited 0.
        [fix-attrs.d] applying ownership & permissions fixes...
        [fix-attrs.d] 01-resolver-resolv: applying... 
        [fix-attrs.d] 01-resolver-resolv: exited 0.
        [fix-attrs.d] done.
        [cont-init.d] executing container initialization scripts...
        [cont-init.d] 30-resolver: executing... 
        [cont-init.d] 30-resolver: exited 0.
        [cont-init.d] 40-resolver: executing... 
        [cont-init.d] 40-resolver: exited 0.
        [cont-init.d] done.
        [services.d] starting services
        AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6. Set the 'ServerName' directive globally to suppress this message
        [services.d] done.
      
  3. 将相关文件拷贝到宿主机
    • 执行docker cp svn-server:/etc/subversion /home/svndata
    • 执行docker cp svn-server:/opt/svnadmin/data /home/svndata/svnadmin
    • 执行docker cp svn-server:/etc/apache2/httpd.conf /home/svndata/apache2/httpd.conf
  4. 修改httpd.conf,解决启动时报错AH00558: httpd
    • 找到/home/svndata/apache2/httpd.conf文件中的ServerName,复制一行改为本机域名或ip+端口,如下

        #
        # ServerName gives the name and port that the server uses to identify itself.
        # This can often be determined automatically, but we recommend you specify
        # it explicitly to prevent problems during startup.
        #
        # If your host doesn't have a registered DNS name, enter its IP address here.
        #
        #ServerName www.example.com:80
              
        # 改为自己的域名或ip+端口
        ServerName 10.10.1.27:8080
              
        #
        # Deny access to the entirety of your server's filesystem. You must
        # explicitly permit access to web content directories in other 
        # <Directory> blocks below.
        #
      
  5. 重新启动容器,并挂载目录
    • 执行chmod 777 -R /home/svndata/*修改挂载的目录权限
    • 执行docker stop svn-server停止旧容器
    • 执行docker rm svn-server删除旧容器
    • 执行如下命令,启动容器并挂载目录

        docker run -d -v /home/svndata/repository:/home/svn -v /home/svndata/subversion:/etc/subversion -v /home/svndata/svnadmin/data:/opt/svnadmin/data -v /home/svndata/apache2/httpd.conf:/etc/apache2/httpd.conf --name svn-server -p 8080:80 -p 3690:3690 elleflorio/svn-server:latest
      
    • 执行docker logs --tail 500 svn-server查看日志,启动成功日志如下

        [root@localhost ~]# docker logs --tail 500 svn-server
        [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
        [s6-init] ensuring user provided files have correct perms...exited 0.
        [fix-attrs.d] applying ownership & permissions fixes...
        [fix-attrs.d] 01-resolver-resolv: applying... 
        [fix-attrs.d] 01-resolver-resolv: exited 0.
        [fix-attrs.d] done.
        [cont-init.d] executing container initialization scripts...
        [cont-init.d] 30-resolver: executing... 
        [cont-init.d] 30-resolver: exited 0.
        [cont-init.d] 40-resolver: executing... 
        [cont-init.d] 40-resolver: exited 0.
        [cont-init.d] done.
        [services.d] starting services
        [services.d] done.
      
  6. 浏览器访问管理界面http://10.10.1.27:8080/svnadmin,填写配置文件路径

     Subversion authorization file: /etc/subversion/subversion-access-control
     User authentication file (SVNUserFile):/etc/subversion/passwd
     Parent directory of the repositories (SVNParentPath):/home/svn
     Subversion client executable:/usr/bin/svn
     Subversion admin executable:/usr/bin/svnadmin
    

填写后点击Test按钮,全部显示Test passed.后,点击页面底部的Save configuration保存配置

image

保存成功后,会自动创建管理员User: admin Password: admin,点击login now登录管理员帐号

image

  • 管理端创建仓库后,需要给用户设置权限才能使用
  • 我使用的是小乌龟TortoiseSVN,检出版本库URL为http://服务器ip:8080/svn/仓库名称

问题

无法提交大文件和提交超时

  • 如果使用了Nginx,需要修改配置

      client_max_body_size 10240m # 设置文件上传大小限制
      proxy_send_timeout 600s   # 设置发送超时时间
      proxy_read_timeout 600s	 # 设置读取超时时间
    
  • 本项目使用的是阿里云容器服务 Kubernetes 版,需要添加Ingress注解

      nginx.ingress.kubernetes.io/proxy-body-size:10240m
      nginx.ingress.kubernetes.io/proxy-connect-timeout:600
      nginx.ingress.kubernetes.io/proxy-read-timeout:600
      nginx.ingress.kubernetes.io/proxy-send-timeout:600
    

对于本文内容有问题或建议的小伙伴,欢迎在文章底部留言交流讨论。