如何架设Git Server


  1. 架设Git Server
    • 安装OpenSSH  
    • 安装 git 
      • #sudo apt-get install git-core
    • 安装 gitosis   
      • #git clone git://eagain.net/gitosis
      • #cd gitosis
      • #sudo python setup.py install
      • 注意:如果python setup.py install失败,需要安装python-setuptools.py
      • #sudo apt-get install python-setuptools.py
    • gitosis create system user
      • #sudo adduser --system --shell /bin/sh --gecos 'git SCM user' --group --disabled-password --home /home/git  git
      • 如果遇到su git的时後密码一直不对可以用下面的方法
      • #sudo useradd -m git
      • #sudo password git
    • Add user
      • 在各local user端(需要用到git server的机器)
      • #ssh-keygen -t rsa
      • #scp ~./ssh/id_rsa.pub ${SERVER_IP}:id_rsa.pub
      • cd 到 id_rad.pub foler
      • #sudo chmod 777 id_rsa.pub
      • #sudo -H -u git gitosis-init < id_rsa.pub 
      • (or su git; gitosis-init < id_rsa.pub也可以 记得exit切回原user)
      • 此时,会在/home/git目录下生成一些目录,如果clone gitosis-admin.git,需要执行
      • #sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
    • 安装GitWeb (如果有需要的话)
      • sudo apt-get install gitweb
    • 安装Apache
      • sudo apt-get install apache2
    • config gitweb
      • #cd /var/ www/ 
      • #sudo ln -s / usr/ share/ gitweb/* .
      • sudo vim /etc/ gitweb.conf
      • $projectroot 改为gitosis-admin.git所在目录: /home/git/repositories
      • 修改 /home/git/repositories权限,默认情况下,gitosis将 repositories权限设置为不可读
      • #sudo chmod 777 -R /home/git/repositories
    • Config Apache
      • 默认的web目录是/var/www,默认的cgi目录是 /usr/lib/cgi-bin/
      • gitweb的gitweb.cgi 应该会在 /usr/lib/cgi-bin/
      • 如果没有需要执行下面step

      • #sudo vim etc/apache2/apache.conf
      • SetEnv  GITWEB_CONFIG   /etc/gitweb.conf
      • gitweb.conf配置文件形如:(可自行修改,这里不做详细介绍)
      • <Directory "/srv/www/cgi-bin/gitweb">           
      • Options FollowSymlinks ExecCGI          
      • Allow from all                          
      • AllowOverride all 
      • Order allow,deny                        
      •  <Files gitweb.cgi>
      • SetHandler cgi-script
      • </Files>                    
      • RewriteEngine on
      • RewriteCond %{REQUEST_FILENAME} !-f
      • RewriteCond %{REQUEST_FILENAME} !-d
      • RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
      • </Directory>
     2. Git Manager
    • 安装msysgit
      • 下载地址:http://code.google.com/p/msysgit/downloads/list
    • Gen Public Key   
      • #ssh-keygen -t rsa
    • Clone一份 admin
      • #git clone git@YOUR_SERVER:gitosis-admin.git
      • cd gitosis-admin
      • gitosis.conf是用来管理gitosis
      • #vim gitosis.conf, 打开gitosis.conf文件,内容为:
             [group gitosis-admin]
             writable = gitosis-admin
             members =  Administrator@LILIN
             这个是管理组的权限,members中的用户名就是刚才上传的公钥里面的用户名。
             
             把内容修改为:
             [gitosis]
             gitweb = yes

             [group gitosis-admin]
             writable = gitosis-admin
             members = Administrator@LILIN wirror800@192.168.1.102

             [group apps ]
             writable = apps
             members = Administrator@LILIN wirror800@192.168.1.102
      • #git commit -a -m “created a new repository” 
      • #git push
      • 以上就完成修改
    • Create App repo
      •  #mkdir apps
      • #cd apps
      • #git init 
      • #git remote add origin git@YOUR_SERVER:apps.git
      • #git add .
      • #git commit -am "imitial import" 
      • #git push origin master:refs/heads/master
    • Add member
      • #cd ../gitosis-admin
      • #cp member_1.pub keydir/
      • #cp member_2.pub keydir/ git
      • #add keydir/member_1.pub keydir/member_2.pub
      • #vim gitosis.conf

                     [group apps]
                     - members = wirror800
                     + members = wirror800 member_1 member_2
                     writable = apps
      • #git commit -a -m "Granted new members commit rights to apps"  
      • #git push 
    • 其他member抓code
      •  #git clone git@YOUR_SERVER:apps.git

留言