原帖:参考(https://www.cnblogs.com/wangxiaoqiangs/p/6179610.html)
1.Git安装
- 获取gitHub编译安装包:https://github.com/git/git/releases
- 编译安装
autoconf && ./configure && make && make install git --version
2.Git SSH 协议
- 创建 Git 仓库
mkdir -p /data/git && cd /data/git git init --bare sample.git git update-server-info
- 客户端 clone 仓库
git clone root@192.168.0.1:/data/git/sample.git # 输入 对应服务器 的 root 密码 root@192.168.0.1's password:
3.Nginx安装与配置
- 安装(略:需额外安装扩展:–with-http_dav_module)
- 安装fcgiwrap
git clone https://github.com/gnosek/fcgiwrap.git cd fcgiwrap && autoreconf -i && ./configure && make && make install vm /etc/init.d/fcgiwrap #! /bin/bash ### BEGIN INIT INFO # Provides: fcgiwrap # Required-Start: $remote_fs # Required-Stop: $remote_fs # Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: FastCGI wrapper # Description: Simple server for running CGI applications over FastCGI ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SPAWN_FCGI="/usr/local/bin/spawn-fcgi" DAEMON="/usr/local/sbin/fcgiwrap" NAME="fcgiwrap" PIDFILE="/var/run/$NAME.pid" FCGI_SOCKET="/var/run/$NAME.socket" FCGI_USER="www-data" FCGI_GROUP="www-data" FORK_NUM=5 SCRIPTNAME=/etc/init.d/$NAME case "$1" in start) echo -n "Starting $NAME... " PID=`pidof $NAME` if [ ! -z "$PID" ]; then echo " $NAME already running" exit 1 fi $SPAWN_FCGI -u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -P $PIDFILE -F $FORK_NUM -f $DAEMON if [ "$?" != 0 ]; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Stoping $NAME... " PID=`pidof $NAME` if [ ! -z "$PID" ]; then kill `pidof $NAME` if [ "$?" != 0 ]; then echo " failed. re-quit" exit 1 else rm -f $pid echo " done" fi else echo "$NAME is not running." exit 1 fi ;; status) PID=`pidof $NAME` if [ ! -z "$PID" ]; then echo "$NAME (pid $PID) is running..." else echo "$NAME is stopped" exit 0 fi ;; restart) $SCRIPTNAME stop sleep 1 $SCRIPTNAME start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|status}" exit 1 ;; esac
# 注意 spawn-fcgi 跟 fcgiwrap 脚本路径及 FCGI_GROUP 跟 FCGI_GROUP
# 脚本启动了 5 个 cgi 进程,按需调整 -
nginx server.conf配置
server { listen 80; server_name git.server.com; #root /usr/local/share/gitweb; #gitWeb按需配置 client_max_body_size 100m; auth_basic "Git User Authentication"; auth_basic_user_file /usr/local/nginx-1.10.2/conf/pass.db; location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /data/git; } location ~ /.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /data/git; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_connect_timeout 24h; fastcgi_read_timeout 24h; fastcgi_send_timeout 24h; fastcgi_param SCRIPT_FILENAME /usr/local/libexec/git-core/git-http-backend; fastcgi_param PATH_INFO $uri; fastcgi_param GIT_HTTP_EXPORT_ALL ""; fastcgi_param GIT_PROJECT_ROOT /data/git; fastcgi_param REMOTE_USER $remote_user; include fastcgi_params; } #下面为gitweb配置 try_files $uri @gitweb; location @gitweb{ fastcgi_pass unix:/war/ren/fcgiwrap.socket; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; fastcgi_param SCRIPT_FILENAME /usr/local/share/gitweb/gitweb.cgi; fastcgi_param PATH_INFO $uri; include fastcgi_params; } }
-
配置git用户表
yum -y install httpd-tools cd /usr/local/nginx/conf htpasswd -c pass.db gituser # 添加用户时执行 htpasswd pass.db username
5.gitWeb界面显示
- 配置gitWeb并启动
vm /etc/gitweb.conf # path to git projects (<project>.git) $projectroot = "/data/git"; # 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; # javascript code for gitweb $javascript = "static/gitweb.js"; # stylesheet to use $stylesheet = "static/gitweb.css"; # logo to use $logo = "static/git-logo.png"; # the 'favicon' $favicon = "static/git-favicon.png";
- # 手动执行开是否报错,Status: 200 OK 正常,以下为报错及解决方法
/usr/local/share/gitweb/gitweb.cgi
2.1:
Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendorperl /usr/share/perl5/vendorperl /usr/lib/perl5 /usr/share/perl5 .) BEGIN failed--compilation aborted. yum -y install perl-CPAN
2.2:
Can't locate CGI.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendorperl /usr/share/perl5/vendorperl /usr/lib/perl5 /usr/share/perl5 .) BEGIN failed--compilation aborted. yum -y install perl-CGI
2.3:
Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/gitweb/gitweb.cgi line 20. yum -y install perl-Time-HiRes
- Gitweb-theme 样式
git clone https://github.com/kogakure/gitweb-theme.git cd gitweb-theme ./setup -vi -t /usr/local/share/gitweb --install # -t 指定 gitweb 根目录,一路 y 即可