1.安装nginx
wget http://nginx.org/download/nginx-1.13.12.tar.gz
tar zxvf nginx-1.13.12.tar.gz
./configure && make && make install
2.安装git,gitweb
yum install -y git gitweb spawn-fcgi fcgi-devel fcgi
3.安装fcgiwrap
wget https://codeload.github.com/gnosek/fcgiwrap/legacy.tar.gz/master
tar zxvf master
cd gnosek-fcgiwrap-99c942c
yum install autoconf -y
autoreconf -i
./configure && make && make install
4.修改/etc/gitweb.conf
$projectroot = "/home/git/repositories";
@git_base_url_list= ("git://192.168.126.130", "http://192.168.126.130:88");
$git_temp = "/tmp";
$home_text = "indextext.html";
@stylesheets = ("gitweb.css");
$javascript = "gitweb.js";
@diff_opts = ();
$feature{pathinfo}{default} = [1];
$feature{'highlight'}{'default'} = [1];
仓库地址为/home/git/repositories
git地址为git://192.168.126.130或者http://192.168.126.130:88
5.修改/etc/sysconfig/spawn-fcgi
FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=git
FCGI_GROUP=git
FCGI_EXTRA_OPTIONS="-M 0700"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"
设置spawn-fcgi自启动,并重启
chkconfig --levels 2345 spawn-fcgi on
/etc/init.d/spawn-fcgi start
5.创建git用户
useradd git
passwd git
su git
6.安装gitosis
git clone git://github.com/res0nat0r/gitosis.git
cd gitosis
python setup.py install
cd /home/git
mkdir repositories .ssh
cd .ssh
ssh-keygen -t rsa
cd ..
sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub
安装了gitosis,创建仓库,生成公钥密钥,初始化
7.初始化一个项目
cd repositories
mkdir webpro.git
git --bare init
git config --file config http.receivepack true
以上为 创建一个项目,初始化项目
8.配置GITWEB + NGINX
修改nginx/conf/nginx.conf
server {
error_log logs/git.error.log;
access_log logs/git.access.log;
listen 88;
server_name gitweb;
index gitweb.cgi;
root /home/git;
location ~* ^.+\.(css|js|png|jpg|jpeg)$ {
root /var/www/git;
access_log off;
expires 24h;
}
location ~ \.(cgi|pl).*$ {
gzip off;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /home/git/gitweb.cgi;
fastcgi_param SCRIPT_NAME gitweb.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
root /home/git;
}
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
root /home/git;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL true;
fastcgi_param GIT_PROJECT_ROOT /home/git/repositories;
fastcgi_param PATH_INFO $uri;
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
try_files $uri @gitweb;
location @gitweb {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /var/www/git/gitweb.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
include fastcgi_params;
}
}
cd /var/www/git/static
mv gitweb* ../
将js,css文件移动到git目录
9.使用htpasswd给gitweb加上用户和密码
yum install httpd -y
cd /usr/local/nginx/conf
htpasswd -c gitauth admin
sed -i "s/logs\/git.access.log;/&\nauth_basic \"EverET.org GitWeb Server\";\nauth_basic_user_file \/usr\/local\/nginx\/conf\/gitauth;/" nginx.conf
sudo ../sbin/nginx -s reload
上面的意思就是通过htpasswd创建一个用户名admin的密码文件;
通过sed命令在gitweb的server中加上两句,认证文件指向刚刚生成的密码文件
重新加载nginx
10.使用git客户端实现远程推拉
本地创建文件夹,用git客户端连接虚拟机上的git服务
git init
echo 123 > readme
git add .
git commit -m "hh"
git remote add origin http://192.168.126.130:88/webpro.git
git push origin master
成功拉