gitosis/git服务器搭建

来源:互联网 发布:马甲线软件 编辑:程序博客网 时间:2024/04/30 01:58

刚刚搭建了一个git服务器,碰到很多问题,记下了希望对后来人有所帮助。

git的文档有很多很多,最经典的还是progit.pdf,所以我也是参照这份文档做的。以前一直用git,但是没有做过管理员。都说命令行好用,都是泪。废话少说,开始:


1. 创建git用户

这样所有用户都可以通过git用户来访问git服务器。

你可以这样

$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh

等等! 前辈们已经写过了,我还是不写了吧,转一下 ^_^

=======================================================================================================

Git服务器Gitosis安装设置

http://wiki.ubuntu.org.cn/Git%E6%9C%8D%E5%8A%A1%E5%99%A8Gitosis%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE

1、安装 openssh服务器

sudo apt-get install openssh-server openssh-client

2、创建个人公钥和私钥

在默认用户的主目录路径下,运行以下命令,按照提示创建公钥和私钥

ssh-keygen -t rsa

默认生成2048位,如果需要提高安全级别,也可以通过下面的命令创建公钥和私钥

ssh-keygen -t rsa -b 4096

默认情况下,公钥和私钥会保存在~/.ssh目录下,如下所示:

id_rsa  id_rsa.pub  known_hosts

3、安装 git服务器

sudo apt-get install git-core

4、配置 git服务器

创建git服务器管理用户

sudo useradd -m gitsudo passwd git

创建git仓库存储目录

sudo mkdir /home/git/repositories

设置git仓库权限

sudo chown git:git /home/git/repositoriessudo chmod 755 /home/git/repositories

初始化全局设置

git config --global user.name "myname"git config --global user.email "myname@server"

5、安装python的setup tool

sudo apt-get install python-setuptools

6、获取并安装gitosis

cd /tmpgit clone https://github.com/res0nat0r/gitosis.gitcd gitosissudo python setup.py install

7、配置gitosis

cp ~/.ssh/id_rsa.pub /tmp     (管理员的公匙)sudo -H -u git gitosis-init < /tmp/id_rsa.pubsudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

8、管理gitosis配置

cd ~git clone git@hostname:gitosis-admin.gitcd gitosis-admin/
里面有一个文件gitosis.conf和一个目录keydir,gitosis.conf文件是管理用户名称和项目名称的配置文件,keydir目录是放置用户公匙的目录。并且公匙的名称要和配置文件里的名称相同。
gitosis.con对应/home/git/repositories/gitosis-admin.git/.gitosis.conf文件,keydir目录对应/home/git/repositories/gitosis-admin.git/gitosis-export/keydir目录,每次更改都需要push到服务器。

各个用户按照前面提到的办法生成各自的ssh公钥文件后,服务器管理员把所有人的 ssh公钥文件都拿来,拷贝到keydir目录下。

修改gitosis.conf文件,如下所示

[gitosis]
[group gitosis-admin]writable = gitosis-adminmembers = a@server1
[group developers]writable = helloworldmembers = a@server1 b@server2
[group test] readonly = helloworldmembers = c@server3

这个配置文件表达了如下含义:gitosis-admin组成员有a,该组对gitosis-admin仓库有读写权限; developers组有a,b两个成员,该组对helloworld仓库有读写权限; test组有c一个成员,对helloworld仓库有只读权限。 当然目前这些配置文件的修改只是在你的本地,你必须推送到gitserver上才能真正生效。 加入新文件、提交并push到git服务器:

git add .git commit -am "add helloworld project and users"git remote add origin ssh://git@hostname/helloworld.gitgit push origin master

9、安装apache2

sudo apt-get install apache2

10、安装gitweb

sudo apt-get install gitweb

11、配置 gitweb

默认没有 css 加载,把 gitweb 要用的静态文件连接到 DocumentRoot 下:

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

修改配置:

sudo vi /etc/gitweb.conf

将 $projectroot 改为git仓库存储目录(例如:/home/git/repositories),保存后刷新浏览器。


