zoukankan      html  css  js  c++  java
  • Git安装配置总结

    实验环境:

    主机名           IP(Static)                   系统                                                    配置                                用途
    GitServer       192.168.220.211        CentOS-6.3-x86_64-minimal          2CPU,1G RAM,20G DISK,1网卡     Git Server

    GitNode01     192.168.220.212        CentOS-6.3-x86_64-minimal          2CPU,1G RAM,20G DISK,1网卡     Git Node

    GitNode02     192.168.220.213         Windows 7 64bit                            2CPU,1G RAM,20G DISK,1网卡     Git Node

    *******************************************************************************************************************************************************

    一、配置GitServer:

    1.系统基础设置:

    [root@GitServer ~]# vi /etc/selinux/config

    SELINUX=disabled

    [root@GitServer ~]#  iptables –F

    [root@GitServer ~]# service iptables stop

    [root@GitServer ~]# chkconfig iptables off

    [root@GitServer ~]# reboot

    2.安装Git,设置用户:

    [root@GitServer ~]# yum -y install git

    [root@GitServer ~]# groupadd gitserver

    [root@GitServer ~]# useradd --home /home/git git -g gitserver

    [root@GitServer ~]# passwd git

    更改用户 git 的密码 。

    新的 密码:

    无效的密码: 它基于字典单词

    无效的密码: 过于简单

    重新输入新的 密码:

    passwd: 所有的身份验证令牌已经成功更新。

    [root@GitServer ~]# git config --global user.name "git"

    [root@GitServer ~]# git config --global user.email "git@email.com"

    [root@GitServer ~]# su - git

    [git@GitServer ~]$ chmod 755 /home/git

    [git@GitServer ~]$ ssh-keygen -t rsa                                  //任何提示可略过,一路回车即可;

    [git@GitServer ~]$ cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys

    [git@GitServer ~]$ echo "Host *" >> ~/.ssh/config

    [git@GitServer ~]$ echo "StrictHostKeyChecking no" >> ~/.ssh/config

    [git@GitServer ~]$ cd .ssh

    [git@GitServer .ssh]$ ls

    authorized_keys  id_rsa  id_rsa.pub                               //将私钥(id_rsa)分发给客户端用户,用于客户端与服务器的无密码交互访问;

    [git@GitServer .ssh]$ exit

    logout

    3.安装Gitosis:

    [root@GitServer ~]# yum -y install python-setuptools

    [root@GitServer ~]# cd /tmp/

    [root@GitServer tmp]# git clone git://github.com/res0nat0r/gitosis.git

    [root@GitServer tmp]# cd gitosis/

    [root@GitServer gitosis]# python setup.py install 

    [root@GitServer gitosis]# cd

    4.初始化gitosis:

    [root@GitServer ~]# su - git

    [git@GitServer ~]$ gitosis-init < /home/git/.ssh/id_rsa.pub

    Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/

    Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/

    [git@GitServer ~]$ ll -h

    总用量 8.0K

    drwxr-xr-x 2 git gitserver 4.0K 8月  20 17:59 gitosis

    drwxr-xr-x 3 git gitserver 4.0K 8月  20 17:59 repositories

    [git@GitServer ~]$ chmod u+x /home/git/repositories/gitosis-admin.git/hooks/post-update

    5.创建新项目:

    [git@GitServer ~]$ cd repositories/

    [git@GitServer repositories]$ ls

    gitosis-admin.git

    [git@GitServer repositories]$ mkdir new-project.git

    [git@GitServer repositories]$ cd new-project.git

    [git@GitServer new-project.git]$ git init --bare

    [git@GitServer new-project.git]$ chmod -R 777 objects refs

    [git@GitServer new-project.git]$ cd ..

    [git@GitServer repositories]$ cd gitosis-admin.git/

    [git@GitServer gitosis-admin.git]$  chmod -R 777 objects refs

    [git@GitServer gitosis-admin.git]$  vi gitosis.conf 

    [gitosis]


    [group gitosis-admin]

    writable = gitosis-admin

    members = git@GitServer


    [group new-project]

    writable = new-project

    members = git@GitServer GitNode01 GitNode02                      //加入GitNode01 GitNode02用户对new-project项目的访问权限;

    保存并退出;

    [git@GitServer gitosis-admin.git]$ cd gitosis-export/

    [git@GitServer gitosis-export]$ ls

    keydir

    [git@GitServer gitosis-export]$ cd keydir/

    [git@GitServer keydir]$ ls                    //该目录下目前只有git@GitServer.pub,当客户端生成公钥后将公钥放置该目录;

    git@GitServer.pub 

    [git@GitServer keydir]$ exit

    6.安装配置gitweb:

    [root@GitServer ~]# yum -y install gitweb httpd

    [root@GitServer ~]# vi /etc/gitweb.conf 

    加入一行:

    $projectroot = "/var/www/git";

    [root@GitServer ~]# vi /etc/httpd/conf.d/git.conf

    内容如下

    Alias /git /var/www/git


    <Directory /var/www/git>

      Allow from all

      AllowOverride all

      Order allow,deny

      Options +ExecCGI

      AddHandler cgi-script .cgi

      DirectoryIndex gitweb.cgi

      SetEnv  GITWEB_CONFIG  /etc/gitweb.conf

      Dav On

      RewriteEngine Off

    </Directory>

    [root@GitServer ~]# /etc/init.d/httpd restart

    [root@GitServer ~]# ln -s /home/git/repositories/new-project.git /var/www/git/

    通过浏览器:

    http://192.168.100.211/git即可访问:

    7.其他相关操作:

    下面操作内容用于Git Windows客户端配置:

    [root@GitServer ~]# mkdir .ssh

    [root@GitServer ~]# cd .ssh

    [root@GitServer .ssh]# ls

    [root@GitServer .ssh]# cp /home/git/.ssh/id_rsa ./

    [root@GitServer .ssh]# cp ~/.gitconfig ./

    [root@GitServer .ssh]# ls -ah

    .  ..  .gitconfig  id_rsa

    [root@GitServer .ssh]# cd

    **********************************************************************************************

    二、配置Linux Git客户端GitNode01:

    1.系统基础设置:

    [root@GitServer ~]# vi /etc/selinux/config

    SELINUX=disabled

    [root@GitNode01 ~]#  iptables –F

    [root@GitNode01 ~]# service iptables stop

    [root@GitNode01 ~]# chkconfig iptables off

    [root@GitNode01 ~]# reboot

    2.安装Git,设置用户

    [root@GitNode01 ~]# yum -y install git

    [root@GitNode01 ~]# groupadd gitserver

    [root@GitNode01 ~]# useradd --home /home/gituser gituser -g gitserver

    [root@GitNode01 ~]# passwd gituser

    更改用户 gituser 的密码 。

    新的 密码:

    无效的密码: 它基于字典单词

    无效的密码: 过于简单

    重新输入新的 密码:

    passwd: 所有的身份验证令牌已经成功更新。

    3.下载项目,上传文件

    [root@GitNode01 ~]# su - gituser

    [gituser@GitNode01 ~]$ ssh-keygen -t rsa                                  //任何提示可略过,一路回车即可;

    [gituser@GitNode01 ~]$ cd .ssh/

    [gituser@GitNode01 .ssh]$ ls

    id_rsa  id_rsa.pub

    [gituser@GitNode01 .ssh]$ rm -rf id_rsa

    [gituser@GitNode01 .ssh]$ scp git@192.168.100.211:/home/git/.ssh/id_rsa ./     //拷贝GitServer的私钥到客户端本地,用户无密码验证;

    [gituser@GitNode01 .ssh]$ mv id_rsa.pub GitNode01.pub

    [gituser@GitNode01 .ssh]$ scp GitNode01.pub git@192.168.100.211:/home/git/repositories/gitosis-admin.git/gitosis-export/keydir/   //上传公钥到GitServer;

    [gituser@GitNode01 .ssh]$ cd

    [gituser@GitNode01 ~]$ mkdir myproject

    [gituser@GitNode01 ~]$ cd myproject/

    [gituser@GitNode01 myproject]$ git clone git@192.168.100.211:/home/git/repositories/new-project.git

    Initialized empty Git repository in /home/gituser/myproject/new-project/.git/

    warning: You appear to have cloned an empty repository.

    [gituser@GitNode01 myproject]$ ls

    new-project

    [gituser@GitNode01 myproject]$ cd new-project/

    [gituser@GitNode01 new-project]$ ls

    [gituser@GitNode01 new-project]$ touch readme.txt

    [gituser@GitNode01 new-project]$ echo "text-1234567890" > readme.txt

    [gituser@GitNode01 new-project]$ more readme.txt

    text-1234567890

    [gituser@GitNode01 new-project]$ git add .         //不要忘了最后面的".";

    [gituser@GitNode01 new-project]$ git commit -a   //该处会弹出编辑对话框,内容实际是文件的注释,在最下端输入想添加的注释即可;

    [gituser@GitNode01 new-project]$ git push origin master

    Counting objects: 3, done.

    Writing objects: 100% (3/3), 227 bytes, done.

    Total 3 (delta 0), reused 0 (delta 0)

    To git@192.168.100.211:/home/git/repositories/new-project.git

     * [new branch]      master -> master

    在浏览器http://192.168.100.211/git/,在new-project项目的tree下可看到readme.txt文件,表明上传成功;

    **********************************************************************************************

    三、配置Windows Git客户端GitNode02:

    1.下载Git Windows客户端,默认安装即可:

    Git Windows客户端下载地址:

    http://code.google.com/p/msysgit/downloads/list

    2.客户端配置:

    查看自己所使用的用户,比如我使用的Administrator,切换到该目录(C:Documents and SettingsAdministrator),将"配置GitServer"第七步中root下的".ssh"目录拷贝至该目录下,然后将.ssh下的.gitconfig文件剪切到上一级目录,即C:Documents and SettingsAdministrator下,修改.gitconfig内容,将"name = git"的git改成GitNode02,"email = git@email.com"的邮件地址部分改为GitNode02@email.com。

    内容如下:


    [user]

    name = GitNode02

    email = GitNode02@email.com

    3.生成公钥

    找一台Linux主机任意用户下执行ssh-keygen -t rsa,并把.ssh目录下的id_rsa.pub文件重命名为GitNode02.pub,将GitNode02.pub文件传送GitServer的/home/git/repositories/gitosis-admin.git/gitosis-export/keydir目录下

    并且执行下列命令:

    [root@GitServer keydir]# pwd

    /home/git/repositories/gitosis-admin.git/gitosis-export/keydir

    [root@GitServer keydir]# chown git:gitserver GitNode02.pub

    [root@GitServer keydir]# chmod 644 GitNode02.pub

    [root@GitServer keydir]# ll -h

    总用量 12K

    -rw-r--r-- 1 git gitserver 395 8月  20 17:59 git@GitServer.pub

    -rw-r--r-- 1 git gitserver 399 8月  20 18:34 GitNode01.pub

    -rw-r--r-- 1 git gitserver 396 8月  20 20:38 GitNode02.pub

    [root@GitServer keydir]# 

    4.Windows测试:

    (1).打开桌面上的”git bash“;

    (2).从GitServer克隆项目:

    (2).查看本地项目克隆结果:

    (3).写一个名为”text-windows.txt“的文件

    (4).上传文件:

    (5).打开浏览器输入:http://192.168.100.211/git/new-project项目的tree下可看到”text-windows.txt“文件,表明上传成功;


    **********************************************************************************************

  • 相关阅读:
    Android Studio Gradle 添加.so 支持文件
    poj 3270 更换使用
    linux通过使用mail发送电子邮件
    php 上传文件 $_FILES['']['type']的值
    浅谈Base64编码
    expect实现ssh自动登录
    C++ 多源码文件简单组织
    linux下修改hostid
    SQLite/嵌入式数据库
    类内数组声明,“类外”指定大小
  • 原文地址:https://www.cnblogs.com/myiaas/p/4161361.html
Copyright © 2011-2022 走看看