Operation and maintenance
  • 目录
  • linux 历史
    • Linux网卡配置
    • linux互相登陆
  • 文件目录管理
    • linux目录结构
    • 文件的基本信息
    • linux别名alias
    • 环境变量
    • linux终端相关快捷键
    • linux文件和目录添加删除
    • linux文件查看命令
    • linux文件目录权限
    • linux文件特殊权限
    • 链接文件
    • linux下文件查找
    • linux和window文件互传
    • linux文件压缩和打包
    • vim工具集
  • 用户和组管理
    • 用户组和用户管理
    • 修改组和用户
    • 用户切换
    • 禁止root远程登陆
  • linux磁盘管理
    • 磁盘分区
    • 格式化磁盘
    • 分区挂载
    • 手动添加swap分区
    • lvm基础
  • linux软件安装和卸载
    • rpm工具
    • yum工具
    • 源码安装包
  • 日常运维
    • 监控磁盘IO
    • 查看网络状态
    • linux抓包
    • linux网络相关
    • Linux防火墙-netfilter
    • linux任务计划
    • linux系统服务管理
    • linux同步工具rsync
    • linux系统日志和screen
  • LAMP架构
    • 安装mysql
    • 免编译安装mariadb
    • 安装apache
    • 安装php5
    • 安装php7
    • apache 配置虚拟主机
    • apache 用户认证
    • apache 域名跳转
    • apache 访问日志
    • apache 不记录文件日志
    • apache 配置静态元素过期时间
    • apache 配置防盗链
    • apache 访问控制
    • apache 禁止解析php文件
    • apache 禁止user_agent
    • php 配置文件
    • php 动态扩展模块安装
  • LNMP架构
    • 安装mariadb
    • 安装php
    • 安装nginx
    • nginx 默认虚拟主机
    • nginx 用户认证
    • nginx 域名重定向
    • nginx 访问日志
    • nginx 日志切割
    • nginx不记录指定文件类型日志
    • nginx 静态文件和过期时间
    • nginx 防盗链
    • nginx 访问控制
    • nginx 解析php
    • nginx 代理
    • nginx 负载均衡
    • nginx 支持https
  • MySQL集合
    • 更改root密码
    • mysql 常用操作
    • mysql 常用sql
    • mysql 数据备份
    • mysql 主从配置
  • linux常用服务
    • nfs 服务搭建
    • CentOS7 搭建snmp服务
    • ftp 服务搭建
    • samba 服务搭建
    • Squid 服务搭建
    • Tomcat 服务搭建
    • resin 搭建
    • dns 服务搭建
    • iscsi 服务搭建
  • linux开发语言环境
    • python 开发环境
    • golang 开发环境
  • linux集群架构
    • linux 高可用
    • linux 负载均衡
  • linux监控平台
    • zabbix 监控平台(上)
  • shell集合
  • NoSql
    • memcached (上)
    • memcached(下)
    • redis(上)
    • redis(中)
    • redis(下)
    • mongodb(上)
    • mongodb(中)
    • mongodb(下)
  • 代码管理工具
    • 代码管理工具 svn
    • 代码管理工具 git
    • 搭建git私有仓库
    • 安装配置gitlab
  • docker 入门
    • docker 安装
    • docker 镜像管理
    • docker 容器管理
    • docker 仓库管理
    • docker 共享目录
    • docker 数据备份和恢复
    • docker 网络管理
    • docker 使用dockerfile
    • docker compose
  • 自动化运维
    • saltstack 安装
    • saltstack 配置认证
    • saltstack 远程执行命令
    • saltstack grains
    • saltstack pillar
    • saltstack 实战:安装配置httpd
    • saltstack 实战:配置管理文件
    • saltstack 实战:配置管理远程命令
    • saltstack 实战:配置管理任务计划
    • saltstack salt-ssh工具
    • ansible 安装
    • ansible 远程命令
    • ansible 远程目录拷贝
    • ansible 任务计划
    • ansible 远程rpm/服务管理
    • ansible playbook 详解
    • ansible playbook 实战:安装nginx
  • linux虚拟化
    • KVM介绍
    • 安装KVM
    • 虚拟机管理
    • 克隆虚拟机
    • 快照管理
    • 磁盘扩容
    • 调整虚拟机配置
    • 迁移虚拟机
  • 错误排查
    • linux启动挂在不上sysroot问题
