在 Debian Lenny 下创建 Apache2 SSL 认证的多重..
时间:2010-08-04 来源:longbow0
(1) 对不同用户创建不同的 Subversion 仓库;
(2) 使用 Apache2 SSL 连接;
(3) 使用 Apache2 mod_auth_pgsql 认证;
(4) 为不同的仓库设置不同的用户权限。
2. 基本参数
OS | Debian Lenny |
IP | 192.168.1.100 |
SVN 目录 | /opt/svn |
SVN 仓库 |
/opt/svn/repo1 /opt/svn/repo2 |
SVN 用户 |
test1 test2 |
用于访问认证管理的 PostgreSQL 数据库 |
svn |
PostgreSQL 用户 |
svn |
说明:
以下操作中,
$ - 普通用户
# - root 用户
3. 安装 Debian 包
# apt-get install apache2 libapache2-mod-auth-pgsql libapache2-svn\ postgresql postgresql-contrib subversion cert-ssl |
4. PostgreSQL 数据库及设置
4.1 创建用户 Apache2 认证的数据库
(1) 创建数据库 svn 和用户
$ sudo su postgres
postgres $ createdb svn
CREATE DATABASE
postgres $ createuser svn
Shall the new role be a superuser? (y/n) n
Shall the new user be allowed to create databases? (y/n) n
Shall the new user be allowed to create more new users? (y/n) n CREATE USER |
(2) 导入加密脚本,以加密保存的密码
postgres $ psql -d svn < /usr/share/postgresql/8.3/contrib/pgcrypto.sql
SET
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION ... |
(3) 创建表
postgres $ psql -d svn svn =# |
-- user table |
(4)为用户 svn 设置密码
ALTER USER svn WITH ENCRYPTED PASSWORD '123456'; |
4.2 修改 PostgreSQL 服务器访问权限
编辑 /etc/postgresql/8.3/main/pg_hba.conf:
在
host all all 127.0.0.1 255.255.255.255 ident sameuser |
host svn svn 127.0.0.1 255.255.255.255 md5 |
然后重启 PostgreSQL 服务:
# /etc/init.d/postgresql-8.3 restart |
5. 创建 Subversion 仓库
# mkdir /opt/svn/
# svnadmin create /opt/svn/repo2 |
然后
# chown -R www-data:www-data /opt/svn |
6. 配置 Apache2 SSL
6.1 加载 SSL 模块
# a2ensite default-ssl |
6.2 创建站点 SSL 证书
# make-ssl-cert generate-default-snakeoil --force-overwrite |
7. 设置 Apache2 WebDAV
7.1 加载模块
# a2enmod dav |
7.2 设置 mod_auth_pgsql 认证
编辑文件 /etc/apache2/mods-available/dav_svn.conf
<Location /svn> |
7.3 在数据库 svn 中创建 Subversion 用户 test1 和 test2
$ sudo su postgres |
-- User 'test1', for 'repo1' |
7.4 设置 Subversion 访问目录控制文件 /etc/apache2/dav_svn.authz
其中仓库 repo1 只能由用户 test1 完全访问,其他用户无法访问;
仓库 repo2 可以被用户组 testgrp 里的用户只读,由用户 test2 完全访问。
[groups] |
8. 重启 Apache2 服务
仓库 repo1 和 repo2 可以分别从
- https://192.168.1.100/svn/repo1
- https://192.168.1.100/svn/repo2