CentOS 7에서 Git 소스 컴파일 설치 및 서버 설정 가이드

Git 설치 전 준비 사항

CentOS 7.9 환경에서는 기본 패키지 매니저를 통해 제공되는 Git 버전이 낮아, 최신 기능을 사용하기 위해 소스 컴파일 방식으로 설치해야 합니다. 특히 2.46 이상 버전은 libcurl 7.30.0 이상 필요하며, 커널 업그레이드도 고려해야 할 수 있습니다.

의존성 패키지 설치

[root@localhost ~]# dnf -y install dnf
[root@localhost ~]# dnf -y install dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel
[root@localhost ~]# yum -y remove git
[root@localhost ~]# dnf -y install asciidoc xmlto docbook2X

libcurl 업그레이드 (필수)

기본 libcurl 버전(7.29.0)은 최신 Git 소스 빌드에 부족합니다. 다음처럼 libcurl 8.18.0을 소스로 컴파일 설치하세요.

[root@localhost ~]# tar xvf curl-8.18.0.tar.gz
[root@localhost ~]# cd curl-8.18.0
[root@localhost curl-8.18.0]# ./configure --prefix=/usr/local/curl-8.18.0 --with-ca-bundle=/etc/pki/tls/certs/ca-bundle.crt
[root@localhost curl-8.18.0]# make && make install

Git 소스 컴파일 및 설치

[root@localhost ~]# tar xvf git-2.49.1.tar.xz
[root@localhost ~]# cd git-2.49.1
[root@localhost git-2.49.1]# ./configure --prefix=/usr/local/git-2.49.1 --with-curl=/usr/local/curl-8.18.0
[root@localhost git-2.49.1]# ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
[root@localhost git-2.49.1]# make all doc info
[root@localhost git-2.49.1]# make install install-doc install-html install-info

환경 변수 등록

[root@localhost git-2.49.1]# echo 'export PATH=/usr/local/git-2.49.1/bin:$PATH' >> /etc/profile
[root@localhost git-2.49.1]# source /etc/profile
[root@localhost git-2.49.1]# git --version
git version 2.49.1

Git 서버 사용자 생성 및 권한 설정

[root@localhost ~]# groupadd git
[root@localhost ~]# useradd git -g git
[root@localhost ~]# passwd git
[root@localhost ~]# su - git
[git@localhost ~]$ mkdir .ssh
[git@localhost ~]$ chmod 700 .ssh
[git@localhost ~]$ touch .ssh/authorized_keys
[git@localhost ~]$ chmod 600 .ssh/authorized_keys
[git@localhost ~]$ vim .ssh/authorized_keys
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAA... (공개키 내용)

SSH 제한된 접근 강제 적용

[root@localhost ~]# which git-shell
/usr/bin/git-shell
[root@localhost ~]# echo '/usr/bin/git-shell' >> /etc/shells
[root@localhost ~]# chsh git -s /usr/bin/git-shell

HTTP 프로토콜 통신을 위한 Apache 구성

[root@localhost ~]# dnf -y install httpd httpd-tools
[root@localhost ~]# mkdir -p /srv/git
[root@localhost ~]# vim /etc/httpd/conf.d/git.conf
Listen 8989

SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<Directory "/usr/libexec/git-core">
    <Files "git-http-backend">
        AuthType Basic
        AuthName "Git Access"
        AuthUserFile /srv/git/.htpasswd
        Require expr !(%{QUERY_STRING} -strmatch '*service=git-receive-pack*' || %{REQUEST_URI} =~ m#/git-receive-pack$#)
        Require valid-user
    </Files>
</Directory>

<Directory "/srv/git">
    Options +ExecCGI
    AllowOverride None
    Require all granted
</Directory>

[root@localhost ~]# systemctl restart httpd

사용자 계정 및 저장소 생성

[root@localhost ~]# htpasswd -c /srv/git/.htpasswd testuser
[root@localhost ~]# cd /srv/git
[root@localhost git]# git init --bare my_project.git
[root@localhost git]# touch my_project.git/git-daemon-export-ok
[root@localhost git]# chgrp -R apache /srv/git
[root@localhost git]# chmod -R g+w /srv/git

클라이언트 테스트

$ git clone http://192.168.142.101:8989/git/my_project.git
$ cd my_project
$ echo "test" > file.txt
$ git add .
$ git commit -m "first commit"
$ git push
Enter username and password for HTTP authentication...

태그: CentOS Git SSH HTTP Apache

7월 18일 03:11에 게시됨