• centos8平台安装gitosis服务


    一,git服务器端:准备gitosis需要的各依赖软件

    1,确认openssh是否存在?如不存在,以下列命令进行安装

    [root@yjweb ~]# yum install openssh openssh-server openssh-clients

    2,安装git

    [root@yjweb ~]# yum install git

    判断git是否安装成功?

    [root@yjweb ~]# git --version
    git version 2.18.2

    3,安装python工具

    [root@yjweb ~]# yum install -y python2 python2-setuptools

    检查python的setuptools是否安装成功?

    [root@yjweb gitosis]# python2 -c "import setuptools"  

    如无任何输出,表示安装成功

    如有报错输出,表示安装失败

    说明:此处要使用python2

    因为gitosis的初始化需要python2,

    如果使用python3会报错

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

     说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,git服务器端:创建git服务专用管理用户

    1,创建git用户

    [root@yjweb ~]# groupadd git
    [root@yjweb ~]# useradd -g git git
    [root@yjweb ~]# grep git /etc/passwd
    git:x:1003:1003::/home/git:/bin/bash

    2,确保git用户对git目录有写入权限

    [root@yjweb ~]# chown git:git /home/git
    [root@yjweb ~]# ll /home/ | grep git
    drwx------ 2 git   git    62 Mar  9 17:00 git

    三,git服务器端:安装gitosis

    1,克隆gitosis这个项目到本地的source文件夹

    [root@yjweb source]# git clone https://github.com/res0nat0r/gitosis.git
    Cloning into 'gitosis'...
    remote: Enumerating objects: 734, done.
    remote: Total 734 (delta 0), reused 0 (delta 0), pack-reused 734
    Receiving objects: 100% (734/734), 147.40 KiB | 29.00 KiB/s, done.
    Resolving deltas: 100% (458/458), done.

    2,安装

    [root@yjweb source]# cd gitosis/
    [root@yjweb gitosis]# python2 setup.py install

    说明:此处要使用python2

    因为gitosis的初始化需要python2,

    如果使用python3会报错

    说明:如果看到下面的提示表示安装成功

    Finished processing dependencies for gitosis==0.2

    四,git服务器端:生成.ssh目录及授权文件:

    [root@yjweb ~]# mkdir -p /home/git/.ssh
    [root@yjweb ~]# chmod 700 /home/git/.ssh
    [root@yjweb ~]# touch /home/git/.ssh/authorized_keys
    [root@yjweb ~]# chown git.git -R /home/git

    说明:authorized_keys文件用来供gitosis保存项目中的公钥

    五,开发机客户端:生成密钥并上传到服务器上

    说明:我们的开发机客户端,是一台运行ubuntu 19.10的机器

    1,创建ssh密钥

    说明:此处的客户端是一台ubuntu机器

    root@kubuntu:~# ssh-keygen -t rsa

    操作中一路回车即可,无需输入密码

    2,检查密钥对是否生成

    完成后可以从.ssh目录下看到生成的密钥对

    root@kubuntu:~# ls .ssh/
    id_rsa  id_rsa.pub  known_hosts

    其中 id_rsa.pub 是我们所要使用的公钥

    3,把生成的公钥上传到git服务器

    用scp或ftp工具,把id_rsa.pub复制到git服务器上

    放到/tmp目录下

    此处假设git服务器的ip地址是:123.124.125.126,端口地址是12345

    root@kubuntu:~# scp -P 12345 .ssh/id_rsa.pub sysop@123.124.125.126:/tmp/
    sysop@123.124.125.126's password: 
    id_rsa.pub                                                 100%  566    70.3KB/s   00:00

    六,git服务器端: 初始化gitosis

    1,切换到git账号,查看客户端上传的公钥是否存在?

    [root@yjweb ~]# su git
    [git@yjweb root]$ ll /tmp/id_rsa.pub
    -rw-r--r-- 1 sysop sysop 566 Mar  9 18:46 /tmp/id_rsa.pub 

    2,初始化gitosis项目

    [git@yjweb root]$ gitosis-init < /tmp/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/

    3,初始化到底都做了哪些工作?

    创建了一个gitosis目录和一个库目录

    [git@yjweb ~]$ ls
    gitosis  repositories

    在.ssh目录下的authorized_keys中写入了id_rsa.pub的内容

    [git@yjweb ~]$ cd .ssh
    [git@yjweb .ssh]$ more authorized_keys
    ### autogenerated by gitosis, DO NOT EDIT
    command="gitosis-serve root@kubuntu",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2E
    ...

    七,开发机客户端:克隆gitosis-admin项目

    root@kubuntu:~# git clone ssh://git@123.124.125.126:12345/gitosis-admin.git
    正克隆到 'gitosis-admin'...
    remote: Enumerating objects: 5, done.
    remote: Counting objects: 100% (5/5), done.
    remote: Compressing objects: 100% (4/4), done.
    remote: Total 5 (delta 0), reused 0 (delta 0)
    接收对象中: 100% (5/5), 完成.

    可以看到gitosis-admin这个项目已下载到客户端的机器本地

    root@kubuntu:~# ls
    gitosis-admin  node_modules  package.json  work

    八,客户端查看gitosis-admin项目的remote设置

    root@kubuntu:~/gitosis-admin# git remote -v
    origin  ssh://git@123.124.125.126:12345/gitosis-admin.git (fetch)
    origin  ssh://git@123.124.125.126:12345/gitosis-admin.git (push)

     

    九,查看本地centos的版本

    [webop@yjweb ~]$ cat /etc/redhat-release
    CentOS Linux release 8.0.1905 (Core) 

    十,gitosis的使用  

    参见这一篇:centos8上使用gitosis管理git项目
    地址:https://www.cnblogs.com/architectforest/p/12457035.html
  • 相关阅读:
    CICD : 存代码部署(精简版)
    CICD:通过Shell 将打包后的代码部署到各环境
    linux:curl 取得HTTP返回的状态码
    闭包简单的了解
    javascript正则表达式了解
    搭建PHP开发环境(四)-PHP操作MySQL
    搭建PHP开发环境(三)-MySQL安装配置
    搭建PHP开发环境(二)-PHP安装
    搭建PHP开发环境(一)-Apache安装配置
    生成简单验证码文字
  • 原文地址:https://www.cnblogs.com/architectforest/p/12456655.html
Copyright © 2020-2023  润新知