一、背景:
作为一个专业的后端程序员(手动狗头),当然是要会SVN的使用的。但是我接到的工作是将windows的SVN程序迁移至linux!那能咋整,反抗不了就只能默默忍受呗! 在经过各种查询资料和踩坑后的一个月(当然我不只是做这一个活)公司的整个SVN程序在linux系统上顺利的运行起来了。 我也看了网上不少博主相关的教程,再结合我迁移完公司大大小小五六十个的SVN程序库后,我打算自己写一篇博客。希望对以后有相同的业务场景的同行有所帮助,少走弯路。
二、本博客的重点:
我不喜欢重复造轮子的工作,所以这篇博客主要记录我迁移过程中参考的博客和操作顺序以及操作过程中遇到的一些坑。
三、主要流程:
1:在你的linux服务器安装SVN的环境并熟悉SVN的一些常用指令以及配置方式
这边我主要参考黎陌MLing大佬的博客:(建议先看完大佬博客,然后看完我的小tips,再操作!)
注意点和实例:
(1):在你执行以下步骤前,你得提前规划你所有的SVN程序应该放在哪个目录下
(自己因为没有提前检查linux的挂载磁盘大小,导致后面磁盘空间满了,全部删除重来)
你应该先查看自己linux的磁盘挂载情况:df -Th
可见我这边磁盘主要挂载的大空间在/home目录下,那我就将SVN的所有版本库在/home目录下创建
我的实际操作: svnadmin create /home/svndata/svn/app 当然我这边不止有一个版本库,下面就是创建完的效果:
(2):使用一个authz文件和一个密码文件来管理所有版本库
每个新建好的SVN版本库的conf目录下都有这三个文件:
一个版本库无所谓,但是如果你有多个SVN版本库,为了方便后续的操作和维护,我推荐使用一个authz文件和一个密码文件来管理所有版本库
处理过程:
1. 修改每个版本库的svnserve.conf文件(改好一个,其他的直接替换):
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository. (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
### Visit http://subversion.apache.org/ for more information.
[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
anon-access = none
auth-access = write
### The password-db option controls the location of the password
### database file. Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = /home/svndata/svn/htpasswd
### The authz-db option controls the location of the authorization
### rules for path-based access control. Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file. If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = /home/svndata/svn/authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa. The default realm
### is repository's uuid.
realm = /home/svndata/svn
### The force-username-case option causes svnserve to case-normalize
### usernames before comparing them against the authorization rules in the
### authz-db file configured above. Valid values are "upper" (to upper-
### case the usernames), "lower" (to lowercase the usernames), and
### "none" (to compare usernames as-is without case conversion, which
### is the default behavior).
# force-username-case = none
[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-check# 使非授权用户无法访问only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256
主要注意以上5个参数:
anon-access = none #(别人博客有说明,自己看)
auth-access = write #(别人博客有说明,自己看)
password-db = /home/svndata/svn/htpasswd #指定密码文件存储位置(我这边因为配置了http和https所有密码文件名字有所变化)
authz-db = /home/svndata/svn/authz #指定授权文件存储位置
realm = /home/svndata/svn #这个我也没深究重不重要,建议配置为项目库创建的上一层(因为我是这么做的)
2. 准备好统一的authz文件和密码文件
放置在上面svnserve.conf配置的password-db、authz-db指定的路径(当然windows应该有原始的用户的authz和密码文件,不一定可以直接用,建议看下格式)
3.单独说明下authz的多版本库如何配置
如果你的版本库叫app(也就是你的创建语句是:svnadmin create /home/svndata/svn/app),可以在这样写:
[app:/]
来设置app这个版本库的单独使用的用户,当然也可以做更加细致的路径控制:
[app:/abc]
这样可以设置这个版本库的abc路径的具体使用用户
(3):启动项目并在自己的局域网内测试
我的实际启动命令: svnserve –d –r /home/svndata/svn
不出意外的话应该是不会出意外的
2:将你的Windows的SVN打包,并上传到你的linux磁盘中,最后还原数据到对应的版本库
这边我主要参考殷玮大佬的博客:(建议先看完大佬博客,然后看完我的小tips,再操作!)
信我的话建议从这个位置开始看(并且先用一个小的项目测试)
注意点和实例:
注意在windows中腾出足够的空间来制作dump文件
(本人因为没关注或者错误估算了制作出来的dump文件的大小,导致dump文件重做,浪费了很多时间)
*** 正确的估算制作出来dump的大小***
第一步:在windows中找到原始的SVN版本库的文件夹,鼠标右击-点击属性-来查看大小
举个栗子:如果你查看到app这个版本库的大小为100GB,那么按照我的迁移五六十个版本的经验来讲,这个版本库全量生成的dump文件至少有700GB。如果你确保你的windows可以腾出一个T的空间来存放这个的话你可以一次性生成,当然我这边没有这种条件,我这边的操作是上面博客提到的增量备份的方式
第二步:在windows中找到原始的SVN版本库的文件夹-进去db文件夹-找到current文件-用记事本或者其他编辑器打开查看的当前的版本号
增量备份就需要这个版本号信息: 再举个梨子:如果你看到app这个版本库的版本号是106425,并且你磁盘只有300GB的空间来操作,那就可以以一万个版本号作为一个增量包: 我这边的实际操作过程:(只用app来打包实例)
1、打开dos命令窗口,在windows中制作dump包:
svnadmin dump E:\Repositories\app -r 0:10000 > F:\app0-10000.dump(第一个包)
制作好的dump包及时转移到linux,腾出足够的空间给后续的文件(你可以启动多个dos窗口,将下面的命令同时执行,但是你得确保你的磁盘空间足够)
svnadmin dump E:\Repositories\app -r 10001:20000 --incremental > F:\app0-10000.dump(第二个包注意多个--incremental)
......
svnadmin dump E:\Repositories\app -r 100001:106425 --incremental > F:\app0-10000.dump(最后一个包)
2、将制作好的dump文件转移至linux并还原到对应的版本库
实际操作: 我通过xshell将dump文件上传至linux服务器的 /home/svndata/dump文件夹(这个传输时间完全看你的网速带宽,建议和公司网关沟通下)
将第一个dump包的数据还原:
svnadmin load /home/svndata/svn/app < /home/svndata/dump/app0-10000.dump
这个过程也只能让它慢慢跑完,不能中断,并且只能按照版本号的顺序依次还原数据(别问,我试过)
将第二个dump包的数据还原:
svnadmin load /home/svndata/svn/app < /home/svndata/dump/app10001-20000.dump
......
拉取测试:这个时候的拉取地址应该是svn://IP:/项目名称
举个粒子:如果你的linux的ip是192.168.1.29
此时在小乌龟(TortoiseSVN)上的拉取地址应该是:svn://192.168.1.29/app
3、补充
这个打包过程不影响现在的windows的svn的正常服务,所以只需要在制作最后的dump文件时停止服务以防止用户不断提交数据
3、svn配置http
这边我主要参考黎陌MLing大佬的博客:(建议先看完大佬博客,然后看完我的小tips,再操作!)
这里面没有什么注意点,跟着照做就行,我就给出我操作过程中某些实际命令,以便读者对照之前的目录结构:
1.修改仓库拥有者
将SVN目录下的所有版本库改为apache用户 chown -R apache:apache /home/svndata/svn
2.开启读写权限
chmod -R o+rw /home/svndata/svn
chcon -R -t httpd_sys_content_t /home/svndata/svn
chcon -R -t httpd_sys_rw_content_t /home/svndata/svn
3.配置htpasswd的密码
创建用户xiaoming:
如果你没有这个文件:/home/svndata/svn/htpasswd
应该用的命令是:
htpasswd -c -m /home/svndata/svn/htpasswd xiaoming
但是你前面如果是照着做的:
你应该先把之前的htpasswd文件的信息备份并清空
然后使用命令:(修改xiaoming的密码的指令也是这个)
htpasswd -m /home/svndata/svn/htpasswd xiaoming
实际的生成后的htpasswd密码文件像这样:
用户添加完后,需要在/home/svndata/svn/authz文件里对这个用户授权
例如给xiaoming版本库AHYCsvn的读写权限:
4.添加subversion.conf 文件内容
我这边添加后的内容:(相关的讲解请参考原作者)
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<Location /svn >
DAV svn
SVNListParentPath on
SVNParentPath /home/svndata/svn
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /home/svndata/svn/htpasswd
AuthzSVNAccessFile /home/svndata/svn/authz
Satisfy all
Require valid-user
SVNAutoversioning on
ModMimeUsePathInfo on
</Location>
如果你前面的步骤和我的一样,那下面的内容是不需要修改的:
其他的照做即可
5.拉取测试
此时在小乌龟(TortoiseSVN)上的拉取地址应该是:http://192.168.1.29/svn/app
4、svn配置https
1.正常方式:
这边我主要参考黎陌MLing大佬的博客:(这里建议完全照着做;如果你的业务场景也是仅内网使用,并且你按照正常方式一直失败,可以参考非常规操作的内容)
我因为不懂数字证书的生成的具体参数,所以请教的我公司的网管(后面他告诉我,这个可以随便填写)
也就是下面输入的国家、省、市、公司、域名等信息:
2.非常规操作:
(如果你尝试了多次还是不行的话,我这边提供一种方案,但是我因为不懂其中的原理,所以不保证其安全性)因为我们网管也是在无意的情况的情况下,发现svn程序可以正常拉取.
过程是这样的:我和我公司网关按照步骤执行到下面这步:
也不知道是证书没生成对还是什么原因,后续的https的拉取老是失败,所以我们将文件删除后
从这个步骤开始又尝试了几次,也还是失败了。后面发现(好像)安装SSL模块时默认生成/etc/httpd/conf.d/ssl.conf中也指定了默认的证书文件,如下所示(这是我本地的ssl.conf文件):
Listen 443 https
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
<VirtualHost _default_:443>
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
请关注这两行:
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
这也是默认的证书文件的路径,(当然你如果有正经的安全的证书文件,请替换掉上面的路径)
我这边图方便就使用了默认的证书文件(因为只在我们内网中使用,不映射到公网,所以无太多所谓)
下面再附上/etc/httpd/conf/httpd.conf的内容:
ServerRoot "/etc/httpd"
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
SSLRequireSSL
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
3.拉取测试:
此时在小乌龟(TortoiseSVN)上的拉取地址应该是:https://192.168.1.29/svn/app
四、后续计划:
1:补充SVN中新建额外的映射地址的内容
2:SVN常见问题和功能使用
五、声明:
第一次写博客,关于文章的排版、格式以及内容的正确性都欢迎大佬们不吝赐教