安装subversion https server, 并实现版本库的同步

发布于 2022-08-05 02:13:48 字数 9253 浏览 14 评论 1

一: 安装subversion https server

1. Install Apache
In the terminal type:

sudo apt-get install apache2 apache2.2-common apache2-utils

               
This installs the apache 2 server common modules and utilities
2. Install Subversion
In the terminal type:

sudo apt-get install subversion subversion-tools

               
3. Install Apache Subversion Modules
In the terminal :

sudo apt-get install libapache2-svn

               
4. Restart Apache
In the terminal type:

sudo apache2ctl restart

               
5. Enable SSL Apache Module
In the terminal type:

sudo a2enmod ssl

               
6. Enable Apache to listen to the correct port for ssl (443)
In the terminal type:

sudo gedit /etc/apache2/ports.conf

               
Add the line: Listen 443
Note: Actually we can ignore this step, Because port 443 is enabled by default in /etc/apache2/site-*/default. If your apache fails to start after subversion virtual host configuration, please comment port 443 line in ports.conf.
7. Create a certificate for SSL use.
Unfortunately apache is missing the tool (apache2-ssl-certificate) required to create the certificate but this can be easily downloaded from apache2-ssl.tar.gz , download this file and extract the package. There are two files ssleay.cnf and apache2-ssl-certificate. In the terminal navigate to the directory two files have been extracted and type:
sudo mkdir /etc/apache2/ssl
sudo cp ./ssleany.cnf  /etc/apache2/ssl/
sudo cp ./apache2-ssl-certificate /usr/sbin/

Now create your certificate with and follow the instructions

sudo apache2-ssl-certificate

Note: Ubuntu Feisty/Debian has a bug where the command apache2-ssl-certificate is missing. This is a well documented bug. Here is the file you need to download to overcome this defect to create a self signed certificate. After you download, follow the notes below to copy the downloaded files to the location where they are supposed to be present.
1.        Extract the package
2.        put ssleay.cnf to /usr/share/apache2/
3.        put apache2-ssl-certificate to /usr/sbin.
4.        Create /etc/apache2/ssl directory.
Now apache2-ssl-certificate script should work. Please follow this link if you want to know how to use it.
8. Create a Subversion repository

Here make a directory where you want to store one or more subversion repositories, in this example I’m using /srv/svn/repos/

sudo mkdir  /srv
sudo mkdir  /srv/svn
sudo mkdir  /srv/svn/repos

               
Now make the repository directory accessible to apache (www-data)

chown www-data:www-data /srv/svn/repos

               
Now we will make the first repository using the super user www-data

cd /srv/svn/repos
su -u www-data -s
svnadmin create projectname
We now have our first subversion repository remember when creating other repositories always use the su www-data to ensure apache can access the repository.
9. Creating the virtual host

Create the virtul host file for Apache

sudo cp /etc/apache2/sites-available/default  /etc/apache2/sites-available/svn.domain.com
sudo gedit  /etc/apache2/sites-available/svn.domain.com
Copy and paste the following code edit the domain name and repository path if different:

NameVirtualHost *:443
<VirtualHost *:443>
  ServerAdmin yourname@domain.com
  ServerName svn.domain.com
  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/apache.pem
  SSLProtocol all
  SSLCipherSuite HIGH:MEDIUM
  <Location />
    Order allow,deny
    Allow from all
    DAV svn
    SVNPath /srv/svn/repos/projectname
    AuthType Basic
    AuthName "domain.com Subversion Repository"
    AuthUserFile /etc/apache2/dav_svn.passwd
    Require valid-user
  </Location>
  ErrorLog /var/log/apache2/error.log

  # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
  LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>

               
If you have many projects that you will be using the repository change

SVNPath /srv/svn/repos/project

to

SVNParentPath /srv/svn/repos

10. Create user(s) to access subversion repository

sudo htpasswd -c /etc/apache2/dav_svn.passwd username

to add more users use -m (the -c creates a new file)

sudo htpasswd -m /etc/apache2/dav_svn.passwd username2

11. Restart Apache and test

sudo /etc/init.d/apache2 restart

Now test your repostory with https://svn.domain.com and enjoy, if I’ve missed steps out please let me know in the comments.

二: 装镜像服务器,安装方法同上,别忘了改apache虚拟主机配置中指向镜像版本库的路径。

三:在镜像服务器上设置同步

Introduction
You may need to backup your svn repos so that data is safe even if something happens to the main repos.There are many ways of doing it I did it using svnsync.
So this is what we will do.
•        We will create a mirror repo in some other system.
•        svnsync will synchronize the mirror repo with the main repo
•        and we set the hooks that no one else other than the synsync changes the mirror repo.
Create a mirror repo
Mirror repo is just another svn repo created by svnadmin create command
svnadmin create /var/svnmirror
Create a svn user
We create an svn user such that only that user can change the mirror repo. We can add user by editing svnserv.conf and the password file
on file /conf/svnserve.conf uncomment the following line
# Uncomment this line.
password-db = passwd
on file /conf/passwd add this code
syncuser = mypasswd

on file /conf/authz
[/]
* = r
svnsync = rw

Add the hooks
We need to add pre-revprop-change hook and start-commit hook so that only svnsync modifies the svn-mirror
Add the following code to file /hooks/pre-revprop-change
#!/bin/sh
USER="$3"
if [ "$USER" = "syncuser" ]; then exit 0; fi
echo "Only the syncuser user can change revprops" >&2
exit 1
Make the file executable
chmod +x /hooks/pre-revprop-change

Add the following code to file /hooks/start-commit
#!/bin/sh
USER="$2"
if [ "$USER" = "syncuser" ]; then exit 0; fi
echo "Only the syncuser user may commit new revisions" >&2
exit 1
Make the file executable
chmod +x /hooks/start-commit

Synchronize with the main repo
For synchronizing with the main repo first we initialize the svn sync by this resisters which all repos has to be synchronised with which all source repos
svnsync init <mirror> <source>
eg:
svnsync init file:///var/svnmirror http://www.iiitmk.ac.in/svn/projects/my-project
Next we do a synchronisation by the command
svnsync sync <mirror repo's url>
eq:svnsync sync file:///var/svnmirror

Cache certificate to www-data home folder:

Cp –rf /root/.subversion/ /var/www  #www-data home folder.
Cd /var/www
Chown –R www-data.www-data .subversion  
Registering it in the cron job
You can add svn sync to the cron job's so that it does it daily without any user intervention.
on the command line give the command
crontab -e
this will open an editor add this line to it
30 1 * * *  svnsync sync file:///var/svnmirror
So that the mirror gets synchronized at 1:30 daily.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2022-08-09 07:41:27

很好的,现在使用svn的要对于cvs的,google的code就是使用svn

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文