Linux git服务器http方式搭建

来源:互联网 发布:matlab读取数据和文件 编辑:程序博客网 时间:2024/05/01 12:21
Git访问方式:基于http的基本验证(非SSL)
Apache的安装
1. 安装Apache软件:yum install httpd
2. 设置Apache在服务器启动时运行:chkconfig --levels 235 httpd on
Git的安装与配置
1. 安装git

yum install git


2. 安装 git-core(为了使用git-http-backend——支持git的CGI程序,apache支持git就靠它)

yum install git-core


3. 创建存放git repository的文件夹,比如这里是/gitServer

mkdir gitServer && cd gitServer


4. 创建一个空的项目
cd gitServer
 git init --bare sample.git


5. 修改上一步创建的文件夹gitServer的所有者与所属群组,要让apache能读/写这个文件夹

chown -R apache:apache .


chown命令使用帮助:每天一个linux命令(30): chown命令
Apache的配置
1. 创建用于git用户验证的帐户(用户帐户由apache管理)
1.1 创建新用户

htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>
示例  htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd zhangcheng


然后输入该用户要使用的密码。
1.2 修改git-team.htpasswd文件的所有者与所属群组

chown apache:apache /etc/httpd/conf.d/git-team.htpasswd


1.3 设置git-team.htpasswd文件的访问权限

chmod 640 /etc/httpd/conf.d/git-team.htpasswd


chmod命令使用帮助:每天一个linux命令(27):linux chmod命令
2. 修改apache配置文件httpd.conf
2.1 用vim打开httpd.conf:vi /etc/httpd/conf/httpd.conf
2.2 将光标移至文件结尾:0G
2.3 添加如下的内容:



<VirtualHost *:80>        ServerName git.cnblogs.com        SetEnv GIT_HTTP_EXPORT_ALL        SetEnv GIT_PROJECT_ROOT /gitServer        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服务器的域名
/home/git是代码库存放的文件夹
ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend
AuthUserFile是验证用户帐户的文件
2.4 保存并退出:x
3. 重启apache使设置生效

service httpd restart


客户端访问Git服务器
运行以下命令签出git-test项目:

git clone http://<username>:<password>@git.cnblogs.com/git/sample.git[/code] 
示例 http://zhangcheng:dancheng51@192.168.8.200/git/sample.git
如果访问不到注意80端口是否开启
重启防火墙 service iptables restart输入用户名与密码,如果输出下面的信息,就说明签出成功。
remote: Counting objects: 6, done.remote: Compressing objects: 100% (4/4), done.remote: Total 6 (delta 0), reused 0 (delta 0)Unpacking objects: 100% (6/6), done.
htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>
0 0
原创粉丝点击