개요

github 나 gitlab 의 Enterprise 솔루션을 사용하지 않고 git 에 내장된 기능을 이용하여 간단하게 로컬 저장소를 구성해서 설정 파일을 git + ssh 로 관리하는 방법을 정리해 본다.

RHEL/CentOS 6 기준

git repositories 는 /var/lib/git 이라 가정한다.


SSH 로 연계

/var/lib/git 을 git repostories 로 활용한다.


master

  1. git central repository 서버(ex: www.example.org)에 root 로 로그인한후에 /var/lib/git 에 access 할 수 있는 계정을 설정한다. (Ex. lesstif)

    mkdir /var/lib/git
    setfacl -m u:lesstif:rwx /var/lib/git
    CODE
  2. root 에서 logoff 한후에 위에 설정한 계정으로 login 한다.
  3. git 디렉터리에 프로젝트를 생성한다. (bare 저장소에야 한다)

    git init --bare /var/lib/git/testprj.git
    CODE
  4. 생성한 빈 저장소를 작업 폴더로 clone 한다.

    git clone file:///var/lib/git/testprj.git 
    CODE

    file: 뒤에 / 가 세 개인 것에 주의!

    만약 이미 로컬에서 작업을 진행했다면 clone 하지 말고 git init 후에 remote 를 추가한다.

     git remote add origin file:///var/lib/git/testprj.git
    CODE
  5. 파일을 추가한다.
    1. vi hello.c

      hello.c

      #include <stdio.h>
       
      int main(int argc, char** argv)
      { 
         printf("Hello World\n");
         return 0;
      }
      CPP
  6. 커밋한다.

    git add hello.c
    git commit -m "hello.c 추가"
    CODE
  7. remote 에 push 한다.

    git push origin master
    CODE

second 서버

  1. clone 할 서버에 로그인한다.
  2. 다음 문법에 맞게 clone 한다. (SSH Port 가 22 번이 아닐 경우 b 번처럼 포트번호를 명시적으로 기술해줘야 한다.)
    1. git clone USERID@www.example.org:/var/lib/git/testprj.git
    2. git clone ssh://lesstif@www.example.org:1022/var/lib/git/testprj.git
  3. cd testprj
  4. git remote show origin 명령어로 git central server 를 확인한다.

    $ git remote show origin
    
    * remote origin
      Fetch URL: lesstif@www.example.org:/var/lib/git/testprj.git
      Push  URL: lesstif@www.example.org:/var/lib/git/testprj.git
      HEAD branch: master
      Remote branch:
        master tracked
      Local branch configured for 'git pull':
        master merges with remote master
      Local ref configured for 'git push':
        master pushes to master (up to date)
    BASH

Apache HTTP 로 연계

  1. git central server 에 root 로 로그인한다.
  2. gitweb package 를 설치한다.
    1. yum install gitweb -y

  3. git repository가 /var/lib/git 이므로 SELinux rule에 의해 apache httpd 는 읽을수 없다. git을 위해 추가된 context 인 httpd_git_content_t 를 설정한다. 
    1. chcon -R -t httpd_git_content_t /var/lib/git
  4. apache config 를 수정한다.
  5. 11
    1. cd /etc/httpd
    2. vi /etc/httpd/conf.d/git.conf
    3. vi /etc/httpd/conf/httpd.conf
      1. VirtualHost 항목에 다음 내용 추가

        <VirtualHost *:80>
                ServerName www.example.org
        #       conf.d/의 모든 conf 를 loading 하므로 아래 구문 불필요
        #        Include conf.d/git.conf
         
        		ServerAdmin lesstif@example.org
        		ErrorLog logs/gitserver-error_log
                CustomLog logs/gitserver-access_log common
        </VirtualHost >
        CODE
    4. vi /etc/httpd/conf/gitpasswd
  6. git client 에 로그인한다.
  7. cloning
    1. git clone http://lesstif@www.example.org/git/testprj

  8. git remote show origin 으로 정상 설정 여부를 확인한다.


See Also


Ref


daemon