手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

RedHat Linux配置Git Server

[日期:2012-04-10] 来源:Linux社区  作者:fzxy002763 [字体: ]

这几天尝试了下用RedHat Linux来配置git server,还是挺顺利的

首先要配置EPEL,要不然就要下载源码编译(比较折腾,就算了),EPEL的配置见 http://www.linuxidc.com/Linux/2012-04/58309.htm

然后开始进行git server的配置

1.安装git-core

  1. yum install git-core  

2.初始化一个 repository

  1. [root@bogon first]# git init --bare myprj                //这里是工程的放置的目录,myprj为工程名  
  2. Initialized empty Git repository in /home/xfx-git/first/myprj/  
PS;指定 --bare,当前 repository 下就只有 .git/ 下的 objects,而没有真实文件。一般在 Server 端

3.初始化并提交项目

初始化repository后, 我们需要建立个master branch,才能被正常 git clone 

  1. [root@bogon first]# cd myprj/  
  2. [root@bogon myprj]# mkdir initial.commit  
  3. [root@bogon initial.commit]# git init  
  4. Initialized empty Git repository in /home/xfx-git/first/myprj/initial.commit/.git/  
  5. [root@bogon initial.commit]# git remote add origin /home/xfx-git/first/myprj/  
  6. [root@bogon initial.commit]# touch Readme  
  7. [root@bogon initial.commit]# git add Readme  
  8. [root@bogon initial.commit]# git commit -m "inital commit"  
  9. [master (root-commit) 5b6e14d] inital commit  
  10.  Committer: root <root@bogon.(none)>  
  11. Your name and email address were configured automatically based  
  12. on your username and hostname. Please check that they are accurate.  
  13. You can suppress this message by setting them explicitly:  
  14.   
  15.     git config --global user.name "Your Name"  
  16.     git config --global user.email you@example.com  
  17.   
  18. After doing this, you may fix the identity used for this commit with:  
  19.   
  20.     git commit --amend --reset-author  
  21.   
  22.  0 files changed, 0 insertions(+), 0 deletions(-)  
  23.  create mode 100644 Readme  
  24. [root@bogon initial.commit]# git push origin master  
  25. Counting objects: 3, done.  
  26. Unpacking objects: 100% (3/3), done.  
  27. Writing objects: 100% (3/3), 203 bytes, done.  
  28. Total 3 (delta 0), reused 0 (delta 0)  
  29. To /home/xfx-git/first/myprj/  
  30.  * [new branch]      master -> master  
4.激活了该 repository, 我们可以正常使用了
  1. [root@bogon myclient]$ git clone /home/xfx-git/first/myprj   
  2. Cloning into 'myprj'...  
  3. done.  
  4. [root@bogon myclient]$ cd myprj  
  5. [root@bogon myprj]$ vim Readme   
  6. [root@bogon myprj]$ git commit -m "modify readme" Readme  
  7. [master 1bf69b4] modify readme  
  8.  1 files changed, 1 insertions(+), 0 deletions(-)  
  9. [root@bogon myprj]$ git push  
  10. Counting objects: 5, done.  
  11. Writing objects: 100% (3/3), 247 bytes, done.  
  12. Total 3 (delta 0), reused 0 (delta 0)  
  13. Unpacking objects: 100% (3/3), done.  
  14. To /home/xfx-git/first/myprj   
  15.    032dad8..1bf69b4  master -> master  
5.git的使用,这里转载几种常用的git方法

(1)SSH
SSH 协议大家都很熟悉,只要你的 Server 能 ssh 登录就可以。假设你的 Server 可以远程 ssh 登录,我们看如何从 Server clone 出 Git Repository:
 [lgao@lgao myclient]$ git clone lgao@10.66.14.143:git_repos/myprj from_remote
Cloning into 'from_remote'...
lgao@10.66.14.143's password: 
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
也就是说只要你在 Server 端给一个用户创建完帐号后, 他就可以 clone 代码了。 具体的chmod.html' target='_blank'>权限设置和 Linux 下权限配置是一样的。 一般跟一组 repositories 指定一个新的 group, 把新建的用户加入到该 group 后就可以有相应的读写权限了。
还有另外一种方式,是通过提交公钥到 Server 端来获得访问和提交权限,而不需要创建用户。 具体细节本文不加讨论。
(2)Git
该协议一般只是只读权限。
第一步需要安装 git-daemon:
[root@lgao ~]# yum install git-daemon
接着启动 git-daemon:
[lgao@lgao initial.commit]$ git daemon --base-path=/home/lgao/sources/my_own/repositories --export-all
在你的工程下创建 git-daemon-export-ok 文件:
[lgao@lgao repositories]$ cd myprj
[lgao@lgao myprj]$ touch git-daemon-export-ok
现在就可以通过 Git 协议 clone repository 了:
[lgao@lgao test]$ git clone git://lgao.nay.redhat.com/myprj
Cloning into 'myprj'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
(3)HTTP
该协议一般只是只读权限。GitWeb 包提供 CGI , 它可以被部署到任何支持静态 web 服务的服务器中去。我们还以最常见的 Apache 为例:
版本信息:
Httpd:Apache/2.2.21 (Fedora
Git:  git version 1.7.7.5
GitWeb:1.7.7.5-1.fc16
安装 Httpd 和 gitweb:
[lgao@lgao initial.commit]$ yum install httpd gitweb
修改 /etc/gitweb.conf:
[lgao@lgao repositories]$ vim /etc/gitweb.conf
添加:
our $projectroot = "/home/lgao/sources/my_own/repositories"; 
在 httpd 的 DocumentRoot 所在目录创建 Link 文件:
[root@lgao DCIM]# cd /var/www/html
[root@lgao html]# ln -s /home/lgao/sources/my_own/repositories/ git
[root@lgao html]# chown -R 777 git
重启 httpd:
[root@lgao httpd]# service httpd restart
Restarting httpd (via systemctl):                          [  OK  ]

PS:这里访问网址是10.0.61.61/git,前面的根据自己的redhat server ip地址改下,就能访问了

更多RedHat相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10

linux
相关资讯       redhat  Git 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款