Ubuntu 12.04 64位上搭建svn服务器
前情提要:福无双至,祸不单行。这句话映射到程序员身上就是不但笔记本电脑进厂了,而且连电脑上近一个月写的代码也丢了。欲哭无泪之际,开始思量着给自己的代码找个安身之所。说起鄙人那堆可怜的代码。最开始的时候,是在台式机上装了本地的SVN服务器。代码不出门,全在家里住。那会毕业不久,写的东西少也不怎么实用。也没有代码库的概念。后来积累的东西多了,遇到的很多问题都属于重复编码。家里的代码库连不上网,那拷硬盘放着呗。老板看你整天用硬盘不爽不说,代码不同步搞到千疮百孔。再后来开始用git了。用着还不错,就是私有化项目这一块没弄,也没敢全往上面传。直到上星期笔记本挂了,丢了几份代码。思来想去,还是得自己开个代码仓库。存到服务器上提交方便,也多份保障吧。
1.1 sudoapt-get install apache2
安装apache2。如果你已经装了nginx的话。先将nginx停掉。他使用的80端口和后面安装的apache2会冲突。如:/etc/init.d/nginx stop。
安装完之后,如无意外会出现如下报错:
[html] view plain copy
1. apache2: Could not reliably determinethe server's fully qualified domain name, using 127.0.0.1 for ServerName
在/etc/apache2/httpd.conf(此文件此时为空,是正常的)中增加下面一行:
[html] view plain copy
1. ServerName 127.0.0.1:80
重启apache2 ,执行 /etc/init.d/apache2restart。出现如下字段表示重启成功。
[html] view plain copy
1. root@xxxxx:/etc/apache2#/etc/init.d/apache2 restart
2. * Restarting web server apache2
3. ... waiting ...done.
1.2 sudoapt-get install subversion
安装subversion。略过。
1.3 sudoapt-get install libapache2-svn
安装连接插件。略过。
执行下面命令:
[html] view plain copy
1. sudo addgroup subversion
2. sudo usermod -G subversion -a www-data
查看结果:
[html] view plain copy
1. cat /etc/group|grep subversion
2. subversion:x:1001:www-data
2.2 Apache2挂载SVN模块(通过http://访问)
通过 WebDAV 协议访问SVN 文件仓库,必须在/etc/apache2/mods-available/dav_svn.conf中加入下面的代码片段:
[html] view plain copy
1. <Location /svn/>
2. DAV svn
3. SVNParentPath /home/svn
4. SVNListParentPath On
5. AuthType Basic
6. AuthName "Subversion Repository"
7. AuthUserFile /home/svn/conf/dav_svn.passwd
8. AuthzSVNAccessFile /home/svn/conf/dav_svn.authz
9. Require valid-user
10. </Location>
11. RedirectMatch^(/svn)$ $1/
新建/home/svn/conf目录。为用户设置密码,会以加密方式保存(-c 是新建的意思,去掉就是追加)。后面会提示你输入对应密码的。
[html] view plain copy
1. htpasswd -c /home/svn/conf/dav_svn.passwd user_1
2. htpasswd /home/svn/conf/dav_svn.passwd user_2
新建dav_svn.authz 文件,加入如下代码。
[html] view plain copy
1. [groups]
2. admin=user_1
3. user=user_2
4. [/]
5. @admin = rw
6. @user = r
重启apache2。/etc/init.d/apache2 restart
如无意外会出现如下报错
[html] view plain copy
1. Syntax error on line 65 of/etc/apache2/mods-enabled/dav_svn.conf:
2. Invalid command'AuthzSVNAccessFile', perhaps misspelled or defined by a module not included inthe server configuration
3. Action 'configtest' failed.
4. The Apache error log mayhave more information.
5. ...fail!
原因是没有载入模块。在/etc/apache2/mods-available/dav_svn.load加入下面代码。
[html] view plain copy
1. LoadModule authz_svn_module/usr/lib/apache2/modules/mod_authz_svn.so
再执行重启/etc/init.d/apache2restart就正常了。
修改后如下:
12. LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so
13. LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so
14. <Location /svn>
15. DAV svn
16. SVNParentPath /home/svn
17. SVNListParentPath On
18. AuthType Basic
19. AuthName "Subversion Repository"
20. AuthUserFile /home/svn/conf/dav_svn.passwd
21. AuthzSVNAccessFile /home/svn/conf/dav_svn.authz
22. Require valid-user
23. </Location>
在/home/svn/目录下新建test目录:mkdir test。
[html] view plain copy
1. sudo chown -R root:subversion test
2. sudo svnadmin create /home/svn/test
目录授权
[html] view plain copy
1. sudo chmod -R g+rws test
执行查看命令ls test 会发现下面出现如下文件。表示仓库已建好。
[html] view plain copy
1. conf db format hooks locks README.txt
重启SVN服务器:killall svnserve; svnserve -d -r/home/svn/
重启apache2服务器:/etc/init.d/apache2 restart
在浏览器打开http://localhost/svn/test。输入用户密码就能看到目录结构了。
后记:
很大机会你会遇到403禁止访问页面。网上有很多解决方法。
如我主要参考的是:http://blog.youkuaiyun.com/Ivy_yayaxueyu/article/details/1779653。
You don't have permission to access /svn/ on this server.
Apache/2.2.22 (Ubuntu) Server at 127.0.0.1 Port80
但都不是我遇到的。我应该是被官方文档给坑了。
当时是按照官方的配置来配/etc/apache2/mods-available/dav_svn.conf文件如下。但是就是因为加上了<LimitExcept GET PROPFIND OPTIONS REPORT></LimitExcept>一直报403。去掉就好了。后来看了一下说明应该还要加一个模块才能实现module(enable it with 'a2enmod')。我就不加了,直接去掉。详细的可以参考IBM的官方文档:http://www.ibm.com/developerworks/cn/java/j-lo-apache-subversion/。
[html] view plain copy
1. <Location /svn/>
2. DAV svn
3. SVNParentPath /home/svn
4. SVNListParentPath On
5. AuthType Basic
6. AuthName "Subversion Repository"
7. AuthUserFile /home/svn/conf/dav_svn.passwd
8. AuthzSVNAccessFile /home/svn/conf/dav_svn.authz
9. <LimitExcept GET PROPFIND OPTIONS REPORT>
10. Require valid-user
11. </LimitExcept>
12. </Location>
如果出现报错
[html] view plain copy
1. Can’t open‘/home/svn/test/txn-current-lock’:Permissiondenied
那就重新给他设置一下权限吧。
[html] view plain copy
1. sudo chown -R root:subversion test
Linux下SVN创建新的项目
Linux环境下的SVN创建新的项目
一、前置条件:
1)有安装了linux系统的服务器,123.*.*.29
2)服务器上安装了svn,本人服务器的svn的数据安装的目录地址:/application/svndata
二、创建新的svn项目:
1)进入到linux服务器。可以是root的的目录下
2)创建仓库的命令:svnadmin create /application/svndata/iReportTest (本次建立的项目名称为iReportTest,为了练习iReport+JasperReport生成表报用);
3)进入到新的项目的conf目录下:cd /application/svndata/iReportTest/conf
4)修改passwd文件:(添加用户名)vi passwd
[users]
# harry = harryssecret
# sally = sallyssecret
chenjie = Chenjie
5)修改svnserve.conf 文件;(修改配置文件)vi svnserve.conf
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
6) 修改authz 文件;(修改配置文件)vi authz
[groups]
test = zzk
[/]
@test = rw
7)停止svn
killall svnserve
8)启动svn项目
svnserve -d -r /application/svndata/
9)测试是否创建成功
svn co svn://123.*.*.29/iReportTest