阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下使用Apache搭建Git服务器

169次阅读
没有评论

共计 2569 个字符,预计需要花费 7 分钟才能阅读完成。

最近在学 Linux,终于在 Linux 上用 Apache 搭建起了 Git 服务器,在此记录一下。

服务器:阿里云 服务器

Linux 版本:CentOS 6.5

Apache 版本:Apache/2.2.15

Git 版本:git 1.7.1

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 的文件夹,比如这里是 /home/git

cd /home && mkdir git && cd git

4. 创建一个空的项目

mkdir git-test && cd git-test

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

chown -R apache:apache .

Apache 的配置

1. 创建用于 git 用户验证的帐户(用户帐户由 apache 管理)

1.1 创建新用户

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

然后输入该用户要使用的密码。

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

Linux 权限设置 chmod  http://www.linuxidc.com/Linux/2016-12/138322.htm

Linux 命令 chmod 学习笔记 http://www.linuxidc.com/Linux/2016-11/136810.htm

Linux 基础教程:chmod 命令改变文件 / 文件夹属性  http://www.linuxidc.com/Linux/2016-09/135405.htm

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 /home/git
        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://git.cnblogs.com/git/git-test

输入用户名与密码,如果输出下面的信息,就说明签出成功。

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.

Git 教程系列文章

GitHub 使用教程图文详解  http://www.linuxidc.com/Linux/2014-09/106230.htm 

Git 使用图文详细教程  http://www.linuxidc.com/Linux/2016-11/136781.htm

Ubuntu Git 安装与使用 http://www.linuxidc.com/Linux/2016-11/136769.htm

Git 标签管理详解 http://www.linuxidc.com/Linux/2014-09/106231.htm 

Git 分支管理详解 http://www.linuxidc.com/Linux/2014-09/106232.htm 

Git 远程仓库详解 http://www.linuxidc.com/Linux/2014-09/106233.htm 

Git 本地仓库(Repository)详解 http://www.linuxidc.com/Linux/2014-09/106234.htm 

Git 服务器搭建与客户端安装  http://www.linuxidc.com/Linux/2014-05/101830.htm 

Git 概述 http://www.linuxidc.com/Linux/2014-05/101829.htm 

分享实用的GitHub 使用教程 http://www.linuxidc.com/Linux/2014-04/100556.htm 

Git 从入门到学会 http://www.linuxidc.com/Linux/2016-10/135872.htm

Git 基本操作详解 http://www.linuxidc.com/Linux/2016-10/135691.htm

Git 的详细介绍:请点这里
Git 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-02/140950.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2569字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中