CentOS 7+Git+Gitosisインストール導入

11745 ワード

文書ディレクトリ
  • 一、Gitの初期化:
  • 二、Gitosis管理を増やし、チーム化作戦
  • を便利にする
  • 三、Gitosisインストールと初期化
  • 4、既存のgitコードを自分のgitサーバ
  • に移行する方法
  • 五、エラー関連:
  • 1、fatal: This operation must be run in a work tree
  • 2、fatal: refusing to merge unrelated histories

  • 六、最後に書く:

  • 導入のニーズ:多くの場合、企業プロジェクトのメンテナンス性を考慮して、みんなはやはり自分のコードバージョンライブラリを持ちたいと思っています.github、giteeは良い選択ですが、これらのプラットフォームに完全に依存して、コードの安全性に対していつも疑問を持っていて、自分のチームのバージョン管理の成長にも不利です.giteeエンタープライズ版では今日もちょっとした問題が発生し、ログイン後に500エラーが発生しました.そこでgitサーバの自己構築計画を実行することを考えた.
    導入環境:
  • システムバージョン:CentOS 7.5
  • Gitバージョン:1.8.3.1
  • Gitosisバージョン:2.2元参照リンク
  • 一、Gitの初期化:
  • ダウンロードGit
  • # yum install git -y
      :             ,             ,yum      ,               ,      yum    git。
    
    # git --version
    git version 1.8.3.1
    
  • gitユーザグループおよびgitユーザ
  • を作成する.
    # groupadd git
    # adduser git -g git
    # passwd
      :      adduser git,          git  ,               
      2:passwd   ,      ,   git      
    
  • git作業ディレクトリ
  • を作成する
    # mkdir -p /home/git/.ssh
    # chmod 700 /home/git/.ssh
    # chown -R git:git /home/git
      :  -p   mkdir      
    

    二、Gitosis管理を増やし、チーム化作戦を便利にする
    注意:本教育はgitが直接サーバーを構築する実践の一環を無視し、Gitosisの管理に重点を置いている.ちなみにgitがサーバとして機能する3つの欠点をまとめます.
    1、git cloneのリモートgitパスは、フルパスであり、相対的に記憶が困難である.2、ユーザーの追加は/home/git/.ssh/authorized_を修正するkeys、人員が増えてメンテナンスが面倒になります.3、この問題はもっと重要だと思います.git倉庫ではマルチプロジェクトの権限制御ができず,人員を増やすと全プロジェクトのコードアクセス権限が自動的に取得される.
    上記の問題を解決するためにGitosisが誕生した.Gitosisは主に2つの問題を解決します.
    1、相対パス問題2、プロジェクトのグループ管理と人員授権アクセス問題
    三、Gitosisのインストールと初期化
  • python依存インストール#yum install python-setuptools-y
  •         :{
        {
        {
    1.1 (  )         ,             
    Installed /usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg
    Traceback (most recent call last):
      File "setup.py", line 64, in 
        'setuptools>=0.6c5',
      File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
        dist.run_commands()
      File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 73, in run
        self.do_egg_install()
      File "/usr/lib/python2.7/site-packages/setuptools/command/install.py", line 101, in do_egg_install
        cmd.run()
      File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 380, in run
        self.easy_install(spec, not self.no_deps)
      File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 604, in easy_install
        return self.install_item(None, spec, tmpdir, deps, True)
      File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 655, in install_item
        self.process_distribution(spec, dist, deps)
      File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 701, in process_distribution
        distreq.project_name, distreq.specs, requirement.extras
    TypeError: \__init__() takes exactly 2 arguments (4 given)
    

    検索後、yumがインストールしたsetuptoolsバージョンが間違っていることを確認します.
    \# ll /usr/lib/python2.7/site-packages/
    > drwxr-xr-x   5 root root   4096 Mar  4 23:29 setuptools
    drwxr-xr-x   2 root root   4096 Mar  4 23:29 setuptools-0.9.8-py2.7.egg-info
    -rw-r--r--   1 root root 793874 Mar  5 00:10 setuptools-33.1.1-py2.7.egg
    drwxr-xr-x   2 root root   4096 Nov 29 11:40 setuptools-36.4.0.dist-info
    -rw-r--r--   1 root root     30 Mar  5 00:10 setuptools.pth
    

    ネット上の解決策は、このディレクトリの下にあるすべてのsetuptoolsフォルダを削除し、#yum remove python-setuptools-y#rm/usr/lib/python 2.7/site-packages/setuptool*-rfを再インストールすることです.
    pipでsetuptools#wgetを再インストールhttps://bootstrap.pypa.io/ez_setup.py
    Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.228.175, 2a04:4e42:36::175
    Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.228.175|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 12537 (12K) [text/x-python]
    Saving to: ‘ez_setup.py’
    
    100%[=============================================================================================================>] 12,537      --.-K/s   in 0.07s
    
    #  python ez_setup.py
    ez_setup.py is deprecated and when using it setuptools will be pinned to 33.1.1 since it's the last version that supports setuptools self upgrade/installation, check https://github.com/pypa/setuptools/issues/581 for more info; use pip to install setuptools
    Downloading https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
    Extracting in /tmp/tmpi_jCtH
    Now working in /tmp/tmpi_jCtH/setuptools-33.1.1
    ...
    Installed /usr/lib/python2.7/site-packages/setuptools-33.1.1-py2.7.egg
    Processing dependencies for setuptools==33.1.1
    Finished processing dependencies for setuptools==33.1.1
    
    # easy_install-2.7 pip
    Searching for pip
    Best match: pip 18.1
    Adding pip 18.1 to easy-install.pth file
    Installing pip script to /usr/bin
    Installing pip3.7 script to /usr/bin
    Installing pip3 script to /usr/bin
    Using /usr/lib/python2.7/site-packages
    Processing dependencies for pip
    Finished processing dependencies for pip
    
    # pip2.7 install --upgrade pip
    Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
    Collecting pip
      Downloading http://mirrors.aliyun.com/pypi/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
        100% |████████████████████████████████| 1.4MB 73.7MB/s
    Installing collected packages: pip
      Found existing installation: pip 18.1
        Uninstalling pip-18.1:
          Successfully uninstalled pip-18.1
    Successfully installed pip-19.0.3
    
    # rm /usr/lib/python2.7/site-packages/setuptool* -rf
    # python -m pip install --upgrade pip setuptools wheel
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
    Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
    Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages (19.0.3)
    Collecting setuptools
      Downloading http://mirrors.aliyun.com/pypi/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-40.8.0-py2.py3-none-any.whl (575kB)
        100% |████████████████████████████████| 583kB 52.2MB/s
    Collecting wheel
      Downloading http://mirrors.aliyun.com/pypi/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
    Installing collected packages: setuptools, wheel
      Found existing installation: wheel 0.29.0
        Uninstalling wheel-0.29.0:
          Successfully uninstalled wheel-0.29.0
    Successfully installed setuptools-40.8.0 wheel-0.33.1
    

    最後にsetuptools-40.8.0というバージョンで再実行#python setup.py installインストール成功}}
  • 初期化Gitosis準備作業:ftpまたは他のIDを使用してrsa.pub,ssh公開鍵ファイルアップロードgitサーバ,仮定位置/tmp/id_rsa.pub. そしてさっきのGitosisソースディレクトリの下で
  • # su - git
    # gitosis-init < /tmp/id_rsa.pub
    # cd ~
    # ll 
    total 0
    drwxr-xr-x 2 git git  27 Jan 28 01:28 gitosis
    drwxr-xr-x 8 git git 124 Jan 28 01:37 repositories
      ::      ,           ,          root   ,   chown -R git:git /home/git/
    

    まとめてみると、PythonでGitosisをインストールした環境利用/tmp/id_rsa.pubはGitosisのアカウントを管理するすべての真実を初期化しました/home/git/.ssh/authorized_keysは後で知った.vi/home/git/.ssh/authorized_keysさっき私たちに清算されたauthorizedが見えますkeysファイルにidがインポートされましたrsa.pubの内容ですが、私たち自身の書き込みとは違います###autogenerated by gitosis,DO NOT EDIT command="gitosis-serveユーザー名",no-port-forwarding,no-X 11-forwarding,no-agent-forwarding,no-pty ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • 管理GitosisさっきGitosisをインストールした後、/home/gitの下に2つのディレクトリ#ll total 0 drwxr-xr-x 2 git git 27 Jan 28 01:28 gitosis drwxr-xr-x 8 git git 124 Jan 28 01:37 repositories
  • 重要なディレクトリは1つのrepositoriesしかありません.これには、後で私たちのすべてのプロジェクトのgit倉庫ファイルが格納されています.
    # cd /home/git/repositories
    # ll
    total 0
    drwxr-x--- 7 git git 139 Jan 28 01:28 gitosis-admin.git
    

    現在、このディレクトリの下にはgitosis-admin.gitというフォルダしかありません.これがGitosisが持っている管理ツールです.次に、このツールcloneをローカルに移動して、Gitos clone Gitos-adminを管理する必要があります.さっきidを取得しました.rsa.pubのパソコンは、普通はあなたのワークマシンでしょう.git clone git@サーバIP:/gitosis-admin.git
    sshポート番号が変更された場合ssh://git@サーバIP:sshポート番号/gitosis-admin.git
    備考1:気づきましたか?gitosis-admin.gitはフルパスを使用して取得されていません.上記のコマンドを正常に実行した場合は、git倉庫にアクセスするために相対パスを使用できることを示します.注釈2:エラーが発生した場合:fatal:'/gitosis-admin.git'does not appear to be a git repository、つまり相対パスが有効ではありません.なぜなら、あなたが空になっていない可能性があるからです./home/git/.ssh/authorized_keys、このファイルにGitosis規格ではない公開鍵構成が存在し、Gitosisエラーを起こしました.方法はauthorized_を削除することですkeys、さっきGitosisをインストールしたときの5歩目を歩いて、彼を再初期化して、普通の問題は解決しました.cloneは成功しました.gitosis-adminでGitosisとGitを管理することができますか?原理:gitosis-adminはgitosis.confによってプロジェクトグループ、ユーザーグループと権限関係を構成し、keydirディレクトリによってユーザーの公開鍵を保存し、gitコミットによってGitosisサービス構成の更新メンテナンスを実現する.
    gitosis-adminのディレクトリ#dir 2019/01/28 01:15.2019/01/28 01:15...2019/01/28 01:22 365 gitosis.conf 2019/01/28 01:21 keydir
    gitosis.confを編集し、プロジェクトとユーザー管理を実現
    [gitosis]
    
    // gitosis-admin        
    [group gitosis-admin]
    writable = gitosis-admin  //         
    members = Administrator  //      keydir    pub         ,    keydir          Administrator.pub    
    //               ,                       
    [group developer]
    members = tom Jams KK //    ,       
    [group tester]
    members = miya lucy lily //   ,       
    //       
    [group test1]
    writable = test1 //         
    members = @developer //                     。
    [group test1_readonly]
    readonly = test1 //     
    members = @tester Jack //         Jack         ,  Gitosis               。
    

    小結は上記の仕事を通じて、Gitosis管理Gitサーバーを完成しました.GitosisはGit自身を利用してGitサーバを制御する目的を非常に巧みに実現した.
    四、既存のgitコードを自分のgitサーバに移行する方法
    この部分は多くの人が経験を持っていると思いますが、私はやはり記録して、この経験をまとめて、みんなが見やすいようにします.ローカルコードの変更をタイムリーにキャッシュしgit bashでコマンドを使用
    # git add .
    # git commit -m "init own git server"
    
     git          
    # cd /home/git/repositories
    # mkdir    .git
    # cd    .git
    # git init --bare
    
      Gitosis        
    # vi gitosis-admin/gitosis.conf
    

    コンテンツをに編集
    [gitosis]
    
    [group gitosis-admin]
    members = administrator
    writable = gitosis-admin
    
    [group common]
    members = Jack
    
    [group    ]
    members = @common
    writable =    
    
    

    変更のコミット
    # cd gitosis-admin
    # git add .
    # git commit -m "    "
    # git push
    

    備考:ここまで、倉庫名.gitはJackのアカウントでリモート更新とアップロードができます.ローカルコードのgit remoteを変更しgitサーバにコードをアップロード
    # git remote remove origin
    # git remote add origin ssh://git@   IP:ssh  /   .git
    # git push -u origin master
    # git pull
    # git branch --set-upstream-to=origin/master master
    # git pull
    
      ,Jack      git            。
    

    完了
    五、誤報関連:
    1、fatal: This operation must be run in a work tree
    説明:ディレクトリを初期化するときに使用するコマンドは#git init--bareが表す裸のライブラリの意味なので、このサーバでgit add commitの操作を行うことはできません.あなた自身がMasterなので、操作すると衝突します.だからサーバのこの倉庫はコミットバージョンの情報を保持するだけです.リファレンスリンク1リファレンスリンク2
    2、fatal: refusing to merge unrelated histories
    説明:元のローカルウェアハウスにあるファイルの名前を変更したため、再度コミットするときに選択したときにエラー(コミットまたはプルのどちらかが見つからない)を報告し、現在のディレクトリでgit bashを開いてコマンド#git pull--allow-unrelated-historiesを使用すればリンクを参照できます.
    六、最後に書く:
    注:1、 git , Gitosis、windowsコードを引くときはgit bash 3、その後TortoiseGitのツールを使うときはこのメモ4、windowsのあるこのクローンディレクトリgitosis-adminをwindowsで修正したほうがいいです.サーバーにも裸の倉庫があるからです.(keydir、gitosis.confプロファイルがクローン化されている理由については、gitosisが持参した下位層である必要があります)詳細