luozhangyou 发表于 2020-2-14 21:40:39

centos6 下安装git(http方式)

1、 安装依赖的库
# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
2、删除原本的安装的git
# yum remove git -y3、下载git-2.10.0.tar.gz 到 /usr/local/src
# cd /usr/local/src
# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz4、编译安装
# tar -zvxf git-2.10.0.tar.gz
# cd git-2.10.0
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install

5、 增加软连接
# ln -s /usr/local/git/bin/* /usr/bin/
# git --version
如果能正常显示版本号,即表示成功。

6、新建git仓库
$ mkdir /home/git/repositories/test.git
$ cd /home/git/repositories/test.git
$ git --bare init

7、修改上一步创建的文件夹test.git的所有者与所属群组,要让apache能读/写这个文件夹,注意这里-R必须加上,不然clone会出现权限不够问题
# chown -R apache:apache /home/git8、Apache的配置(ps:这里开始就和之前安装git方式不一样了)

8.1、安装Apache(系统有的可以忽略这一步)
# yum install httpd apr apr-util
# yum install httpd-manual mod_ssl mod_perl mod_auth_mysql启动Apache,并测试安装是否成功
# /bin/systemctl start httpd.service
# /bin/systemctl enable httpd
# /bin/systemctl status httpd.service


8.2、创建新用户,输入密码
# htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>
(PS:-m:表示MD5加密方式 ;-c:表示创建文件,只有第一次创建用户时候加上该参数,以后不用)

8.3、设置git-team.htpasswd文件的访问权限
# chmod 640 /etc/httpd/conf.d/git-team.htpasswd8.4、修改apache配置文件httpd.conf
      # vi /etc/httpd/conf/httpd.conf在文件末尾添加下列内容:
<VirtualHost *:80>
      ServerName 自己的服务器IP或者域名
      SetEnv GIT_HTTP_EXPORT_ALL
      SetEnv GIT_PROJECT_ROOT /home/git/repositories
      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>8.5、重启Apache
# /bin/systemctl restart httpd.service到这里git服务器基本功能就搭建好了,可以clone了
地址 http://自己服务器IP或域名/git/test.git
(PS:这里如果连接不上,可以查看你的防火墙80端口是否开启,如果没开启当然是无法clone的)

9、安装gitweb实现浏览器访问git服务器
9.1、下载安装gitweb
# yum install gitweb9.2、修改git.conf
# vi /etc/httpd/conf.d/git.conf将 "Alias /git /var/www/git" 改为 "Alias /gitweb /var/www/git"

9.3、修改gitweb.conf
# vi /etc/gitweb.conf修改成:our $projectroot = "/home/git/repositories"

ok,到这里就可以用浏览器访问了,地址 http://自己的服务器IP或者域名/gitweb/

10、客户端http方式访问的,每次都要输入密码这里可以设置长期存储密码,客户端运行
git config --global credential.helper store增加仓库地址时候带上用户名(name)和密码(password)也可以
http://name:password@<strong>自己服务器IP或域名/git/test.git</strong>这里注意一点,如果用户名是邮箱地址或者中文 把它 url编码 ,@对应的是%40


页: [1]
查看完整版本: centos6 下安装git(http方式)