您的位置:首页 > 其它

【项目管理】Jenkins+Maven+Git项目持续构建之搭建git服务器

2017-11-20 17:44 716 查看
gitlab和github两者都是基于web的Git repositories(仓库),拥有流水线型的web开发流程,它们为开发团队存储、分享、发布、测试和合作web开发项目提供了中心化的、云存储的场所。Git版本控制——对于多人共同开发一个project来说非常重要——它提供了分享开源项目的平台。但github是一个开源代码交互沟通平台,是2008年由Ruby on Rails编写而成。GitHub同时提供付费账户和免费账户。这两种账户都可以创建公开的代码仓库,但是付费账户才可以创建私有的代码仓库。所以在github上想要将代码设置为私有是需要收费的。而且将代码保存在别人的服务器上毕竟具有一定的风险性,尤其对于保密级别较高的代码。所以搭建公司私有的代码服务器是十分必要的。不过幸好,github的缺陷gitlab解决了。

下面开始具体介绍一下搭建Git服务器,主要分为以下几个部分:

- 1、安装bitnami

- 2、修改gitlab默认端口号

- 3、生成密钥,将公钥添加到gitlab中

- 4、配置gitlab:创建用户

- 5、配置gitlab:创建项目

- 6、gitlab启动

1、安装bitnami

git服务器比较有名的是gitosis和gitolite,这两个管理和使用起来稍微有些复杂,没有web页面,而gitlab则是类似于github的一个工具,并且gitlab解决了github无法免费建立私有仓库的问题。gitlab有很多依赖,一一安装这些依赖不仅对服务器现有的环境造成干扰,而且非常不方便,而bitnami制作了一键安装的包,下载地址为:https://bitnami.com/redirect/to/37478/bitnami-gitlab-7.0.0-0-linux-installer.run ,会下载当前最新版本的bitnami,当前最新版本应该为10.0.3,下面介绍一下bitnami的具体安装。

这里以bitnami的7.8.1版本为例

1) 将下载后的bitnami拷贝到适当的位置,切换到对应的目录下

2) 赋权限:

chmod +x  bitnami-gitlab-7.8.1-0-linux-x64-installer.run


3) 安装.run文件

./ bitnami-gitlab-7.8.1-0-linux-x64-installer.run




以下为bitnami的安装细节,供参考

[root@localhost ~]# ls
anaconda-ks.cfg  gitlab  learngit.git
[root@localhost ~]# cd gitlab
[root@localhost gitlab]# chmod +x bitnami-gitlab-7.8.1-0-linux-x64-installer.run
[root@localhost gitlab]# ./bitnami-gitlab-7.8.1-0-linux-x64-installer.run
The installer detects that exists a 'git' user in the system. This installer will change the configuration 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]: 输入Email地址

Login [user]: 输入用户名

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 [127.0.0.1]: IP地址

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] : 2

----------------------------------------------------------------------------
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 []: Email地址

Password :
Re-enter :
SMTP Host []: smtp.qq.com

SMTP Port []: 25

Secure connection

[1] None
[2] SSL
[3] TLS
Please choose an option [3] : 3

----------------------------------------------------------------------------
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%
########################################
----------------------------------------------------------------------------
Setup has finished installing Bitnami Gitlab Stack on your computer.

Info: To access the Bitnami Gitlab Stack, go to http://IP地址:80 from your browser.
Press [Enter] to continue:


2、修改gitlab默认端口号

gitlab默认的端口号为80,如果该端口被占用,可以修改端口号,具体操作如下:

1) 找到gitlab的安装目录,一般在opt文件下,我的在../**/gitlab/gitlab-7.8.1-0

2) 修改../**/gitlab/gitlab-7.8.1-0/apache2/conf/httpd.conf,修改Listen 80为新的端口号,例如Listen 9001

3) 修改../**/gitlab/gitlab-7.8.1-0/apache2/conf/bitnami/bitnami.conf,修改端口号为新端口号

4) 修改../**/gitlab/gitlab-7.8.1-0/apps/gitlab/gitlab-shell/config.yml下的端口号

5) 修改../**/gitlab/gitlab-7.8.1-0/apps/gitlab/htdocs/config/gitlab.yml下的端口号

3、生成密钥,将公钥添加到gitlab中

在终端输入ssh-keygen -t rsa -C “Email地址”,生成的密钥保存在/root/.ssh下,将密钥添加到gitlab的ssh key中。

1) 进入到ssh文件夹中:cd /root/.ssh

2) 将公钥保存在gitlab中,在gitlab面板中依次点击ProfileSSH KeysAdd SSH Keys,然后把.ssh文件下的id_rsa.pub公钥的内容粘贴到输入框中保存起来。

注:git仓库之间的代码传输协议主要使用ssh协议,而一般搭建gitlab时使用的git用户是没有密码的,因此直接ssh是不能登录的,就需要使用ssh-keygen上传公钥,使用非对称加密传输。


4、配置gitlab:创建用户

1)点击Admin area,选择Users



2)输入相应的用户名、密码、邮箱等信息



3)创建用户成功后,添加git公钥到Gitlab,点击Profile settings,选择SSH Keys



4)在Key栏中输入生成的公钥,以获得用户的使用权限



5、配置gitlab:创建项目

1)创建项目,点击右上侧的New project,输入项目的相关信息



2)输入相应的项目名称及权限



项目Namespance及权限的简单介绍:

【1】Namespace:这个选择是用来决定这个工程所属的,可以选User为你自己。或者选择组,这个会影响到后面工程的url。

【2】Visibility Level:权限等级分三种

 Private:私有的,只有你自己或者组内的成员能访问

 Internal:所有登录的用户

 Public:公开的,所有人都可以访问

项目创建成功后,会生成对应的url,根据url就可以进行代码的上传和下载了。

3)创建完成后,根据页面提示,可上传项目代码



6、gitlab启动

gitlab安装目录下,有一个ctlscript.sh文件,启动该文件即可完成gitlab的启动,具体操作为:

切换到root用户下,输入命令gitlab-7.8.1-0/ctlscript.sh start命令,则gitlab启动

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息