码迷,mamicode.com
首页 > 其他好文 > 详细

gitlab构建

时间:2019-12-20 13:33:19      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:网页版   目录   介绍   tmp目录   key   roo   ued   oba   clone   

一、安装Git
yum install git
然后进行配置:
useradd --home /home/git git
passwd git
创建完用户后就可以切换到git用户下进行后面的设置,如用户名和邮箱:
su git
git config --global user.name "somebody"
git config --global user.email "somebody@example.com"
设置默认将会保存在~/.gitconfig文件中。
此时,Git的功能就已经可以使用了。为了方便后面的操作,可以先来创建一个空版本库。

mkdir ~/repo
然后建立项目目录

mkdir ~/repo/huhamhire-hosts
切换到项目目录,并进行初始化

cd ~/repo/huhamhire-hosts
git init -bare
至此,一个初始的空项目版本库就配置完成了,后面安装了gitosis之后便可向库中推送我们的代码库内容。
二、安装gitosis
在安装之前,可以看一下gitosis的实现原理:
http://geeklu.com/2012/10/gitosis/
先切换回root权限。

su root
并先安装python-setuptool

yum install python-setuptools
然后开始安装gitosis,值得注意的是gitosis的安装程序本身就是由git管理的,需要使用git来获取。这里在/tmp目录下进行相关的安装操作:

cd /tmp
git clone https://github.com/res0nat0r/gitosis.git
接下来进入下载的gitosis版本库进行安装:

cd gitosis
python setup.py install
安装完成后,便进入对gitosis的设置阶段。由于gitosis需要通过SSH进行管理,所以需要创建SSH密钥对,并将公钥放在服务器端,私钥放在客户端。一般的流程是客户端创建完密钥后,将公钥传到服务器上生效。不过,偷懒的话直接在服务器上操作问题也不大。
切换到git用户并建立文件夹.ssh:

su git
mkdir /home/git/.ssh
一定记得,在客户机上生成公钥,上传到服务器,或者在服务器上生成,下载到客户机。
进入~/.ssh目录并使用ssh-keygen生成公钥:

cd /home/git/.ssh
ssh-keygen -t rsa
注意不能忘记私钥的密码。默认会生成~/.ssh/id_rsa.pub公钥文件。
有了密钥以后便可初始化gitosis,使gitosis获得对Git的管理权限:

gitosis-init < /home/git/.ssh/id_rsa.pub
初始化之后,会在/home/git/repositories创建gitosis-admin.git项目,可以通过维护这个项目来对gitosis进行配置。
除此以外,还需要对gitosis-admin.git/hooks/post-update目录赋上特殊权限:

chmod u+x /home/git/repositories/gitosis-admin.git/hooks/post-update
至此,服务器端的gitosys配置就完成了。
三、设置并使用gitosys
在服务器端完成了gitosys的配置之后,便可在客户端进行接下来的设置,以便使用Git服务器。
较为正规的做法是在客户端通过gitosis-admin版本库做管理设置,之后提交到服务器使项目权限生效,当然也可以使用操作系统的ssh登录方式进行验证,不过这里仅介绍前面一种方法。
在进行以下操作时,需要确认一下,你的公钥是不是已经放在客户机~/.ssh/目录下。如果你也在用github的话,那么你需要设置一下多公钥共存的东西。.ssh/config,在这个文件中写入:
Host github.com
HostName github.com
User git
IdentityFile C:/Users/abc/.ssh/id_rsa
Host git.oschina.net
HostName git.oschina.net
User git
IdentityFile C:/Users/abc/.ssh/id_rsa_a
Host abc.ueder.info
HostName abc.ueder.info
User git
Port 1000
IdentityFile C:/Users/abc/.ssh/id_rsa_new
如我就使用了好几个git服务,每个都有自己的公钥,需要配置文件来区分开来,并且我自己的服务器ssh端口已经不是默认端口,需要在配置文件中声明,否则在每次clone的时候要声明端口。
在客户机上下载gitosis-admin版本库,这里以linux客户机为例:
git clone git@VPS的IP/Domain:/home/git/repositories/gitosis-admin.git
获取完成后对gitosis-admin/gitosis.conf文件进行设置,以上面新建的项目为例,新增:
[group huhamhire-hosts]
writable = huhamhire-hosts
members = hamhire@myhost
随后要将客户端的公钥放到keydir目录下,并随后提交设置到服务器:
cp ~/.ssh/id_rsa.pub ~/gitosis-admin/keydir/hamhire@myhost.pub

cd ~/gitosis-admin
git add ./
git commit -a -m "add new repo"
git push
由于之前已经在/home/git/repo/目录下设置了huhamhire-hosts的版本库位置,所以可以直接进行推送操作。
在本例中可以通过hamhire@myhost:/home/git/repo/huhamhire-hosts的路径来提交项目。
至此,gitosys的配置全部完成。
四、安装gitweb
在配置完成了git服务器以后,如果需要方便在线查看,使用gitweb来提供一个简单网页版的版本显示界面是一个不错的选择。
在centos 下安装gitweb如下:
yum install fcgi-devel

cd /usr/local/src/
git clone git://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure
make
make install
至此,fcgiwrap已经安装到 /usr/local/sbin/fcgiwrap
然后再安装spawn-fcgi
yum install spawn-fcgi
安装好后:
vim /etc/sysconfig/spawn-fcgi
修改文件为:
# You must set some working options before the "spawn-fcgi" service will work.
# If SOCKET points to a file, then this file is cleaned up by the init script.
#
# See spawn-fcgi(1) for all possible options.
#
# Example :
#SOCKET=/var/run/php-fcgi.sock
#OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
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"
然后设置开机运行:

chkconfig --levels 2345 spawn-fcgi on
/etc/init.d/spawn-fcgi start
这里已经完成了fcgi的安装运行。如果你用的nginx,还需要对nginx.conf进行配置,才能将.cgi的请求转发给fcgiwrap.socket
location /cgi-bin/ {
# Disable gzip (it makes scripts feel slower since they have to complete
# before getting gzipped)
gzip off;
# Set the root to /usr/lib (inside this location this means that we are
# giving access to the files under /usr/lib/cgi-bin)
root /var/www/www.example.com;
# Fastcgi socket
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;
# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
最后重启nginx就可以了。

gitlab构建

标签:网页版   目录   介绍   tmp目录   key   roo   ued   oba   clone   

原文地址:https://www.cnblogs.com/li0920/p/12072548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!