最近,团队需要使用Centos6.5作为代码管理服务器,因此研究了一下部署的方法与流程,特整理如下。
以下的安装步骤中,全部采用root用户。
1.安装或者检查apache
确认apache2是否已经安装到系统中,如果没有,则按照如下步骤安装:
#yum install httpd
2.安装mercurial
由于centos的mercurial的版本比较旧,建议从mercurial服务器上取得较新版本的rpm文件进行安装。步骤如下:
# wget https://www.mercurial-scm.org/release/centos6/RPMS/x86_64/mercurial-3.5.2-0.x86_64.rpm
# yum install mercurial-3.5.2-0.x86_64.rpm
3.配置hg给apache用的cgi文件
# cd /var
# mkdir hg
# chown -R apache:apache hg
# cd hg
# cp /usr/share/doc/mercurial-3.5.2/hgweb.cgi .
# chmod a+x hgweb.cgi
# vi hgweb.cgi
# config = "/var/hg/hgweb.config"
4.配置hg web
#vi hgweb.config
[web]
style=gitweb
allow_push = *
push_ssl = false
[collections]
/var/hg/repos = /var/hg/repos
5.配置apache
#vi /etc/httpd/conf/httpd.conf
增加如下的内容
NameVirtualHost *:80
<VirtualHost *>
DocumentRoot /var/www/html
ErrorLog /var/log/httpd/hg.log
ScriptAlias /hg "/var/hg/hgweb.cgi"
<Location /hg>
AuthType Basic
AuthName "Mercurial"
AuthUserFile /var/hg/hgusers
Require valid-user
</Location>
</VirtualHost>
6.建立资源库集目录并设置访问权限
#cd /var/hg
#mkdir repos
#chown apache.apache repos
#htpasswd -mc hgusers admin
这是给这个库集设定访问用户admin,回车后输入密码。除了添加第一个用户时使用-mc参数外,添加后续用户用-m(建htpasswd用法)
7.编辑hgrc文件
#vi /etc/mercurial/hgrc
[web]
allow_push = *
push_ssl = false
8.建立测试库
由于使用root用户建立测试库,因此需要使用chown转为apache
#cd /var/hg/repos
#mkdir test
#cd test
#hg init
#cd ..
#chown -R apache:apache test
9.停止SELinux安全控制
永久
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
临时
# setenforce 0 #设置selinux为permissive模式(即关闭)
# setenforce 1 #设置selinux为enforcing模式(即开启)
9.重启apache服务器,并测试
#service httpd restart
从浏览器访问http://[your server]/hg/