如果没有找到项目,你需要将$projectroot/*.git 的属性改为755,让apache用户有可读权限。可以只改你需要让别人通过web访问的那个git。http://localhost/cgi-bin/gitweb.cgi


修改/etc/gitweb.conf 内容:

# path to git projects (<project>.git)#$projectroot = "/var/cache/git";$projectroot = "/home/git/repositories";
# directory to use for temp files$git_temp = "/tmp";
# target of the home link on top of all pages$home_link = $my_uri || "/";
# html text to include at home page$home_text = "indextext.html";
# file with project list; by default, simply scan the projectroot dir.$projects_list = $projectroot;
# stylesheet to use@stylesheets = ("/gitweb/static/gitweb.css");
# javascript code for gitweb$javascript = "gitweb/static/gitweb.js";
# logo to use$logo = "/gitweb/static/git-logo.png";
# the 'favicon'$favicon = "/gitweb/static/git-favicon.png";
# git-diff-tree(1) options to use for generated patches#@diff_opts = ("-M");@diff_opts = ();

12、配置apache2

ubuntu中默认的web目录是/var/www,默认的cgi目录是 /usr/lib/cgi-bin/,安装完成gitweb后,gitweb的gitweb.cgi会自动放置到该目录下。

如果你的cgi路径不是默认的/usr/lib/cgi-bin/,需要将gitweb安装在/usr/lib/cgi-bin中的gitweb.cgi复制到原来配置的cgi-bin路径,并在apache的配置文件/etc/apache2/apache.conf末尾加上以下内容:

SetEnv  GITWEB_CONFIG   /etc/gitweb.conf <Directory "/srv/www/cgi-bin/gitweb">                Options FollowSymlinks ExecCGI               Allow from all                               AllowOverride all                            Order allow,deny                             <Files gitweb.cgi>           SetHandler cgi-script      </Files>                         RewriteEngine on      RewriteCond %{REQUEST_FILENAME} !-f      RewriteCond %{REQUEST_FILENAME} !-d      RewriteRule ^.* /gitweb.cgi/$0 [L,PT] </Directory>

重新启动apache:sudo /etc/init.d/apache2 restart,访问http://localhost/cgi-bin/gitweb.cgi File:5640850295_c021ba8c01_z.jpg

13、参考:

Git Reference

ArchLinux下安装git, gitosis, gitweb服务

Git服务器在Ubuntu中的搭建

Ubuntu中Git服务器搭建

Git服务器Gitosis架设指南

gitweb在ubuntu上的配置

git通过ssh进行认证连接


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 微商别人觉得贵怎么办 id被别人锁定了怎么办 2017闯红灯扣6分怎么办 乐天玛特超市卡怎么办 乐天玛特的卡怎么办 乐天玛特倒闭 卡怎么办 公租房五年到期怎么办 超市的水杯坏了怎么办 玩天涯明月刀卡怎么办? 想开童装店没什么经验怎么办 孕后期鼻炎犯了怎么办 酷狗国外听不了怎么办 酷狗音乐换手机怎么办 有优势卵泡不排卵怎么办 卵泡30mm不破怎么办 成熟的卵泡不破怎么办 卵泡大了不破怎么办 卵泡突然不长了怎么办 想怀孕卵泡不长怎么办 吉吉影音下载慢怎么办 辞职后社保断了怎么办 2岁泡泡糖咽下去怎么办 我在拼多多开团怎么办 养了一条鱼死了怎么办 鱼缸的鱼尾巴烂怎么办 捡到玉佛吊坠该怎么办 晚上睡不踏实多梦易醒怎么办 红米3s蓝屏怎么办 吃饭没给钱跑了怎么办 刚出生的宝宝红屁屁怎么办 刚出生的宝宝红屁股怎么办 眼镜配高了25度怎么办 广州摇号中签后怎么办 深圳摇号中签后怎么办 皮肤被紫外线晒伤怎么办 脸被太阳晒过敏怎么办 星际2买了的怎么办 脸被风吹红了怎么办 天谕背包满了怎么办 剑灵没用的武器怎么办 人老实心太善良怎么办