由 GitBook 提供支持
在本页
  • 前言
  • 搭建github私有仓库
  • 客户端使用

这有帮助吗?

  1. 代码管理工具

搭建git私有仓库

前言

github毕竟是公开的,而私有仓库又得花钱买。所以我们可以想办法搭建一个私有的,只自己公司使用的。

搭建github私有仓库

首先找一台能联网的服务器,安装相关的软件包

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

添加 git 用户并设置用户登陆:

[root@localhost ~]# useradd -s /usr/bin/git-shell git

设置 git 用户的 shell 的目的是为了不让 git 用户远程登陆

创建 authorized_keys 文件,并更改属主、属组和权限,用来存客户端机器上的公钥

[root@localhost ~]# cd /home/git/
[root@localhost ~]# mkdir .ssh
[root@localhost ~]# touch .ssh/authorized_keys
[root@localhost ~]# chown -R git.git .ssh
[root@localhost ~]# chmod 600 .ssh/authorized_keys

创建存储 git 代码的仓库

[root@localhost git]# mkdir /data/gitroot
[root@localhost git]# cd /data/gitroot/
[root@localhost git]#git init --bare sample.git 
# 会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,
# 所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾
[root@localhost git]# chown -R git.git sample.git

以上操作是在 git 服务器上做的,平时 git 服务器是不需要开发人员登录修改代码的,它仅仅是充当着一个服务器的角色,就像 github 一样,平时操作都是在我们自己的 pc 上做的。

客户端使用

首先要把客户端上的公钥放到 git 服务器上 /home/git/.ssh/authorized_keys 文件里

[root@localhost ~]# ssh-keygen -t rsa # 创建密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:
70:4f:c1:c0:4f:a9:82:8e:f2:ae:ae:c1:dc:a3:1f:f2 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|       ..o..     |
|        . +.     |
|     .. .+.      |
|    . .o.o.      |
|   o   .S .      |
|+ o .            |
|.* +             |
| .= o            |
|==oE             |
+-----------------+
[root@localhost ~]# scp ~/.ssh/id_rsa.pub 192.168.3.163:/home/git/.ssh/authorized_keys # 复制到远程 github 的服务器上
root@192.168.3.163's password: 
id_rsa.pub                                                                                        100%  408     0.4KB/s   00:00

在客户端上(自己pc)克隆远程仓库

[root@localhost tmp]# git clone git@192.168.3.163:/data/gitroot/sample.git
Cloning into 'sample'...
warning: You appear to have cloned an empty repository.
[root@localhost tmp]#

此时就可以在当前目录下生成一个sample的目录,这个就是我们克隆的远程仓库了。进入到这里面,可以开发一些代码,然后push到远程。

我们来操作试试:

进入目录下并写入内容

[root@localhost tmp]# cd sample/
[root@localhost sample]# ls
[root@localhost sample]# echo "test" >> 1.txt
[root@localhost sample]# ls
1.txt
[root@localhost sample]# cat 1.txt 
test

我们还要设置 git 的全局变量

[root@localhost sample]# git config --global user.name "Your name"        
[root@localhost sample]# git config --global user.email "Your@example.com"

我们提交修改并上传到仓库

[root@localhost sample]# git add 1.txt
[root@localhost sample]# git commit -m "add 1.txt"
[master (root-commit) e1c57f0] add 1.txt
 1 file changed, 1 insertion(+)
 create mode 100644 1.txt
[root@localhost sample]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 211 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.3.163:/data/gitroot/sample.git
 * [new branch]      master -> master
[root@localhost sample]#

我们来看看是否修改成功了

[root@localhost sample]# cd ../
[root@localhost tmp]# rm -fr sample/
[root@localhost tmp]# git clone git@192.168.3.163:/data/gitroot/sample.git
Cloning into 'sample'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@localhost tmp]# cd sample/
[root@localhost sample]# ls
1.txt
[root@localhost sample]# cat 1.txt 
test
[root@localhost sample]#

删除本机上的sample目录,再从仓库中克隆,发现和我们上交时相同,修改成功。github私有仓库搭建成功了。

上一页代码管理工具 git下一页安装配置gitlab

最后更新于4年前

这有帮助吗?