Linux git服务器http方式搭建

Git访问方式:基于http的基本验证(非SSL)
Apache的安装
1. 安装Apache软件:yum install httpd
2. 设置Apache在服务器启动时运行:chkconfig --levels 235 httpd on
Git的安装与配置
1. 安装git

yum install git


2. 安装 git-core(为了使用git-http-backend——支持git的CGI程序,apache支持git就靠它)

yum install git-core


3. 创建存放git repository的文件夹,比如这里是/gitServer

mkdir gitServer && cd gitServer


4. 创建一个空的项目
cd gitServer
 git init --bare sample.git


5. 修改上一步创建的文件夹gitServer的所有者与所属群组,要让apache能读/写这个文件夹

chown -R apache:apache .


chown命令使用帮助: 每天一个linux命令(30): chown命令
Apache的配置
1. 创建用于git用户验证的帐户(用户帐户由apache管理)
1.1 创建新用户

htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>
示例  htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd zhangcheng


然后输入该用户要使用的密码。
1.2 修改git-team.htpasswd文件的所有者与所属群组

chown apache:apache /etc/httpd/conf.d/git-team.htpasswd


1.3 设置git-team.htpasswd文件的访问权限

chmod 640 /etc/httpd/conf.d/git-team.htpasswd


chmod命令使用帮助: 每天一个linux命令(27):linux chmod命令
2. 修改apache配置文件httpd.conf
2.1 用vim打开httpd.conf:vi /etc/httpd/conf/httpd.conf
2.2 将光标移至文件结尾:0G
2.3 添加如下的内容:



<VirtualHost *:80>
        ServerName git.cnblogs.com
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv GIT_PROJECT_ROOT /gitServer
        ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
        <Location />
                AuthType Basic
                AuthName "Git"
                AuthUserFile /etc/httpd/conf.d/git-team.htpasswd
                Require valid-user
        </Location>
</VirtualHost>




ServerName是git服务器的域名
/home/git是代码库存放的文件夹
ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend
AuthUserFile是验证用户帐户的文件
2.4 保存并退出:x
3. 重启apache使设置生效

service httpd restart


客户端访问Git服务器
运行以下命令签出git-test项目:

git clone http://<username>:<password>@git.cnblogs.com/git/sample.git[/code] 
示例 http://zhangcheng:dancheng51@192.168.8.200/git/sample.git
如果访问不到注意80端口是否开启
重启防火墙 service iptables restart
输入用户名与密码,如果输出下面的信息,就说明签出成功。

remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值