linux进阶之gitlab仓库搭建及免密使用

一、Gitlab简介

GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。

可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用。Gitlab私有仓库;GitHub公共的代码仓库。

功能:Gitlab 是一个提供代码托管、提交审核和问题跟踪的代码管理平台。对于软件工程质量管理非常重要。

版本:GitLab 分为社区版(CE 和企业版(EE)。

配置:建议CPU2核,内存2G以上。

Gitlab的服务构成:

1Nginx:静态web服务器。

2gitlab-shell:用于处理Git命令和修改authorized keys列表。(Ruby

3gitlab-workhorse: 轻量级的反向代理服务器。(go

GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pullGit包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn

4logrotate:日志文件管理工具。

5postgresql:数据库。

6redis:缓存数据库。

7sidekiq:用于在后台执行队列任务(异步执行)。(Ruby

8unicornAn HTTP server for Rack applicationsGitLab Rails应用是托管在这个服务器上面的。(Ruby Web Server,主要使用Ruby编写)

管理的命令:

gitlab-ctl stop            #停止所有gitlab组件

gitlab-ctl start            #启动所有gitlab组件

gitlab-ctl restart         #重启所有gitlab组件

gitlab-ctl status          #查看服务状态

gitlab-ctl reconfigure        #重新编译gitlab的配置(执行 reconfigure 命令会把gitlabnginx组件的配置还原,导致自定义修改的端口以及域名等都没有了。)

vim /etc/gitlab/gitlab.rb            #修改gitlab配置文件

gitlab-rake gitlab:check SANITIZE=true --trace              #检查gitlab

gitlab-ctl tail              #查看日志

二、gitlab安装及使用

第一步:安装gitlab

[root@ren5 ~]# yum localinstall gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm -y

第二步:修改配置文件

在文件11行左右把主机名修改为主机IP地址

[root@ren5 ~]# vim /etc/gitlab/gitlab.rb

########################################

11 external_url 'http://192.168.11.5'

#############################################

注释行#的含义:

1.不生效

2.默认值

第三步:重新配置(使配置重新生效,需要一定的时间)

启动gitlab的时候80端口不能被占用!

[root@ren5 ~]# gitlab-ctl reconfigure          #重新配置

[root@ren5 ~]# ss -tnl

[root@ren5 ~]# lsof -i :80

COMMAND  PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   9629       root    6u  IPv4  50984      0t0  TCP *:http (LISTEN)

nginx   9630 gitlab-www    6u  IPv4  50984      0t0  TCP *:http (LISTEN)

[root@ren5 ~]# firewall-cmd --add-port=80/tcp                      #添加防火墙端口

[root@ren5 ~]# firewall-cmd --add-port=80/tcp --permanent

第四步:浏览器访问

直接输入服务器IP 即可访问

需要修改密码,输入新的密码,密码长度需要8位(change your password

Admin换成root,密码就是刚才设置的密码,点击sign in

第五步:gitlab使用

windows中可以通过创建用户,创建项目组,创建项目来新建一个项目

Linux中的使用

[root@ren5 ~]# mkdir rrr        #创建根目录

[root@ren5 ~]# cd rrr

[root@ren5 rrr]# yum -y install git

[root@ren5 rrr]# git clone http://192.168.11.5/root/first-project.git      #克隆远程仓库(拉取项目)

[root@ren5 rrr]# ls

first-project

[root@ren5 rrr]# cd first-project/

[root@ren5 first-project]# ls -a

.  ..  .git

[root@ren5 first-project]# touch {1..5}.txt        #更新文件

[root@ren5 first-project]# echo "111111111111" > 1.txt

[root@ren5 first-project]# ls

1.txt  2.txt  3.txt  4.txt  5.txt

[root@ren5 first-project]# git add .             #工作目录内容上传到暂存区域

[root@ren5 first-project]# git commit -m "v1"         #把暂存区内容添加到仓库

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"

  git config --global user.name "Your Name"

to set your account's default identity.

Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@ren5.(none)')

[root@ren5 first-project]# git config --global user.email "you@example.com"

[root@ren5 first-project]# git config --global user.name "Your Name"      #认证

[root@ren5 first-project]# git commit -m "v1"         #重新提交

[master(根提交) d5aee1b] v1

 5 files changed, 1 insertion(+)

 create mode 100644 1.txt

 create mode 100644 2.txt

 create mode 100644 3.txt

 create mode 100644 4.txt

 create mode 100644 5.txt

[root@ren5 first-project]# git branch          #查看分支

* master

[root@ren5 first-project]# git push -u origin master        #把本地内容推送至远程仓库(第一次推送时必须加 -u 选项,之后可不加-u选项)

Username for 'http://192.168.11.5': root             #输入用户名(gitlab的用户密码)

Password for 'http://root@192.168.11.5':          #输入密码

[root@ren5 first-project]# git branch hello        #创建新的分支

[root@ren5 first-project]# git checkout hello            #切换到新分支

切换到分支 'hello'

[root@ren5 first-project]# touch test && echo "hello world" > test     #添加测试文件

[root@ren5 first-project]# git add .     #添加至暂存区

[root@ren5 first-project]# git commit -m "v2"         #添加至仓库

[root@ren5 first-project]# git push -u origin hello           #推送至远程仓库

三、linux当中免密使用gitlab

在上面我们每次登录gitlab都要输入名字和密码很麻烦,故可以使用密钥SSH来推送。

第一步:生成密钥对

ssh-keygen

第二步:复制公钥信息

[root@ren5 first-project]# cat /root/.ssh/id_rsa.pub

第三步:粘贴到web服务端profile-settingsssh-keys

第四步:点击提交之后再次下载仓库信息

回车之后可以看到没有输入任何东西就直接下载完成

注意:拉取的时候指定的是ssh地址而不再是http地址!

推送时可使用分支的形式推送,也可以选择ssh的地址进行推送

四、window中免密使用gitlab

第一步:准备文件

你需要首先在网上下载下面的这个客户端工具:Git-2.7.2-32-bit_setup.1457942412.exe

第二步:安装

第三步:创建一个文件夹作为工作目录并进入目录之后;右击鼠标有两个选项,一个是bash一个是图形化

第四步:生成秘钥信息,进行免密登录;在这个界面输入ssh-keygen一直点回车生成秘钥信息

第五步:把公钥信息输入到web服务端;可以从上面的信息中看到秘钥信息保存在哪了,现在我们去c盘找;复制这个公钥里面的信息

第六步:本地下载仓库;使用git clone 加上你的项目ssh信息

第七步:本地查看;发现已经有了仓库信息了,现在你就可以开始写程序了

第八步:测试;进入到包含.git的目录并在此右击打开bash,执行创建分支操作,并建立test.txt测试文件

第九步:上传文件;和linux中一样执行上传命令

第十步:在web中查看;可以看到我们刚才在window中创建的文件也已经被上传上来了

原文地址:https://www.cnblogs.com/renyz/p/11368933.html