安装Git版本:git 2.10.0

Git访问方式:基于http的基本验证(非SSL)

1. 安装Apache软件:

[root@localhost ~]# yum install httpd

设置Apache在服务器启动时运行(centos7:systemctl enable httpd):

[root@localhost ~]# chkconfig --levels 235 httpd on

2. 安装依赖库:

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost ~]# yum install gcc perl-ExtUtils-MakeMaker

3. 卸载旧版git:

[root@localhost ~]# yum remove git

4. 安装git, 先进入需要安装git的目录、下载git、解压和编译安装:

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz
[root@localhost src]# tar -zvxf git-2.10.0.tar.gz
[root@localhost src]# cd git-2.10.0
[root@localhost git-2.10.0]# make prefix=/usr/local/git all
[root@localhost git-2.10.0]# make prefix=/usr/local/git install

5. 将git目录加入PATH:

[root@localhost git-2.10.0]# echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
[root@localhost git-2.10.0]# source /etc/bashrc

安装成功后就可以查看到git版本了:

[root@localhost git-2.10.0]# git --version
git version 2.10.0

6. 创建git仓库并初始化:

[root@localhost git-2.10.0]# mkdir -p /home/git/repositories/test.git
[root@localhost git-2.10.0]# cd /home/git/repositories/test.git
[root@localhost test.git]# git --bare init
Initialized empty Git repository in /home/git/repositories/test.git/

7. 给git仓库设置apache用户和用户组并设置权限:

[root@localhost test.git]# chown -R apache:apache /home/git/repositories/test.git

(如果已经执行6、7步,此处忽略!)一条命令建仓库,方便以后执行一步完成:

[root@localhost ~]# mkdir -p /home/git/repositories/ssm-master.git && cd /home/git/repositories/ssm-master.git && git --bare init && chown -R apache:apache /home/git/repositories

8.Apache的配置

创建新用户

[root@localhost test.git]# htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>

注意:以后再分配用户的时候,此命令为:

[root@localhost test.git]# htpasswd -m /etc/httpd/conf.d/git-team.htpasswd <username>

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

修改git-team.htpasswd文件的所有者与所属群组

[root@localhost test.git]# chown apache:apache /etc/httpd/conf.d/git-team.htpasswd

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

[root@localhost test.git]# chmod 640 /etc/httpd/conf.d/git-team.htpasswd

修改apache配置文件httpd.conf

[root@localhost test.git]# vi /etc/httpd/conf/httpd.conf

将光标移至文件结尾(Shift+g),添加如下的内容:

<VirtualHost *:80>
ServerName 127.0.0.1
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /home/git/repositories
ScriptAlias /git/ /usr/local/git/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服务器的域名或ip地址(填127.0.0.1)

/home/git/repositories是代码库存放的文件夹

ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend

AuthUserFile是验证用户帐户的文件

保存并退出

9.gitweb的安装和配置

(1).安装gitweb

[root@localhost test.git]# yum install gitweb

(2). 修改git.conf

[root@localhost test.git]# vi /etc/httpd/conf.d/git.conf

Centos6.8的配置:

Alias /gitweb /var/www/git

<Directory /var/www/git>
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex gitweb.cgi
Order allow,deny
Allow from all
</Directory>

Centos7.0的配置:

Alias /gitweb /usr/local/git/share/gitweb

<Directory /usr/local/git/share/gitweb>
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex gitweb.cgi
Order allow,deny
Allow from all
</Directory>

其中:/usr/local/git/share/gitweb为安装git时自带的gitweb,就配置它。查看此目录方法:

[root@iZbp1ap7v4yegqdgzrh7cuZ /]# ls -F $(dirname $(dirname $(git --html-path)))/gitweb
gitweb.cgi* static/
[root@iZbp1ap7v4yegqdgzrh7cuZ /]# echo $(dirname $(dirname $(git --html-path)))/gitweb
/usr/local/git/share/gitweb
[root@iZbp1ap7v4yegqdgzrh7cuZ /]#

(3). 修改gitweb.conf

[root@localhost test.git]# vi /etc/gitweb.conf

(Shift+g到末尾),添加的一些内容,这样:

# 版本库的根目录
our $projectroot = "/home/git/repositories"; # 设置克隆每个版本库的URL地址,一个版本库可以设置多个地址(逗号隔开)
#our @git_base_url_list= ("git://www.jsxfd.com/git"); # 菜单定制:tree view文件旁显示追溯(blame)链接
$feature{'blame'}{'default'} = [1];
$feature{'blame'}{'override'} = 1; # 菜单定制:tree添加快照(snapshot)下载链接
$feature{'snapshot'}{'default'} = ['zip', 'tgz'];
$feature{'snapshot'}{'override'} = 1;

重启apache使设置生效(centos7命令为:/bin/systemctl restart  httpd.service)

[root@localhost test.git]# service httpd restart

(4). 用浏览器访问gitweb: http://服务器ip地址或者域名/gitweb

附加:

clone地址为:

http://服务器ip地址/git/test.git

