如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management You can use subscription-manager to register
Package git-1831-4el7x86_64 already installed and latest version
Nothing to do
[root@linuxprobe ~]# mkdir linuxprobegit
修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobegit/
初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobegit/
[root@linuxprobe linuxprobegit]# git --bare init
Initialized empty Git repository in /root/linuxprobegit/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair
Enter file in which to save the key (/root/ssh/id_rsa):
Created directory '/root/ssh'
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/ssh/id_rsa
Your public key has been saved in /root/ssh/id_rsapub
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 root@linuxprobecom
The key's randomart image is:
+--[ RSA 2048]----+
| o+ooo |
| oo + |
| + E o |
| o = + = |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh-copy-id 1921681010
root@1921681010's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '1921681010'"
and check to make sure that only the key(s) you wanted were added
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone root@1921681010:/root/linuxprobegit
Cloning into 'linuxprobe'
warning: You appear to have cloned an empty repository
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#
初始化下Git工作环境:
[root@linuxprobe ~]# git config --global username "Liu Chuan"
[root@linuxprobe ~]# git config --global useremail "root@linuxprobecom"
[root@linuxprobe ~]# git config --global coreeditor vim
向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readmetxt
[root@linuxprobe linuxprobe]# git add readmetxt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached " to unstage)
#
# new file: readmetxt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readmetxt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server root@1921681010:/root/linuxprobegit
将文件提交到远程Git服务器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done
Total 3 (delta 0), reused 0 (delta 0)
To root@1921681010:/root/linuxprobegit
[new branch] master -> master
Branch master set up to track remote branch master from server
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@linuxprobe linuxprobe]# cd /Desktop
[root@linuxprobe Desktop]# git clone root@1921681010:/root/linuxprobegit
Cloning into 'linuxprobe'
remote: Counting objects: 3, done
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readmetxt
I successfully cloned the Git repository
这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下
一、使用包管理器安装Git
Git已经被所有的主流Linux发行版所支持。所以安装它最简单的方法就是使用各个Linux发行版的包管理器。
1、Debian, Ubuntu, 或 Linux Mint
$ sudo apt-get install git2、Fedora, CentOS 或 RHEL
$ sudo yum install git或$ sudo dnf install git3、Arch Linux
$ sudo pacman -S git4、OpenSUSE
$ sudo zypper install git5、Gentoo
$ emerge --ask --verbose dev-vcs/git二、从源码安装Git
如果由于某些原因,希望从源码安装Git,按照如下介绍操作。
1、安装依赖包
在构建Git之前,先安装它的依赖包。
//Debian, Ubuntu 或 Linux Mint$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
//Fedora, CentOS 或 RHEL
$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x
2、从github官网下载最新版本的Git。然后在/usr下构建和安装。
注意,如果打算安装到其他目录下(例如:/opt),那就把“--prefix=/usr”这个配置命令使用其他路径替换掉。
$ cd git-xxx$ make configure
$ 。/configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info
1创建Gitblit安装目录 首先我们将在我们的服务器上建立一个目录,并在该目录下安装最新的Gitblit。 $ sudo mkdir -p /opt/gitblit $ cd /opt/gitblit 创建gitblit目录 2 下载并解压 现在,我们将从Gitblit官方站点下载最新版的Gitblit。
1、yum方式安装
# yum -y install git
如果提示系统提示没有找到git包,可以采用下面的方式
2、下载Git源码包
官网:http://git-scmcom/
$ tar -xjvf git-1741tarbz2
$ cd git-1741/
$ make prefix=/usr/local all
$ make prefix=/usr/local install
0条评论