在Apache项目中设置源代码控制系统(如SVN或Git)是确保代码管理和协作的关键步骤

在Apache项目中设置源代码控制系统(如SVN或Git)是确保代码管理和协作的关键步骤。以下是详细的设置指南:

1. 安装必要的软件

  • Subversion (SVN): 用于版本控制和协作开发。
  • Git: 一个分布式版本控制系统,适用于快速、灵活的开发流程。
安装SVN
# 对于Debian/Ubuntu系统
sudo apt-get update
sudo apt-get install subversion

# 对于RedHat/CentOS系统
sudo yum install subversion
安装Git
# 对于Debian/Ubuntu系统
sudo apt-get update
sudo apt-get install git

# 对于RedHat/CentOS系统
sudo yum install git

2. 配置用户权限

为了确保只有授权用户可以访问和修改代码库,需要配置用户权限。

创建用户组和用户
# 创建用户组
sudo groupadd devgroup

# 添加用户到用户组
sudo usermod -aG devgroup username
设置目录权限

假设你的代码库位于/var/svn目录下:

# 创建目录并设置权限
sudo mkdir /var/svn
sudo chown -R :devgroup /var/svn
sudo chmod -R 775 /var/svn

3. 初始化仓库

初始化SVN仓库
# 进入仓库目录
cd /var/svn

# 创建仓库
sudo svnadmin create myproject

# 设定访问权限
sudo chown -R :devgroup myproject
初始化Git仓库
# 进入仓库目录
cd /var/svn

# 创建空的Git仓库
sudo git init --bare myproject.git

# 设定访问权限
sudo chown -R :devgroup myproject.git

4. 配置Web服务器(可选)

如果你希望通过Web界面访问代码库,可以配置Apache或其他Web服务器。

配置Apache以支持SVN

编辑Apache配置文件(例如/etc/apache2/apache2.conf):

<Location /svn>
    DAV svn
    SVNParentPath /var/svn
    AuthType Basic
    AuthName "Subversion Repository"
    AuthUserFile /etc/apache2/dav_svn.passwd
    Require valid-user
</Location>

然后启用相关模块并重启Apache:

sudo a2enmod dav_svn
sudo systemctl restart apache2
配置Apache以支持Git

使用gitweb来浏览Git仓库:

# 安装gitweb
sudo apt-get install gitweb

# 配置Apache以支持gitweb
<Location /git>
    SetHandler cgi-script
    Options +ExecCGI
    DirectoryIndex index.cgi
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/gitweb.cgi
    Require all granted
</Location>

然后重启Apache:

sudo systemctl restart apache2

5. 测试访问

确保你可以通过浏览器或命令行工具访问代码库。例如,使用SVN客户端工具检查仓库内容:

svn list http://yourserver/svn/myproject

或者使用Git客户端工具克隆仓库:

git clone http://yourserver/svn/myproject.git

如何在 Apache 设置 SVN 进行源码控制

安装必要的组件

为了使 SVN 和 Apache 协同工作,在 CentOS 7 上需要安装 httpd (Apache HTTP Server) 和 Subversion 的两个动态库支持,以及用于密码验证的支持。这可以通过命令行完成:

yum install httpd mod_dav_svn subversion

上述命令会安装 Apache Web 服务器及其与 SVN 结合所需的模块。

配置 Apache 支持 SVN

配置文件位于 /etc/httpd/conf.modules.d/10-subversion.conf 中,通过编辑此文件确保启用了 DAV_SVN 模块并设置了正确的路径指向 SVN 存储库的位置。通常情况下,默认配置已经足够启动基本功能。

对于更详细的设置,可以在该文件内添加如下内容来指定特定仓库位置和服务选项:

<Location /svn>
    DAV svn
    SVNParentPath /var/www/svn
    AuthType Basic
    AuthName "Subversion Repository"
    AuthUserFile /etc/svn-auth-users
    Require valid-user
</Location>

这段配置定义了一个名为 /svn 的 URL 路径访问所有存放在 /var/www/svn 下面的项目,并且开启了基于用户名和密码的身份认证机制。

创建新的 SVN 库

创建一个新的版本库目录结构之后,使用 svnadmin create 命令初始化它:

mkdir -p /var/www/svn/myproject
svnadmin create /var/www/svn/myproject

这样就建立起了一个可供使用的 SVN 仓库实例。

添加用户账号

利用 htpasswd 工具可以方便地向已有的用户列表中加入新成员。首次运行时需加上 -c 参数表示创建新文件;后续只需提供用户名即可更新现有文件中的条目。

htpasswd -cm /etc/svn-auth-users user1
htpasswd -m /etc/svn-auth-users user2

这些指令分别用来创建第一个用户 (user1) 并加密其口令保存至 /etc/svn-auth-users 文件里,接着再追加第二个用户 (user2) 到同一文件中。


