必要なパッケージをインストール
# yum install -y httpd git
httpd設定ファイル作成
# cd /etc/httpd/conf.d/
# vi git.conf
git.conf
SetEnv GIT_PROJECT_ROOT /var/lib/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
<LocationMatch "^/git/">
Require all granted
</LocationMatch>
ファイアウォールの設定
# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
Gitリポジトリ作成
# mkdir /var/lib/git
# cd /var/lib/git
# git init --bare --shared test.git
# cd test.git
# git update-server-info
# git config http.receivepack true
# mv hooks/post-update.sample hooks/post-update
# chown -R apache.apache /var/lib/git
SELinux設定
# semanage fcontext -a -t httpd_var_lib_t '/var/lib/git(/.*)?'
# semanage fcontext -a -t httpd_sys_script_exec_t '/var/lib/git/[^/]+/hooks(/.*)?'
# restorecon -v -R /var/lib/git
SELinuxについて
- https://milestone-of-se.nesuke.com/sv-advanced/selinux/chcon-restorecon-semanage-fcontext/
- https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/managing_confined_services/sect-managing_confined_services-the_apache_http_server-types
サービス設定
# systemctl enable httpd
# systemctl start httpd
アクセス
# git remote add origin http://git-server/git/test.git
# git push --set-upstream origin master
# git clone http://git-server/git/test.git