注意git代码库所在的文件夹不要配置到这个路径中,  /git/ 已经配置过转向到代码库。

这样每次pull、push都要输入用户名和密码。所以要设置用户名密码到http路径中,如:

http://用户名:密码@服务器ip地址/git/test.git

如果用户名是邮箱地址,需要把邮箱地址中的@改为 %40

http://xxx%40qq.com:密码@服务器ip地址/git/test.git

至于用户名是中文的话,直接去看看url编码。

以后如果想增加git项目,直接执行上面的第6、7步即可。

搞定!

Centos6.8/7.0搭建Git服务http访问方式的更多相关文章

  1. Windows平台搭建Git服务教程详解

    引言 软件企业的核心就是代码,如何确保代码的安全?如何在团队开发中协同工作?为解决这些问题,我们需要采用相应的管理工具来满足管理的需求.探长从最初的VSS.SVN.TFS到现在的Git存储一路走来,感 ...

  2. Centos6.8搭建Git服务(git版本可选)

    搭建Git服务器需要准备一台运行Linux的机器,本文以Centos6.8纯净版系统为例搭建自己的Git服务. 准备工作:以root用户登陆自己的Linux服务器. 第一步安装依赖库 [root@lo ...

  3. 用Gogs在Windows上搭建Git服务

    1.下载并安装Git,如有需求,请重启服务器让Path中的环境变量生效. 2.下载并安装Gogs,请注意,在Windows中部署时,请下载MiniWinService(mws)版本. 3.在Maria ...

  4. centos上搭建git服务--2

    在 Linux 下搭建 Git 服务器   环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.window ...

  5. gogs搭建git服务教程

    使用gogs搭建自己的git服务!!! 一.GIT服务器搭建方式 上一节课我们讲过GIT是一个分布式版本管理系统,既然是分布那么必定会涉及远程通信,那么GIT是采用什么协议进行远程通信的呢? git支 ...

  6. winodws系统搭建git服务--Tomcat--jdk配置

    一.http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html  下载jdk程序: 1.下载 ...

  7. Git学习笔记(四)标签和搭建Git服务

    一.标签是什么 发布一个版本时,我们通常先在版本库中打一个标签,这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库的一 ...

  8. centos 搭建 git 服务端和客户端

    centos 搭建git需要设置远程服务端和客户端.远程代码存放在服务端,多个客户端可以共享和维护服务端代码. 一.服务端主机 1.创建ssh,大部分默认已经安装,有ssh就跳过 yum instal ...

  9. Linux搭建git服务端

    1.安装$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel$ yum inst ...

随机推荐

  1. Oracle学习笔记之七(用户管理、角色与权限、导入导出等)

    下面这些基本的SQL语句应该熟悉,能够灵活运用.最好在不查资料的情况下,能够写出如下的任何代码. 1. 用户操作 --create user username identified by passwo ...

  2. 关于TcpClient,Socket连接超时的几种处理方法

    用TcpClient做通信的时候,经常发现网络连接不通的时候,代码就卡死在那里,TcpClient竟然没有超时的设定 泪奔啊 看来微软不是把所有工具准备得妥妥当当的啊 没办法 现在用线程来包装一下这个 ...

  3. .NET执行SQL插入时间的问题

    错误描述: 一个项目,源码是BOSS给的,部署到网上了,运行没有问题,可是在本地运行,就会有问题,问题在于往一些表插入记录的时候,本地不管怎么样都插入不了,而网上就可以插入,都是相同的一份代码 解决: ...

  4. 【Android】6.3 ProgressDialog

    分类:C#.Android.VS2015: 创建日期:2016-02-08 一.简介 进度条对话框(ProgressDialog)常用于不能在短时间内快速完成的操作,显示进度条的目的是为了让用户明白程 ...

  5. SQL 从查询结果里查询

    有orders表: 我想要从从表中查出每天电动车和手机各自的销售总额.这个需求还是蛮简单的,仅仅须要依据createtime和product group by即可了.以下是我写的SQL语句: SELE ...

  6. ssh 连 koding

    2014.12.10更新可用方法 koding是一个在线的开发平台.让自己从开发平台中释放出来.除了提供在线编程功能之外,Koding还有强大的社区功能,允许开发者通过相互浏览.交换代码而达到项目协作 ...

  7. 2>/dev/null

    2>/dev/null是如果你的命今出错的话,错误报告直接输出到黑洞里不会显示在屏幕上. ls -al 1>list.txt 2>list.err #将显示的数据,正确的输出到lis ...

  8. Spark history Server配置实用

    Spark history Server产生背景 以standalone运行模式为例,在运行Spark Application的时候,Spark会提供一个WEBUI列出应用程序的运行时信息:但该WEB ...

  9. JS移动li行数据,点击上移下移(是位置的互换,不是top的偏移量改变)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. mysql too many max_connections

    debian 环境 mysql  MySQL Community Server 5.6.27 首先修改 my.cnf文件  全局查找  find / -name my.cnf* [mysqld] 配置 ...