安装和建立版本库

1
2
3
4
5
6
7
8
9
10
11
12
sudo yum install httpd httpd-devel subversion mod_dav_svn mod_auth_mysql

# 假设以 /var/svn 作为版本库根目录
cd /var/svn

# 新建名为 stuff 的版本库
svnadmin create stuff
chown -R apache.apache stuff
chcon -R -t httpd_sys_content_t stuff

# killall -9 svnserve
svnserve -d -r /var/svn/

新建名为 fang 的用户,文件位置 /var/svn/passwd

1
htpasswd -cm /var/svn/passwd fang

新建 /var/svn/authz 文件,将用户权限加上

1
2
3
4
5
6
7
[aliases]
###
[groups]
###

[/]
fang = rw

修改 /etc/httpd/conf.d/subversion.conf

1
2
3
4
5
6
7
8
9
10
11
<Location /svn>
DAV svn
SVNParentPath /var/svn

AuthType Basic
AuthName "Hello!"
AuthUserFile /var/svn/passwd
AuthzSVNAccessFile /var/svn/authz
Require valid-user
# SSLRequireSSL
</Location>

其中 SSLRequireSSL,意味着需要https加密访问
重启apache,访问 http://ip/svn/stuff/ 即可

HTTPS服务

安装软件包

1
sudo yum install mod_ssl openssl

申请证书

cd /etc/pki/tls/private
openssl genrsa -out ca.key 1024
openssl req -new -key ca.key -out ca.csr 
cd /etc/pki/tls/certs
openssl x509 -req -days 365 -in /etc/pki/tls/private/ca.csr -signkey /etc/pki/tls/private/ca.key -out ca.crt

修改 /etc/httpd/conf.d/ssl.conf 替换真实路径

SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key

修改 /etc/httpd/conf/httpd.conf,最后面加入下列代码

NameVirtualHost *:443
<VirtualHost *:443>
   SSLEngine on
   SSLCertificateFile /etc/pki/tls/certs/ca.crt
   SSLCertificateKeyFile /etc/pki/tls/private/ca.key
   <Directory /var/svn>
      AllowOverride All
   </Directory>
   DocumentRoot /var/svn
   ServerName H0STNAME
</VirtualHost>

重启apache,访问 https://H0STNAME/svn/stuff/ 即可