mercurial serverhtml
对于代码管理工具,更多的人可能更熟悉 Git 一些(Git 太火了)。其实另一款分布式代码管理工具也被普遍的使用,它就是 mercurial。多人协做时,最好可以经过建立一个 mercurial server 对用户进行权限认证,同时也会方便持续集成。python
关于建立 mercurial server 的步骤,mercurial 官方的 wiki 有说明,网上也有不少朋友分享了本身的建立过程。但笔者在建立的过程当中仍是颇费了一番周折才最终成功,因此也在此分享一下本身的经验,但愿对朋友们有所帮助。web
文章来源:葡萄城产品技术社区api
1、环境及软件安装浏览器
笔者使用的操做系统为 Server2012R2 x64 Standard 中文版。服务器
首先,在安装其余工具前,须要先安装 IIS。安装 IIS 时须要注意,必定要把 CGI 和 ISAPI 这两个选项都勾选上。架构
而后,安装 Python,使用默认设置安装 python 2.7.x。app
最后,安装 mercurial server,请从这里在这里下载 mercurial server 的安装包并安装,安装完成后检查 C:\Python27\Lib\site-packages\mercurial 目录是否被正确安装!分布式
注意,python 和 sercurial server 必须保持相同的架构,不要一个安装 x86 另外一个安装 x64。工具
2、设置 IIS 服务器支持 python 模块
在 IIS 管理器中选择 IIS server,双击”ISAPI 和 CGI 限制”,添加一项新的扩展:
喜欢使用命令行的同窗也能够经过一行命令直接搞定:
C:\Windows\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /+"[path='C:\Python27\python.exe -u %22%s%22',description='Python',allowed='True']"
3、建立网站
在 IIS 中建立一个新的网站,端口绑定81(80端口已被默认网站占用)。在网站的根目录中添加 web.config 文件,web.config 文件的内容为:
[html] view plain copy
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="Python" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Python27\python.exe -u "%s"" resourceType="Unspecified" requireAccess="Script" /> </handlers> </system.webServer> </configuration>
须要注意文件中 python.exe 的路径,请根据本身机器上的安装目录进行配置。
网站的基本设置已经完成,下面写个简单的测试文件检查一下网站可否正常工做。
在网站的根目录下建立 test.cgi 文件,文件内容以下:
print 'Status: 200 OK' print 'Content-Type: text/html' print print '<html><body><h1>Hello world!</h1></body></html>'
在浏览器中访问 http://localhost:81/test.cgi,若是看不到”Hello world!”,请检查前面的步骤是否执行正确。
4、配置 mercurial server
1. 在网站的根目录下添加 hgweb.config 文件,内容以下:
[collections] C:\repos = C:\repos [web] push_ssl = false allow_push = *
2. 在网站的根目录下添加 hgweb.cgi 文件,内容以下:
#!/usr/bin/env python # Path to repo or hgweb config to serve (see 'hg help hgweb') config = "xxxxx\hgweb.config" from mercurial import demandimport; demandimport.enable() from mercurial.hgweb import hgweb, wsgicgi application = hgweb(config) wsgicgi.launch(application)
注意,请按实际状况配置 config 的路径。
这就 OK 了,让咱们在 c:\repos 目录下初始化一个库而后访问 http://localhost:81/hgweb.cgi 看看:
5、配置 URL 重定向
每次都要在 URL 中输入 /hgweb.cgi,一来不方便,二来总感受怪怪的。能不能输入 http://localhost:81 就能够正常访问呢?固然能够,只需添加一个重定向的配置就能够了。
首先,须要下载并安装IIS的插件:http://www.iis.net/downloads/microsoft/url-rewrite
而后,在 web.config 文件中添加 rewrite 元素,新的 web.config 文件内容为:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="Python" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Python27\python.exe -u "%s"" resourceType="Unspecified" requireAccess="Script" /> </handlers> <rewrite> <rules> <rule name="rewrite to hgwebdir" patternSyntax="Wildcard"> <match url="*" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="hgweb.cgi/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
好了,如今访问下 http://localhost:81 试试,和访问 http://localhost:81/hgweb.cgi 是同样的。
6、设置匿名访问权限
默认状况下咱们已经可使用匿名权限从服务器克隆库并进行操做了,可是当你执行 hg push 命令时会收到一个 HTTP Error 502: Bad Gateway 的错误。出现这个错误,是由于匿名用户没有修改服务器上文件的权限,因此咱们须要给匿名身份验证设置一个有修改文件权限的用户。
如今就能够正常执行 push 操做了。
总结,相比其余工具的一键式安装与配置,mercurial server 的安装和配置稍显复杂。咱们这里只是配置了最简单的匿名访问,并不支持 ssl,不过这在局域网中基本也够用了。