您当前的位置: 首页 >  服务器

庄小焱

暂无认证

  • 1浏览

    0关注

    805博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

GItlab——构建公司局域网git服务器集群

庄小焱 发布时间:2020-12-18 16:57:58 ,浏览量:1

1.安装git  并修改sshd配置文件
# yum -y install git

# git --version
# vim /etc/ssh/sshd_config  #修改配置文件允许通过密钥认证
RSAAuthentication yes
 
PubkeyAuthentication yes
 
AuthorizedKeysFile      .ssh/authorized_key
2.添加用户并修改仓库属组和属主
# useradd git # 添加用户(clone和push的时候都是必要的),注意这里要和你未来web服务器的名字要相同,如果不是做web服务器用的可以随便取名字

# passwd git# 添加密码(设置每一个人登入的密码)

# chown -R git:git /path/to/projectDir/    # 修改仓库的属组和属主(一定要设置 否则不能push 后面是的项目的路径)
3.选定一个目录作为git仓库假定是/home/test.git,在/home目录下输入命令:
 git init --bare sample.git
4.客户端生成密钥
$ download https://git-scm.com/download/win  #在windows下下载git客户端

$ 安装、右键打开Git Bash

$ ssh  git@gitserverIp   #ssh连接你的web服务器,如ssh git@10.10.12.12, 这里是git是你刚刚添加的用户。

输入yes

这里需要输入yes,是ssh的安全机制,用于首次通信,第二次连接就不会有了,此时C:\Users\用户\.ssh 多出一个known_hosts文件

$ ssh-keygen -t rsa #生成公钥和密钥,此时 C:\Users\用户\.ssh\会多出两个文件id_rsa.pub和id_rsa.pub,公钥和私钥,复制id_rsa.pub内容
5.复制本地公钥到服务器
# mkdir -p /home/git/.ssh  #由配置文件我们把认证信息放到了用户家目录下的.ssh文件夹中,www为刚刚添加的用户

# vim  /home/git/.ssh/authorized_keys  #粘贴你刚刚复制的id_rsa.pub内容

# chmod 700 /home/git/.ssh/ #为了保证安全性,需要修改权限

# chmod 600 /home/git/.ssh/authorized_keys #修改文件权限

# usermod -s /usr/bin/git-shell git#不允许该用户登录,只能做git操作

如果想要简洁操作可以在Windows git bash上使用这个命令:

ssh-copy-id -i  /c/Users/用户名/.ssh/id_rsa.pub  git@11.11.12.12

linux也可以使用上面这条命令或者执行

# ssh-keygen  //生成linux的公钥和私钥   /root/.ssh目录下面 

# ls
authorized_keys(公钥)  id_dsa  known_hosts  将公钥拷贝到到服务器的/home/git/.ssh/authorized_keys
# git clone git@192.168.0.246:/disk/git/test.git     从服务器克隆
Initialized empty Git repository in /root/.ssh/test/.git/
The authenticity of host '192.168.0.246 (192.168.0.246)' can't be established.
RSA key fingerprint is 8f:17:75:e3:1b:8b:91:0b:91:62:e1:a3:02:8d:83:ff.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.246' (RSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.(第一次是空的还没放文件呢)

更新版本

# git add .
# git commit -m "first commit"             //注释
[master (root-commit) 69e2d7a] first commit
 Committer: root 
Your name and email address were configured automatically based      //linuc用户会自动注册email和用户 
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"     或使用这2条命令 在windows下需要执行 不然会报错   
    git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name '

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 1.test
# git remote add gitserv git@192.168.0.246:/disk/git/test.git     给远程服务器起个别名 
# git push -u gitserv master   上传 

注意:如果有多个人员参与,每个人的公钥都要追加到authorized_keys里面,ssh-copy-id命令会自动创建.ssh文件夹和追加公钥到authorized_keys文件里

6: tortoiseGit来管理项目(可选)
$ download

https://download.tortoisegit.org/tgit/2.4.0.0/TortoiseGit-2.4.0.2-64bit.msi #

https://download.tortoisegit.org/tgit/2.4.0.0/TortoiseGit-LanguagePack-2.4.0.0-64bit-zh_CN.msi #官方汉化工具

$ 在项目文件上,右键

URL:git@11.11.12.12:/path/to/projectDir/
7:备份git仓库

假设已有git仓库git@10.22.52.217:/srv/autoltp.git

1.进入备份的目的机器目录

cd /home/aouyang/work/autoltp

2. 备份

git clone --mirror git@10.22.52.217:/srv/autoltp.git

3. 如果已有备份,则更新备份

git remote update

4. 编写定时备份

a. touch ltp-backup.sh

#!/bin/bash

cd /home/aouyang/work/autoltp_backup/autoltp.git/

git remote update

cd -

b. crontab -e

写入如下定时器任务: 每周六8点整,定时执行ltp-backup.sh文件

并向多个服务集群中的进行的定时的备份工作。

关注
打赏
1657692713
查看更多评论
立即登录/注册

微信扫码登录

0.0390s