当前位置:首页 » 云服务器 » git远程服务器搭建

git远程服务器搭建

发布时间: 2022-11-27 19:53:16

A. 使用Gitolite搭建Git服务器

Git服务的管理工具,主要有如下几种。

Gitolite 使用perl语言编写,维护和更新比较积极,下面测试使用Gitolite搭建Git服务器。

一般新建用户 ~/.ssh/ 目录是不存在的。

生成路径会在ssh-kengen执行后给出,也可修改。windows下生成路径默认位于 C:/user/用户名/.ssh 下。

此时, gitolite 会初始化两个仓库,同时创建 authorized_keys 文件

管理库中有两个目录, conf/ 和 keydir/ 。

仓库的创建通过编辑 gitolite-admin/conf/gitolite.conf 即可,然后将配置后的文件上传服务器。

若本地已有仓库repo2,将其添加到服务器

gitolite可以通过用户组的方式进行管理

如上提示,需要输入密码。
需要安装 openssh ,并将 gitolite 用户添加在 sshusers 组中,有的服务器可能是 ssh 组。

计算机领域的Cookbook指的是实用经典案例的意思,是对一些普遍性问题的解决方案的总结和整理。

B. linux搭建git远程仓库

1. linux和windows端分别安装git,其中linux中可以用yum安装

[root@node0~]#yum install git

git的默认安装路径在/usr/libexec/git-core

[root@node0 git-core]#cd /usr/libexec/git-core

[root@node0 git-core]#git --version

git version 1.7.1

2.设置linux端git的用户名和密码

[root@node0 git-core]# groupadd git

[root@node0 git-core]# useradd wang -g git

[root@node0 git-core]# passwd wang

New password:

3.在服务器端创建远程仓库

[root@node0 ~]# mkdir -p /mnt/gitrep/wjf

[root@node0 ~]# cd /mnt/gitrep/wjf/

[root@node0 wjf]# git init

Initialized empty Git repository in /mnt/gitrep/wjf/.git/

把仓库所属用户改为wang(git的用户名)

[root@node0 wjf]# chown -R wang:git .git/

注:chown将指定文件的拥有者改为指定的用户或组 -R处理指定目录以及其子目录下的所有文件

4.在windows客户端克隆仓库 

$ git clone [email protected]:/mnt/gitrep/wjf/.git

Cloning into 'wjf'...

The authenticity of host '192.168.111.60 (192.168.111.60)' can't be established.

RSA key fingerprint is SHA256:MgWCWF************************1m2tI.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '192.168.111.60' (RSA) to the list of known hosts.

[email protected]'s password:

第一次连接远程仓库,出现黑体部分,这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,键入yes,然后输入远程仓库的密码就可以了。

5.实际中也通常通过设置公钥的方式来连接远程仓库,这样就不用每次连接都需要密码了。

设置公钥:

1.在windows客户端的gitbash中生成用户私钥和公钥

$ ssh-keygen -t rsa -C "[email protected]"

在c盘用户路径下的/.ssh文件夹下会生成私钥id_rsa和公钥id_rsa.pub

2.linux端

首先 Git服务器打开RSA认证,即,修改/etc/ssh/sshd_config,将其中的以下三项打开

RSAAuthentication yes 

 PubkeyAuthentication yes 

 AuthorizedKeysFile .ssh/authorized_keys

然后,将客户端生成的公钥给到服务器端

即,将公钥给到 home/wang(git的用户名)/.ssh/authorized_keys

[root@node0 ~]# cd /home/wang

[root@node0 wang]# mkdir .ssh

[root@node0 wang]# chmod 777 .ssh

[root@node0 wang]# touch .ssh/authorized_keys

在windows客户端的gitbash中 执行:

$ ssh [email protected] 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

然后在linux端:

[root@node0 wang]# chmod 600 .ssh/authorized_keys

[root@node0 wang]# chmod 700 .ssh

[root@node0 wang]# chown wang:git .ssh

[root@node0 wang]# chown wang:git .ssh/authorized_keys 

至此,以后再连接远程仓库就不需要密码了。

若仍需要密码,可以查看ssh连接日志/var/log/secure:

常见连接失败原因:Authentication refused: bad ownership or modes for directory /home/wang/.ssh 

这时需要检查该目录的所属用户和读写权限等级是否符合要求。公钥以及.ssh文件的权限应该属于git的用户和用户组,读写权限等级.ssh 700,authorized_keys 600.

C. 如何在mac下远程搭建git服务器

第一步,下载gitblit