Source Code Repositories
Git Repository Use At Apache
Web Access - Subversion Repositories
Anonymous Subversion Client Access
Committer Subversion Access
Configuring the Subversion client
Subversion SSL Server certificate
Problems with Subversion?
“Error validating server certificate” errors
“svn: No such revision 765287” errors
“specified baseline is not the latest baseline” errors
“Compressed stream invalid” errors
Problems using date revisions
Frequently Asked Questions
When Do I Need To Use svn lock?
How frequently can I run a cron that connects to the repository?
How do I mirror the entire SVN repository for my experimental $foo?
Why Do I Get a 403 When I Try To Commit?
SOURCE CODE REPOSITORIES
Apache project contributors are located all around the world. To enable them to work together on our software, we keep the source code in an Internet-accessible revision control system - either Subversion (SVN) or in Git. Apache committers have write access to the repository for their projects, enabling them to make changes to the source code. Everyone has read access to the repositories, so you may download the most up-to-date development version of the software. If you are looking for a stable release of the source code, you should download it from the distribution directory. The Subversion or Git repository for your project should only be used if you want to be on the bleeding-edge of the development effort. The code contained in them may fail to work, or it may even eat your hard drive. There are several ways to access the Apache project repositories:

GIT REPOSITORY USE AT APACHE
How-To, documentation, and the list of projects using git for revision control are at https://git.apache.org/.

WEB ACCESS - SUBVERSION REPOSITORIES
If you just wish to browse around or download a few individual files, the best tool is the web-based ViewVC interface for Subversion or go straight to the public repository at http://svn.apache.org/repos/asf/.

ANONYMOUS SUBVERSION CLIENT ACCESS
To access the Subversion repository anonymously, you will need a Subversion client. You can also browse for projects via http://svn.apache.org/repos/asf/.

Choose the module you would like and check it out. For example, to get the Spamassassin module, use:

$ svn checkout http://svn.apache.org/repos/asf/spamassassin/trunk spamassassin
For more help on using Subversion, consult the Subversion website or Subversion book. The web site provides a list of clients and useful links (including a link to the Eclipse plug-in ).

COMMITTER SUBVERSION ACCESS
We currently use HTTPS basic authentication for logging in to Subversion ( certificate info below ). To change your password, visit https://id.apache.org/.

Now, when you make changes, you can commit them with your username/password combination, i.e.

$ svn co https://svn.apache.org/repos/asf/excalibur/trunk/ excalibur-trunk
$ cd excalibur-trunk
$ echo “test” > test.txt
$ svn add test.txt
$ svn commit --username your-name --password your-password
–message “Trying out svn”
svnserve is not supported, nor is svn+ssh.

CONFIGURING THE SUBVERSION CLIENT
Committers will need to properly configure their svn client. One particular issue is OS-specific line-endings for text files. When you add a new text file, especially when applying patches from Bugzilla, first ensure that the line-endings are appropriate for your system, then do… svn add test.txt svn propset svn:eol-style native test.txt Your svn client can be configured to do that automatically for some common file types. Add the contents of the file http://www.apache.org/dev/svn-eol-style.txt to the bottom of your ~/.subversion/config file, normally found at:

Windows: C:\Documents and Settings{username}\Application Data\Subversion\config
Windows 7: C:\Users{username}\AppData\Roaming\Subversion\config]
Linux & Mac OSX: ~/.subversion/config or /etc/subversion/config
Some files may need additional properties to be set, for example svn:executable=* should be applied to those script files (e.g…bat,.cgi,.cmd,.sh) that are intended to be executed. Since not all such files are necessarily intended to be executed, the executable property should not be made an automatic default.

However, you should still pay attention to the messages from your svn client when you do ‘svn commit’.

Tip: If you use TortoiseSVN, a popular Windows GUI client that integrates with Windows Explorer, you can simply right click in Explorer and select TortoiseSVN - Settings, and then press the “Edit” button to update your “Subversion configuration file:”. Simply copy the above svn-eol-style.txt file’s contents into the end of the config editor (usually Notepad) that appears, and save the file.

SUBVERSION SSL SERVER CERTIFICATE
The server certificate for https://svn.apache.org/ is a real SSL certificate. However, Subversion, by default, does not currently ship with a list of trusted CAs. So, here’s some information to help you verify the validity of our cert:

Hostname: *.apache.org
Valid: from Apr 20 00:00:00 2017 GMT until July 20 23:59:59 2019 GMT
Issuer: SSL.com
SHA-1 Fingerprint 2D:97:67:D9:2E:20:EE:07:3D:26:DA:97:A6:43:36:5F:71:8E:94:19
SHA-256 Fingerprint F1:57:0C:FB:84:67:51:20:59:FC:56:63:91:32:AE:CA:B6:6C:E6:93:56:C7:9A:98:54:8B:2D:C6:CA:BC:13:07
Note that the SSL certificate for our Subversion repository is different from certificates used when logging into Apache infrastructure - please see the New Committer guide for more information.

