Git服务器搭建
环境准备:
- 系统环境:CentOS 6.x
- 软件版本:git-2.3.1.tar.gz
- 下载地址:https://www.kernel.org/pub/software/scm/git/git-2.3.1.tar.gz
编译Git版本:
tar -zxvf git-2.3.1.tar.gz
cd git-2.3.1
make prefix=/usr/local all
ln –s /usr/local/bin/git /usr/bin/
2.2创建Git用户
下面创建Git用户,命令如下所示:
useradd git –d /home/git
2.3在Git用户下安装SSH
在Git用户下安装SSH,命令如下所示:
ssh-keygen –t rsa
然后一路回车即可。
2.4安装Gitolite
这是一款Git服务管理工具,通过公钥对用户进行认证,并能够利用配置文件进行repo的精细授权管理。 输入以下命令:
gitolite setup -pk ~/. ssh/id_rsa.pub
出现如下图所示,即表示成功。
2.5添加开发者
由于手上机器有限,我将权限配置和Git 仓库配置在同一台机器上,在前面我们添加了Git用户下的公钥,下面在Git账户下直接输入如下命令:
git clone git@git.company.com: gitolite-admin.git
注:这里的git.company.com在实际使用中可以换成公司域名或IP。
如果在执行命令时,需要输入密码,说明前面某些配置出错了,需要重新查证解决后在继续。
克隆完成后,会在gitolite-admin目录下出现两个子目录:conf和keydir。conf是gitolite的权限配置文件夹,keydir用于放置所有用户的公钥。所以,现在我们将guest.pub文件(开发者电脑生成的公钥)放入keydir目录中,然后编辑conf/gitolite.conf,在文件末尾添加新的repo和权限。下面我们添加一个repo为hdfs-etl,拥有读写权限。内容如下:
repo hdfs-etl
RW+ = guest
注:R(读)W(写)
修改完成后,我们提交更改,完成用户及其库的添加,命令如下:
git add conf git add keydir git commit –m “add repo diexun-etl,give access dengjie” git push
2.6操作repo
下面我在guest的主机上克隆hdfs-etl的工程,命令如下:
git clone git@git.company.com: hdfs-etl.git
如果在网络正常的情况下克隆失败,说明公钥添加未成功;若克隆成功,则会出现hdfs-etl的目录。当然我们也可以查看一下操作的权限,命令如下:
ssh git@git.company.com info
如下图所示:
如图所示,我机上上拥有读和写的权限,与配置的权限一致。
2.7卸载
任何地方使用ssh或git登录到git服务器需要输入密码,都说明配置git服务器出现错误,需要重新安装gitolite,重新安装前先清除之前的文件,清除命令如下所示:
环境准备:
操作系统:CentOS 6.x
由于Gitlab官方给出的安装过程难以成功(尝试过很多次,各种出错,环境只是一种工具,不应该花费太多的时间在这上面)。下面给出一个集成安装工具包BitNami,关于BitNami的简介,这里不做赘述,可自行谷歌了解。
bitnami-gitlab下载地址:https://downloads.bitnami.com/files/stacks/gitlab/7.8.1-0/bitnami-gitlab-7.8.1-0-linux-x64-installer.run
下载完成后,我们开始安装流程,命令如下:
chmod u+x bitnami-gitlab-7.8.1-0-linux-x64-installer.run
./bitnami-gitlab-7.8.1-0-linux-x64-installer.run
注:机器内存至少1G,不然跑不起来。
下面列出安装流程:
The installer detects that exists a 'git' user in the system. This installer will change the config
uration for this user. Do you want to continue the installation? [y/N]: y The installer detects that exists a 'gitlab_ci' user in the system. This installer will change the
configuration for this user. Do you want to continue the installation? [y/N]: y ---------------------------------------------------------------------------- Welcome to the Bitnami Gitlab Stack Setup Wizard. ---------------------------------------------------------------------------- Select the components you want to install; clear the components you do not want to install. Click Next when you are ready to continue. GitLab : Y (Cannot be edited) GitLab CI [Y/n] :Y Is the selection above correct? [Y/n]: Y ---------------------------------------------------------------------------- Installation folder Please, choose a folder to install Bitnami Gitlab Stack Select a folder [/opt/gitlab-7.8.1-0]: ---------------------------------------------------------------------------- Create Admin account Bitnami Gitlab Stack admin user creation Email Address [user@example.com]: smartdengjie@gmail.com Login [user]: sa Password :******** Please confirm your password :******** ---------------------------------------------------------------------------- Hostname that will be used to create internal URLs. If this value is incorrect, you may be unable to access your Gitlab installation from other computers. It is advisable to use a Domain instead of an IP address for compatibility with different browsers. Domain [10.211.55.30]: Do you want to configure mail support? [y/N]: y ---------------------------------------------------------------------------- Configure SMTP Settings This is required so your application can send notifications via email. Default email provider: [1] GMail [2] Custom Please choose an option [1] : 1 ---------------------------------------------------------------------------- Configure SMTP Settings This data is stored in the application configuration files and may be visible to others. For this reason, it is recommended that you do not use your personal account credentials. Username []: sa Password : Re-enter : ---------------------------------------------------------------------------- Setup is now ready to begin installing Bitnami Gitlab Stack on your computer. Do you want to continue? [Y/n]: y ---------------------------------------------------------------------------- Please wait while Setup installs Bitnami Gitlab Stack on your computer. Installing 0% ______________ 50% ______________ 100% #########################################
到这里,Gitlab就安装完成了。
3.2启动服务
命令如下:
/opt/gitlab- 7.1. 1- 0/ctlscript. sh restart #重启
/opt/gitlab- 7.1. 1- 0/ctlscript. sh stop #停止
4.Gitlab使用
下面我们登录到Gitlab的可视化界面,截图如下:
下面演示Gitlab使用流程:
- 创建项目:
其中需要注意: 如果属于Group级的项目,也就是属于多人配合的项目,建议Namespace使用Group name,另外Visibility默认为Internal。我们先创建一个组,如图所示:
这里我们添加组所属用户,如图所示:
- 源仓库的构建
我们接下来按照步骤来创建一个自己的项目:
按照以上提示的步骤操作,我们即可以创建或者导入一个项目成功。
到这里,Gitlab的搭建和项目创建就介绍完成了。