http://gitblit.com/

这里当然是选择linux/osx的版本。下载下来是一个.tar.gz的压缩文件,我下载时最新版本是gitblit-1.7.1.tar.gz


D. 如何在mac下远程搭建git服务器

Git支持的协议主要是四种:
本地: 需要文件共享系统,权限不好控制
HTTP:速度慢
SSH:同时支持读写操作,不支持匿名的读取(Git默认协议)
GIT:最快

搭建的难易程度和特点综合筛选,最合适的还是ssh,并且大部分服务器上基本都有ssh服务,所以省去了不少麻烦。一个最基本的思路是给每一个人一个
ssh帐号,这样大家就可以通过用户名和口令来访问了,但是显然这不是一个好的选择,这个做法有些多余,并且对于repo的权限很难管理。
在使用Github的时候,会利用rsa.pub公钥/私钥的方式,这样在服务端拥有用户的公钥(*.pub)之后就可以,跨过繁琐的口令,直接认证提交了,而服务端也会根据不同的用户身份,对其权限有着更加灵活的管理。因此我们也采用这种方式。
服务端
为了使远程库访问更加直观,先在服务器上创建一个名为git的账户,这样以后clone的时候就如下面的格式了:
git clone git@server:some.git
创建新的用户,创建repo等目录
$sudo adser git
$su git
$cd ——
$mkdir repos
在HOME下的。ssh目录,如果没有则创建,创建一个authorized_keys文件,这个文件就是用来管理所有git用户的公钥的,也就是这里面的用户对于项目有着R+W的权限。
客户端

于每一个客户端,我们需要生成一对密钥和公钥,如果是Github用户,那么。ssh目录下,一定有id_rsa.pub和id_rsa两个文件,其中第
一个是系统生成的公钥,另一个是自己要保存好的密钥。如果没有的话,可以在终端执行:ssh-keygen来生成,完成后,将自己的公钥提交给管理员,这
就是一个注册的行为。
完成
最后一步,管理员将团队成员的公钥添加到authorized_keys中,比如将同学susie加入:
$ cat susie.pub 》 authorized_keys
至此,大家可以通过git@server:repos/some.git来访问公共的版本库了。
问题
安全问题,成员可以登录git用户的shell,细节权限如分支等不好控制
管理麻烦,新建repo,或者增加成员比较麻烦,尤其是修改的时候

E. 自己搭建git服务器

刚开始是看的廖大神的git服务器搭建,感觉看起来很难,因为是第一次在服务器上搭建东西,因此看起来感觉一顿蒙,后来结合简述上的一篇文展和廖大神的文章一并将git服务搭建起来,虽然别人看起来很简单。。。

# 添加用户

# 设定密码

创建放置密钥的文件,进入文件git bash,输入下列命令

按照提示操作,成功后会出现两个密钥,私钥和公钥。

将生成的私钥和公钥放在工作目录下,在服务器端,找到上面创建的git用户,即:

然后创建文件夹.ssh,在.ssh文件下创建文件authorized_keys,用来放置所有所有公钥

进入粘贴公钥

上面的server需要改为你自己的服务器的IP地址

clone成功之后你会在你的工作目录看到服务器上面的sample文件

完成。。。。。。。。。。。。。。。。。。。

F. 如何搭建linux git服务器

首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do

然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@linuxprobe ~]# mkdir linuxprobe.git

修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/

初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/

其实此时你的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_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+

将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.

此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
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 user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim

向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[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 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean

但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git

将文件提交到远程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 [email protected]:/root/linuxprobe.git
* [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 [email protected]:/root/linuxprobe.git
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 readme.txt
I successfully cloned the Git repository

这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下

G. 搭建Git服务器及备份服务器

OS:CentOS 7.2
Git:1.8.3.1

备份模式:

以下步骤以双机备份为例,单机备份同理,只是在镜像git项目的时候把git url换成单机中的git项目目录即可。

首先,查看系统软件库中是否有git和git的版本:

CentOS 7.2环境下的输出如下:

CentOS 7.x版本的仓库中已经附带了1.8.3.1版本的git,可以直接安装。
CentOS 6.x中的git是1.7.x版本,自带库中git版本低的linux发行版可以添加git1.8.3.1的源来安装git,但这个操作要求本机能访问互联网
其他版本的git理论上也可以,请自行测试

结果最后显示“安装完成”或“Complete”表示安装成功。可以直接使用git命令测试一下:

输出如下表示git安装成功并可用。

创建一个git用户,用来提供给外部用户以git url的方式访问git库。

在用户目录或其他对外目录中创建 /git/repos 目录,用来存放git库。

注意: 尽量使用git用户来创建该目录,方便以后git操作该目录,如果是使用其他用户创建的,记得使用以下命令将该目录的owner改为git:

为了方便访问,可以在根目录下创建一个软链连接到该目录:

这样设置后,假如以后有一个库叫 test.git ,那么就可以通过以下url来访问git库了:

创建一个测试库用来测试备份及连通性。

同主GIT服务器的《安装git》章节。

同主GIT服务器的《创建git库目录》章节。
目录结构尽量与主git服务器上的结构一致,如果不一致,使用软链的形式将git url配置为与主git服务器一致,这样保证在切换服务器时,客户端不用做修改操作。

以上个步骤中创建的 test.git 为例:

这样,主git服务器中的 test.git 就镜像到备份机中了。

如果主服务器的git项目发生了变更,可以将变更同步到备份机。

将以上同步命令写成脚本,添加一个定时任务来定时同步即可。
(待补充)

备份同步时每次都需要输入主git服务器的密码,比较麻烦,也不利于定时同步的脚本操作,可以使用ssh免密登录的方式,在主服务器上配置备份服务器的公钥。

一路Enter(回车键),完成后会打印出密钥的生成位置,通常在用户主目录的 .ssh 目录中。默认情况下会生成以下两个文件:

一定要注意上述命令中的第三步,权限要设置对,否则认证不过去不能免密登录。

如果在实际运行中,主git服务器挂了一段时间,在这段时间里一直是备份git服务器在工作,那么在修复好主服务器后需要将这一段时间的变更同步回主服务器。

操作完成后备份库自上一次同步后的更改都推送到了主库。

H. 如何在mac下远程搭建git服务器

为有读写权限的用户建立一个分组。根据你的操作系统,你可以用groupadd命令来实现,用vigr来编辑分组文件,或者直接编辑/etc/group文件。在最后,你会在/etc/group文件中看到如下一行
?
1
repogroup:*:10005:marry,john,violet
其中,repogroup是准许接入这个仓库的组的名字。10005是一个独一无二的分组识别数字,marry,john,violet则是获准接入这个仓库的用户。

决定Git仓库的路径。它既可以放在你的home路径下(e.g. /home/yourname/gitroot),也可以放在一个专用的路径下(e.g. /var/gitroot).
配置权限,让Git用户可以访问这个目录
?
1
2
chmod g+rx /path-to/gitroot
chown :grouprepo /path-to/gitroot
建立新的Git仓库,叫做newrepo
?
1
2
cd /path-to/gitroot
git init --bare newrepo.git
建立路径认证,以允许用户组访问,同时有针对性的设置Git
?
1
2
3
4
5
cd newrepo.git
chown -R :grouprepo .
git config core.sharedRepository group
find . -type d -print0 | xargs -0 chmod 2770
find . -type f -print0 | xargs -0 chmod g=u
设置提交(commit)的email通知(commit是一条命令),这样当有新的修改提交到仓库的时候,开发者们将会收到一封关于修改内容一览的电子邮件。
?
1
2
3
4
5
6
7
echo 'One-line project description' >description
git config --local hooks.mailinglist [email protected]<script cf-hash="f9e31" type="text/javascript">
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */</script>,[email protected]<script cf-hash="f9e31" type="text/javascript">
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */</script>,...
git config --local hooks.emailprefix '[DI-PR] '
git config --local hooks.showrev "git show -C %s; echo"
git config --local hooks.emailmaxlines 100
通过设置一个称为钩子(hook)的东东,来创建这些email通知。

热点内容
安卓九彩蛋如何换颜色 发布:2024-04-27 16:10:36 浏览:504
安卓711如何打开隐藏彩蛋 发布:2024-04-27 16:04:53 浏览:813
写一个脚本让电脑按时自动关机 发布:2024-04-27 16:00:06 浏览:929
php框架排行2018 发布:2024-04-27 15:49:26 浏览:357
地下城与勇士怎么设置二级密码 发布:2024-04-27 15:36:17 浏览:946
headerjava 发布:2024-04-27 15:34:52 浏览:784
android进度条显示 发布:2024-04-27 15:34:49 浏览:351
怎么看组装机电脑配置 发布:2024-04-27 15:20:06 浏览:76
java交易系统 发布:2024-04-27 15:11:46 浏览:720
pythontkinter大小 发布:2024-04-27 14:51:22 浏览:115