linux git web管理工具,玩转Linux(2)——搭建GitWeb

前言

GitWeb 和GitLab相比,一个是简单的仓库查看器,一个是复杂的Git管理系统。

之所以不安装GitLab而选择安装GitWeb的原因有以下:

1、GitLab对配置要求很高

GitLab是基于ruby的,此外还使用了Postgresql、redis等,启动的worker process很多,官方推荐至少需要2核4G。

2、不需要特别多人,没有复杂的权限控制要求

基本是一个“私服”,用来与Jenkins配合实现自动集成,未来可能会有别人用,但也不会有多少人。

如果有人可以直接通过ssh添加公钥的方式。

因此如果搭建GitLab是杀鸡用牛刀。不选择gogs、gitea的原因也是如此。

所以选择了GitWeb(其实搭建GitWeb是更麻烦的)。

搭建过程

虽然没有复杂的权限控制要求,但是还是要做登录,因为服务器内其他应用都是通过nginx转发的,所以决定Git web也使用Nginx转发。

1、安装gitweb和用到的配置软件

sudo apt-get -y install gitweb spawn-fcgi autoconf pkg-config libfcgi-dev

2、安装fastcgi-wrapper

git clone https://github.com/gnosek/fcgiwrap.git

cd fcgiwrap/

autoreconf -i

./configure

make CFLAGS='-Wno-implicit-fallthrough'

sudo make install

3、启动

sudo spawn-fcgi -f /usr/local/sbin/fcgiwrap -p 12345

4、配置GitWeb

sudo vim /etc/gitweb.conf

# git仓库存放的目录

# path to git projects (.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的话,gitweb会自动在$projectroot定义的目录下递归查找合法的git repo来显示。

$projects_list = "/home/git/projects.list";

# $strict_export参数规定只有显示在首页上的repo才能够被访问。换句话说在有projects.list的情况下,该文件列出的repo才能被访问。

$strict_export = 1;

# stylesheet to use

#@stylesheets = ("static/gitweb.css");

# javascript code for gitweb

$javascript = "static/gitweb.js";

# logo to use

$logo = "static/git-logo.png";

# the 'favicon'

#$favicon = "static/git-favicon.png";

# git-diff-tree(1) options to use for generated patches

#@diff_opts = ("-M");

@diff_opts = ();

# $feature数组启用了一些插件或者说特性。blame可以显示代码来源人,snapshot提供repo的打包下载,highlight提供代码高亮。

$feature {'blame'}{'default'} = [1];

$feature {'blame'}{'override'} = 1;

$feature {'snapshot'}{'default'} = ['zip', 'tgz'];

$feature {'snapshot'}{'override'} = 1;

$feature{'highlight'}{'default'} = [1];

5、配置Nginx

链接gitweb文件

sudo ln -s /usr/share/gitweb/ /var/www/

# GitWeb

server {

listen 80;

server_name hostname; # 如xxx.com,建议使用二级域名,如gitweb.xxx.com

root /var/www/gitweb/;

rewrite ^/$ http://$host$1/index.cgi permanent;

location ~ ^.*\.cgi$ {

root /var/www/gitweb/;

fastcgi_pass 127.0.0.1:12345;

fastcgi_index index.cgi;

include fastcgi.conf;

}

# access log file 访问日志

access_log logs/gitweb.access.log;

}

6、浏览器访问你的hostname,如http://gitweb.xxx.com/

7、将一个之前建好的仓库添加到projects.list

未添加的仓库是显示不出来的(通过这个可以控制你想公开的仓库)

echo "test.git" >> projects.list

8、样式不好看,修改一下:

git clone https://github.com/kogakure/gitweb-theme.git

cd gitweb-theme

sudo ./setup -vi --insstall

sudo service nginx restart

9、设置登录认证

sudo htpasswd -c /etc/nginx/gitweb.passwd name

在nginx配置中添加

auth_basic "请先登录";

auth_basic_user_file /etc/nginx/gitweb.passwd;

进入网站提示:

到这里就都搭建完成了~

附:GitWeb仓库配置(在具体的仓库中)

1、description 中可以设置仓库的描述

2、cloneurl 显示该仓库的克隆路径

3、README.html来创建你的仓库内容描述

4、config中可以设置owner = Your Name

http://sourceforge.net/apps/trac/sourceforge/wiki/GitWeb repository browser

Create a “description” file in your git repository root, with a brief, one-line description of your repository. This file is treated as plain text, > > any HTML will be escaped. This will appear in the top section of the gitweb repository landing page.

Create a “cloneurl” file in your git repository root, containing one url per line. Use this to display the clone url for your repository. This will > appear in the same section as the description line, one url per line.

Create a “README.html” file in your git repository root, with arbitrary descriptive content. HTML is allowed, and will be displayed inside a > div tag on the gitweb page, in a section below the one with description.

Set the owner, by setting a gitweb.owner configuration variable in the “config” file, located in your git repository root. If the “gitweb” section does not exist, create it. The owner setting in the config should look like the sample below (you can use any arbitrary string for owner):

[gitweb]

owner = Your Name

来源:https://www.icode9.com/content-3-649901.html

你可能感兴趣的:(linux,git,web管理工具)