PROBLEMS WITH SUBVERSION?
“ERROR VALIDATING SERVER CERTIFICATE” ERRORS
Error validating server certificate for ‘https://svn.apache.org:443’:

  • The certificate is not issued by a trusted authority. Use the
    fingerprint to validate the certificate manually!
    Certificate information:
  • Hostname: *.apache.org
  • Valid: from Apr 20 00:00:00 2017 GMT until July 20 23:59:59 2019 GMT
  • Issuer: SSL.com
  • SHA-1 Fingerprint 2D:97:67:D9:2E:20:EE:07:3D:26:DA:97:A6:43:36:5F:71:8E:94:19
    ®eject, accept (t)emporarily or accept §ermanently?
    Note: SSL fingerprints (as above) for the SVN hosts are listed in the Machines List

“SVN: NO SUCH REVISION 765287” ERRORS
If you’re getting an error message like the following:

svn: No such revision 765287
This may be because of a short lag in the synchronization between Subversion mirrors, and can occur if multiple commits are run immediately after each other. This error will usually only happen if you are located in Europe, or explicitly using the European mirror.

Waiting for 10 seconds and repeating the command should succeed.

Note that this error can also occur when running ‘mvn release:prepare’ The mvn release plugin has a special property to handle this situation:

[http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#waitBeforeTagging] (http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#waitBeforeTagging)

“SPECIFIED BASELINE IS NOT THE LATEST BASELINE” ERRORS
If you’re getting an error message like the following:

svn: Commit failed (details follow):
svn: The specified baseline is not the latest baseline, so it may not be
checked out.
This may be because of a short lag in the synchronization between Subversion mirrors, and can occur if multiple commits are run immediately after each other. This error will usually only happen if you are located in Europe, or explicitly using the European mirror.

Waiting for 10 seconds and repeating the command should succeed.

“COMPRESSED STREAM INVALID” ERRORS
If you’re getting an error message like the following:

svn: PROPFIND of ‘/repos/asf/foobar’:
Compressed stream invalid (https://svn.apache.org)
That’s a known issue in the neon client library which has been fixed in neon 0.24.7. A workaround is to disable compression in your client. Edit ~/.subversion/servers. Uncomment the [global] section if neccessary, and add a line that reads

http-compression = no
And that should “fix” the problem until you can upgrade.

PROBLEMS USING DATE REVISIONS
If you are using a date revision such as -r{2004-09-12}:{2004-08-12} and not getting any or all of the revisions you expected, this is a known problem specific to the ASF repository.

Unfortunately, there is nothing that can be done to improve this situation, so you must use a workaround. You can use svn log or ViewVC to locate the actual revision number that is first after the date you desire, and substitute that into your -r argument to the svn command.

For example, consider the desired command:

$ svn diff -rHEAD:{2005-01-01}
When this produces no output, running svn log alone shows:

r124032 | aheritier | 2005-01-04 09:58:16 +1100 (Tue, 04 Jan 2005) | 1 line

Switch to subversion

r123911 | brett | 2005-01-03 09:48:57 +1100 (Mon, 03 Jan 2005) | 1 line

remove nagoya references

r116173 | brett | 2004-10-23 22:11:51 +1000 (Sat, 23 Oct 2004) | 2 lines

remove old requires descriptions

So, the comand above should become:

$ svn diff -rHEAD:123911
The particular reason this occurs is because the order of the revisions is not identical to the order of dates in the repository. This is a side effect of loading CVS repositories with history with dates prior to the latest date in the Subversion repository.

FREQUENTLY ASKED QUESTIONS
WHEN DO I NEED TO USE SVN LOCK?
Very rarely. Commits in subversion are transactional. This means that locks are almost always unnecessary.

An oft quoted use case is to prevent concurrent editing of a large unmergeable binary document. However, for open development, good communication is preferable to locking even in this use case. A good timely post to the list letting your fellow developers know that you’re going to start editing that huge PDF is better than locking the file.

HOW FREQUENTLY CAN I RUN A CRON THAT CONNECTS TO THE REPOSITORY?
Hourly is fine. Please do not use programs that poll the repository more frequently than hourly. People who run automated scripts that continuously poll the repository wind up getting their access denied, which may impact other folks connecting through the same host. If you need to stay more in-sync than an hourly cron allows, subscribe your script to the relevant commit mailing list.

HOW DO I MIRROR THE ENTIRE SVN REPOSITORY FOR MY EXPERIMENTAL $FOO?
First, ask yourself: do I really want the entire ASF repository? Generally most people really want only a single project. In that case, just checkout that source directory from the repo.

If you really do want the entire ASF repository, don’t use svnsync. Instead, start by looking here: http://svn-master.apache.org/dump/ Use that to bootstrap your repo.

WHY DO I GET A 403 WHEN I TRY TO COMMIT?
Run svn info and check that the URL starts with https://. If it starts with http://, run:

$ svn switch --relocate http://svn.apache.org https://svn.apache.org
If you still get 403 Forbidden errors, ask your PMC to double-check the authz file and LDAP/Unix group membership.
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值