Ubuntu 下 Git 服务器的安装和初级配置

操作环境:Ubuntu 10.04 LTS
安装前提条件,已经安装 apache 服务器或者同类服务器、openssh-service,并且已经熟悉使用 Git 客户端

----- 安装 Git ----------------------------------------------------------------------------------------------------------------------------------------------------------------

sudo apt-get install git-core

----- 安装 gitosis -----------------------------------------------------------------------------------------------------------------------------------------------------------

注:Gitosis 是方便通过 Git 与 ssh 架设中央服务器的软件。
更详细步骤参见:http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

安装 python setuptools,为安装 gitosis 做准备

sudo apt-get install python-setuptools

安装 Gitosis

cd /tmpgit clone git://eagain.net/gitosis.gitcd gitosissudo python setup.py install

注:将 Gitosis 的安装文件暂存在 tmp 目录下,安装完成后可以自行删除

增加名为 Git 的用户,命令行禁用密码

sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git

上传公钥到 tmp 目录下(如果没有,用本机上用 ssh-keygen -t rsa 生成,如何生成参见 Git 客户端的使用方法)

注:上传密钥文件可以通过命令行上传,也可以直接 FTP 上传

运行命令

sudo -H -u git gitosis-init < /tmp/id_rsa.pub

For good measure, let's make sure the post-update hook is set executable. I've seen it where sometimes it doesn't get set (problem with older setuptools):

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

安装完成,现在把 gitosis-admin.git 拷到本地进行修改

gitosis-admin.git

sudo git clone git@YOUR_SERVER:gitosis-admin.git

注:如果要求输入密码,则到服务器端为用户 git 设置密码(pssswd git)

注:如果出现错误 fatal: '~/gitosis-admin.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly,则改成 sudo git clone git@YOUR_SERVER:/home/git/repositories/gitosis-admin.git,即 gitosis-admin.git 所在位置

----- 配置 gitosis ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
将 gitosis-admin.git clone 到本地后,对文件 gitosis.conf 进行相关配置。

[gitosis][group gitosis-admin]writable = gitosis-adminmembers = useremail@server another@server

文件说明:gitosis-admin 组成员有 useremail、another,该组对 gitosis-admin 仓库有读写权限。writable 对应的为项目名称,组名也为项目名称。
添加用户:
需要添加的用户在本地生成密钥(ssh-keygen -t rsa),然后将密钥放在本地项目 gitosis-admin 的 keydir 文件夹内。

配置完成后,将文件推送到服务器 git 项目仓库,然后配置更新。

----- 安装配置 gitweb ----------------------------------------------------------------------------------------------------------------------------------------------------------------
安装前提,需要已经安装 apahce 或者同类的服务器软件
1. 安装gitweb

sudo apt-get install gitweb

2. 配置gitweb
(1) 默认没有 css 加载,把 gitweb 要用的静态文件连接到 WebRoot 下:

cd /var/www/sudo ln -s /usr/share/gitweb/* .

注:注意后面的点

(2) 修改配置:

sudo vi /etc/gitweb.conf

将 $projectroot 改为gitosis-admin.git所在目录: /home/git/repositories

(3) 修改 /home/git/repositories权限,默认情况下,gitosis将 repositories权限设置为不可读的

sudo chmod 777 -R /home/git/repositories

更详细步骤参见:http://blog.enjoyrails.com/2009/01/06/git%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%AE%89%E8%A3%85/


----- 测试::上传本地代码到服务器 git 仓库 -------------------------------------------------------------------------------------------------------------------------------------------
创建测试项目(服务器端)

sudo cd /home/git/repositories
sudo mkdir testproject.git
sudo cd testproject.git
sudo git init --bare

注:如果项目文件夹没有设置为最高权限,键入如下代码否则在本地 push 代码的时候会出现错误。

sudo chmod 777 -R /home/git/repositories/testproject.git

push 本地项目(本机)
切换到项目目录(使用 Windows 平台下 Git Bash 命令行工具)

cd F:/php_root/testproject/
git init
git add .
git commit -m 'push'
git remote add origin git@:testproject.git
git push origin master

操作顺利的话,gitweb 上可以看见已经 push 上去的项目了。

参考:
http://blog.csdn.net/ice520301/article/details/6142503
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
http://www.enjoyrails.com/wikis/Git%E5%AE%89%E8%A3%85
http://blog.enjoyrails.com/2009/01/06/git%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%AE%89%E8%A3%85/
http://www.stylejar.com/archives/ubuntu_install_git_server.html

转载于:https://www.cnblogs.com/shamrocker/archive/2012/08/15/2639477.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值