说明:此处为仅仅为通过shell进行安装部署。
微信公众号 “云计算平台技术”
最终效果:
使用:
1.客户端采用http方式clone命令(密码:123456):
uri: http://10.127.26.91/git/cloudt-config-local.git
username: testuser
password: ******
2.客户端采用ssh协议(密码:rootroot):
git clone [email protected]:/opt/http_git/cloudt-config-local.git
(git clone ssh://[email protected]/opt/http_git/cloudt-config-local.git)
git push origin master
搭建过程:
linux以ssh,http方式搭建git服务器
用到apache和git-core(支持git的CGI)
1.安装httpd
yum install httpd
可以修改监听端口:
vi /etc/httpd/conf/httpd.conf
Listen为http的端口号
Listen 80
启动
service httpd start
如果打开浏览器访如果访问不了,则是因为防火墙
2.安装git
yum install git
yum install git-core
创建仓库:
mkdir -p /opt/http_git/cloudt-config-local.git
cd /opt/http_git/cloudt-config-local.git
git init --bare
// 设置权限
chown -R apache:apache /opt/http_git
3.创建账号:
htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd 123456
// 修改git-team.htpasswd文件的所有者与所属群组
chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
// 设置git-team.htpasswd文件的访问权限
chmod 777 /etc/httpd/conf.d/git-team.htpasswd
4.设置apache,使其请求转发到git-cgi:
vi /etc/httpd/conf/httpd.conf
// 在最后一行IncludeOptional conf.d/*.conf的上面添加下面内容:
<VirtualHost *:80>
ServerName 10.127.26.91
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是验证用户帐户的文件
保存重启:
service httpd restart
5.push失败可能出现的原因
git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码:
[receive]
denyCurrentBranch = ignore
修改目录及其子文件的权限
chmod -R 777 /opt/http_git