Centos7 以http方式搭建git服務器 apache+git


用到apachegit

第一步,安裝httpdgit

yum install git httpd

第二步,啟動httpd服務

systemctl start httpd.service

第三步修改firewalld配置文件和重啟firewalld

firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service

第四步,創建git倉庫

mkdir -p /opt/http_git/test.git
cd /opt/http_git/test.git
git init --bare

//設置權限
chown -R apache:apache /opt/http_git

第五步,創建賬號

// testuser為賬戶名 可以隨意定義
htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd testuser
 
// 修改git-team.htpasswd文件的所有者與所屬群組
chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
 
// 設置git-team.htpasswd文件的訪問權限
chmod 640 /etc/httpd/conf.d/git-team.htpasswd

第六步,設置apache,使其請求轉發到git-cgi:

vi /etc/httpd/conf/httpd.conf
 
// 在最后一行IncludeOptional conf.d/*.conf的上面添加下面內容:
<VirtualHost *:80>
        ServerName 192.168.1.55
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv GIT_PROJECT_ROOT /opt/http_git
        ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
        <Location />
                AuthType Basic
                AuthName "Git"
                AuthUserFile /etc/httpd/conf.d/git-team.htpasswd
                Require valid-user
        </Location>
</VirtualHost>
 
///
ServerName是git服務器的域名,這里最后填寫你機子的IP
/opt/http_git是代碼庫存放的文件夾
ScriptAlias是將以/git/開頭的訪問路徑映射至git的CGI程序git-http-backend
AuthUserFile是驗證用戶帳戶的文件

第七步,重啟httpd

systemctl restart httpd.service

之后就可以進行clone

git clone http://server/git/test.git

如何出現push權限被禁止的話,需要關閉selinux

//查看selinux狀態
getenforce

//臨時關閉selinux
setenforce 0

//永久關閉selinux
vi /etc/sysconfig/selinux
//將SELINUX=enforcing改為SELINUX=disabled
//重啟服務器即可

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM