Ubuntu上建立Mercurial/hg中心服务器 Apache2+hg 修改

2013-11-07 00:00:00 by 【6yang】, 585 visits, 收藏 | 返回

操作基本都是用root,除非特别说明。

1。首先安装apache2和mercurial

  1. 安装Apache: sudo apt-get install apache2
  2. 安装mod_wsgi: sudo apt-get install libapache2-mod-wsgi
  3. 安装mercurialsudo apt-get install mercurial
  4. 查看ssh 是否安装好. 若未安装请先 sudo apt-get install openssh-server
  5. 配置 cd /etc/ssh/
  6. vim ssh_config  (修改RSA验证)
  7. RSAAuthentication yes
    PubkeyAuthentication yes
    PasswordAuthentication yes
     
  8. sudo /etc/init.d/ssh start (启动)
  9. ps ax  | grep sshd
  10.  
  11.  

2。配置hg给apache用的cgi文件

cd /var

mkdir hg

chown -R www-data:www-data hg

cd hg

cp /usr/share/doc/mercurial/examples/hgweb.cgi .

chmod a+x hgweb.cgi

vi hgweb.cgi

config = "/var/hg/hgweb.config"
 

3。配置hg web

vi hgweb.config

[collections]
/var/hg = /var/hg
[ui]
username = jack <jack@163.com>

 

4。配置apache

cd /etc/apache2/sites-available
vi default

在</VirtualHost>前面加入:

ScriptAlias /hg "/var/hg/hgweb.cgi"  #(脚本匿名)

<Location /hg/repos> #(绑定路径)
                AuthType Basic
                AuthName "Mercurial repositories"
                AuthUserFile /var/hg/repos/hgusers
                Require valid-user
</Location>

5。建立资源库集目录并设置访问权限

cd /var/hg

mkdir repos

chown www-data.www-data repos

cd repos
sudo chmod -R 777 ./repos (可以修改访问权限, 否则无法访问.)

htpasswd -mc hgusers admin (创建apache  访问密码)

这是给这个库集设定访问用户admin,回车后输入密码。除了添加第一个用户时使用-mc参数外,添加后续用户用-m(建htpasswd用法)

6。建立测试库

su - www-data

cd /var/hg/repos

mkdir test

cd test

hg init

7。允许http push

vi /etc/mercurial/hgrc

[web]
allow_push = *
push_ssl = false
#allow_read = ccy
[trusted] #限制访问对像
users = jack, hgrepos, dz, www-data
group = wheel

 

8。重启apache2并测试 (sudo /etc/init.d/apache2 restart)

http://192.168.27.131/hg/repos

应该就能看到我们刚建立的测试库repos/test。如有问题查看/var/log/apache2/error.log 

9。建立其它库集并设置不同权限

就是上面repos相关的翻版,上面建立的第一个库集repos,例如我www.linuxidc.com要再建立一个库集cmn:

在/etc/apache2/sites-available/default中加入:

<Location /hg/cmn>
                AuthType Basic
                AuthName "Mercurial repositories"
                AuthUserFile /var/hg/cmn/hgusers
                Require valid-user
</Location>

然后重复上面5,6,只是把repos改成cmn,重启apache。不同库集的权限由相应目录下面的hgusers文件决定。

9.a
关于客户端的配置

[paths]
default = http://192.168.21.131/hg/repos/
[auth]
default.prefix = http://192.168.21.131
default.username = jack
default.password = 123456
[ui]
username = jack<jack@163.com>

 

10。导入实际的代码

首先如上所示建立空的服务器存储路径并hg init,然后客户端本地实际代码所在目录也hg init,然后push到服务器地址即可。 

Note: 如果web中查看代码中文显示有问题,可以改一下hgweb的编码设置(改完别忘了重启apache):

To change the encoding of served content, you can either change the locale under which hgweb operates, or you can add the following to the hgweb.cgi script before lines which start with from mercurial import. For example:

import os

os.environ["HGENCODING"]="UTF-8"

分享到:
share

    图片原图

    loading

    loading