OS : ( Debian6.0.1- 6.0.3) + apache2(2.2.16)+ HTTPS/SSL + Subversion(1.6.12)
需求 : 建立程式碼版本控制服務,使用 subversion
1. 安裝 svn
svn-server 套件
$ apt-get install subversion libapache2-svn apache2
svn-client 套件
$ apt-get install subversion-tools
2. 建立 svn 目錄(/home/svn/repository),配置目錄所有者(www-data)跟 權限
$ mkdir /home/svn
$ chown www-data:www-data -R /home/svn
$ chmod 770 -R /home/svn
3. 建立 svn 用戶 admin 密碼 /etc/apache2/dav_svn.passwd
$ /usr/bin/htpasswd -c /etc/apache2/dav_svn.passwd admin
New password:
Re-type new password:
Adding password for user admin
# 建立一般用戶的帳號 密碼
$ /usr/bin/htpasswd /etc/apache2/dav_svn.passwd fifi.chen
$ cat /etc/apache2/dav_svn.passwd
admin:OlOpE5W7gXLis
user1:W7zVH8zz13KgA
user2:qQ7eb81zSZ2.g
4. 建立 svn 目錄權限配置文件:/etc/apache2/dav_svn.authz
$ vim /etc/apache2/dav_svn.authz
[groups]
admin=admin
guest=user1,user2
#新建每一個版本庫都需要再設一各權限配置
[test1:/] # 版本庫 test1 權限配置
# *= # 默認禁止所有用戶訪問
@admin=rw # admin 組有 rw 權限
user1=r # 用戶 user1 有 r 權限
[test2:/] # 版本庫 test2 權限配置
@admin=rw # admin 組有 rw 權限
user2=r # 用戶 user2 有 r 權限
5. 修訂 /etc/apache2/mods-available/dav_svn.conf
建立 svn location,指定 svn 目錄,認證方式,認證信息;
指定 dav_svn.passwd 用戶密碼配置文件路徑;
指定 dav_svn.authz 目錄權限配置文件路徑。
$ cp /etc/apache2/mods-available/dav_svn.conf /etc/apache2/mods-available/dav_svn.conf.bak
$ vim /etc/apache2/mods-available/dav_svn.conf
<Location /svn>
DAV svn
SVNParentPath /home/svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
AuthzSVNAccessFile /etc/apache2/dav_svn.authz
Require valid-user
</Location>
6. 建立 svn 版本庫(test1、test2)
$ su www-data
$ svnadmin create /home/svn/test1
$ svnadmin create /home/svn/test2
7. 重新啟動 apache2
$ su root
$ /etc/init.d/apache2 restart
8. 打開瀏覽器,輸入 http://domain/svn/test1
9. SVN Clinet 端操作
Windows下, 使用 Tortoise 來存取 版本庫
[Tortoise]
Linux 下 , 使用 svn 存取 , checkout(co)/commit(ci)/update(up).
例如 svn co http://domain/svn/test1
匯入程式檔案
$ svn import /testtmp http://IP&Domain/svn/test1/tmp
打開 brwoser , 輸入 http://IP&Domain/svn/test1/
就可以看到剛剛匯入的 tmp
測試取出匯入檔案
$ cd /tmp/
$ mkdir checkout
$ cd checkout
$ svn co http://domain/svn/test1/tmp ( 在遠端server指令 )
or
$ svn co /home/svn/test1/tmp ( 在localhost指令 )
10. 建立用戶改為 sha 加密(htpasswd SHA 加密方法,參數:-s)
密碼文件默認加密方法:CRYPT encryption,密碼文件格式:用戶名:密碼
基於安全考慮,建議加密方法使用 SHA encryption:htpasswd -s 用戶名
$ sudo /usr/bin/htpasswd -s /etc/apache2/dav_svn.passwd 用戶名
11. 刪除 svn 用戶
$ sudo vim /etc/apache2/dav_svn.passwd查找指定用戶名:/用戶名
刪除用戶指定行:dd
保存退出::wq
12. 安装 SSL 設定
$ apt-get install openssl13. 創建 ssl 目錄,用于存放 ssl pem 証書文件
$ mkdir -p /etc/apache2/ssl
14. 創建 ssl 証書(svn.pem),保存到 ssl 目錄(/etc/apache2/ssl)
-days 365 証書有效時間一年,可依需求自行定義。
$ RANDFILE=/dev/random openssl req $@ -new -x509 -days 365 -nodes \
-out /etc/apache2/ssl/svn.pem \
-keyout /etc/apache2/ssl/svn.pem
15. 配置 ssl証書(svn.pem),包括國家,州(省),市,組織,姓名,E-mail地址
Generating a 1024 bit RSA private key
.......++++++
........++++++
writing new private key to '/etc/apache2/ssl/svn.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:GZ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Reistlin.com
Organizational Unit Name (eg, section) []:Reistlin.com
Common Name (eg, YOUR name) []:reistlin
Email Address []:admin@reistlin.com
16. 証書創建完成後,請配置証書的 root 權限設定(重要!)
$ chmod 600 /etc/apache2/ssl/svn.pem
17. 創建 apache2 svn ssl 設定
$ cp /etc/apache2/sites-available/default-ssl /etc/apache2/sites-available/svn
啟用 SSL Engine,並指定 /etc/apache2/ssl/svn.pem ssl-key存放的位置
並設定 apache2 日誌 svn_error.log 和 svn_access.log
$ vim /etc/apache2/sites-available/svn
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/svn.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/svn_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/svn_access.log combined
</VirtualHost>
18. apache2 svn ssl 配置(a2ensite),啟動 apache2 ssl mod(a2enmod)
$ cd /etc/apache2/sites-available
$ a2ensite svn
Enabling site svn.
Run '/etc/init.d/apache2 reload' to activate new configuration!
$ a2enmod ssl
Module ssl enabled
19. 配置完成,重新 apache2
$ /etc/init.d/apache2 restart
20. 完成
打開 brwoser , 輸入 https://IP&Domain/svn/test1/
參考來源:
Debian Linux Apache2 + SVN 配置
Debian Linux 架設 Subversion(SVN)
沒有留言:
張貼留言