Gitlab搭建详细步骤

Gitlab搭建详细步骤用命令在网上下载一个项目到我们的服务器上 gitclonehttp github com muxiaonong ci test 生成公钥私钥对出来 命令 ssh keygen 安装完成 创建好了 ssl 密钥和证书 gitlab ce repo 源包 利用 ssl 密钥和证书创建签署证书 进入密钥目录 cd ssh 可以看到 ssl 密钥和证书

Gitlab的概念

       GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。安装方法是参考GitLab在GitHub上的Wiki页面。Gitlab是目前被广泛使用的基于git的开源代码管理平台, 基于Ruby on Rails构建, 主要针对软件开发过程中产生的代码和文档进行管理, Gitlab主要针对group和project两个维度进行代码和文档管理, 其中group是群组, project是工程项目, 一个group可以管理多个project, 可以理解为一个群组中有多项软件开发任务, 而一个project中可能包含多个branch, 意为每个项目中有多个分支, 分支间相互独立, 不同分支可以进行归并。

  定义

      GitLab是由GitLabInc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。

 用到的git指令

git init :初始化.git文件夹
git add 文件名:从本地工作区添加文件入暂存区
git add -A:从本地工作区添加全部文件入暂存区
git commit -m “添加的备注” 文件名:暂存区给文件备注确认,记录为一个版本
git commit -m “添加的备注” 文件名:暂存区全部文件备注确认,记录为一个版本
git log:查看历史版本记录
git status:查看文档修改记录,红色为未add内容,绿色为可以commit内容
git push 地址名 本地分支:远程库分支:将暂存区代码推入远程库
git remove add 地址名 地址url:远程库操作
git branch -M 分支名:创建分支


















gitlab的安装与配置

gitlab-ce.repo源包

vim /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1 #yum makecache

或者这样装wget安装

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm

改主机域名

[root@localhost ~]# hostnamectl set-hostname gitlab.example.com [root@localhost ~]# bash [root@gitlab ~]# 

配置 hosts

[root@gitlab ~]# cat /etc/hosts 192.168.100.17 gitlab.example.com 

安装gitlab依赖软件 及获取 GPG 密钥

yum install -y curl policycoreutils openssh-server openssh-clients postfix rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 

安装 postfix 并启动

yum install postfix systemctl start postfix systemctl enable postfix 

安装gitlab-ce 

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash yum -y install gitlab-ce 

手动配置ssl证书

1.创建私有密钥

[root@gitlab ~]# mkdir -p /etc/gitlab/ssl [root@gitlab ~]# openssl genrsa -out "/etc/gitlab/ssl/gitlab.example.com.key" 2048 Generating RSA private key, 2048 bit long modulus ...+++ ........................................+++ e is 65537 (0x10001) 

2.创建私有证书

[root@gitlab ~]# cd /etc/gitlab/ssl [root@gitlab ssl]# ls gitlab.example.com.key [root@gitlab ssl]# openssl req -new -key "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.csr" You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN CN 国家 State or Province Name (full name) []:SX SX 省份 Locality Name (eg, city) [Default City]:XA XA 城市 Organization Name (eg, company) [Default Company Ltd]: 空格 Organizational Unit Name (eg, section) []: 空格 Common Name (eg, your name or your server's hostname) []:gitlab.example.com Email Address []:@.com 邮箱地址 Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: 密码 An optional company name []: 空格 [root@gitlab ssl]# ls gitlab.example.com.csr gitlab.example.com.key 

 3.创建CRT签署证书

[root@gitlab ssl]# openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.com.csr" -signkey "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.crt" Signature ok subject=/C=CN/ST=SX/L=XA/O=Default Company Ltd/CN=gitlab.example.com/emailAddress=@.com Getting Private key [root@gitlab ssl]# ll /etc/gitlab/ssl/ 总用量 12 -rw------- 1 root root 1273 8月 8 15:52 gitlab.example.com.crt -rw------- 1 root root 1070 8月 8 15:52 gitlab.example.com.csr -rw------- 1 root root 1679 8月 8 15:50 gitlab.example.com.key 

4.利用openssl签署pem 证书

root@gitlab ssl]# openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.com.csr" -signkey "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.crt" Signature ok subject=/C=CN/ST=SX/L=XA/O=Default Company Ltd/CN=gitlab.example.com/emailAddress=@.com Getting Private key [root@gitlab ssl]# [root@gitlab ssl]# openssl dhparam -out /etc/gitlab/ssl/dhparams.pem 2048 Generating DH parameters, 2048 bit long safe prime, generator 2 This is going to take a long time ..............................+..............................................................................................................................................................................................................................+.+..........................................................+...........................................................................................................................................+...........................................................................................................................................................................................................................................................+.....................................................................................+.........................................

5.更改ssl下的所有证书权限

[root@gitlab ssl]# chmod 600 * [root@gitlab ssl]# ll 总用量 16 -rw------- 1 root root 424 8月 8 15:53 dhparams.pem -rw------- 1 root root 1273 8月 8 15:52 gitlab.example.com.crt -rw------- 1 root root 1070 8月 8 15:52 gitlab.example.com.csr -rw------- 1 root root 1679 8月 8 15:50 gitlab.example.com.key

6.配置证书到gitlab配置文件中

[root@gitlab ssl]# vim /etc/gitlab/gitlab.rb external_url 'https://gitlab.example.com' 改为https开头 nginx['redirect_http_to_https'] = true 取消#号更改注释并为true 1397行 # nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt" 更改路径 # nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key" 更改路径 # nginx['ssl_dhparam'] = /etc/gitlab/ssl/dhparams.pem 更改路径 # Path to dhparams.pem, eg. /etc/gitlab/ssl/dhparams.pem 

7.更改完之后初始化命令执行

[root@gitlab ssl]# gitlab-ctl reconfigure .... .... .... Running handlers: [2022-08-09T15:04:10+08:00] INFO: Running report handlers Running handlers complete [2022-08-09T15:04:10+08:00] INFO: Report handlers complete Infra Phase complete, 3/818 resources updated in 13 seconds gitlab Reconfigured! # 出现这个表示配置没有问题! [root@gitlab ssl]# gitlab-ctl status [root@gitlab ssl]#gitlab-ctl restart ok: run: alertmanager: (pid 16197) 0s ok: run: gitaly: (pid 16212) 0s ok: run: gitlab-exporter: (pid 16225) 0s ok: run: gitlab-kas: (pid 16227) 0s ok: run: gitlab-workhorse: (pid 16236) 1s ok: run: grafana: (pid 16243) 0s ok: run: logrotate: (pid 16253) 1s ok: run: nginx: (pid 16260) 0s ok: run: node-exporter: (pid 16269) 1s ok: run: postgres-exporter: (pid 16281) 0s ok: run: postgresql: (pid 16371) 0s ok: run: prometheus: (pid 16384) 1s ok: run: puma: (pid 16399) 0s ok: run: redis: (pid 16405) 1s ok: run: redis-exporter: (pid 16411) 0s ok: run: sidekiq: (pid 16419) 0s [root@gitlab conf]# [root@gitlab conf]# gitlab-ctl restart sidekiq ok: run: sidekiq: (pid 17327) 0s

8.对nginx配置

[root@gitlab ssl]#cd /var/opt/gitlab/nginx/conf [root@gitlab conf]# ls gitlab-health.conf gitlab-http.conf nginx.conf nginx-status.conf [root@gitlab conf]# vim gitlab-http.conf server_name gitlab.example.com; rewrite ^(.*)$ https://$host$1 permanent; #需要添加的配置 

9.重启gitlab

[root@gitlab ssl]# gitlab-ctl restart ok: run: alertmanager: (pid 15710) 0s ok: run: gitaly: (pid 15723) 1s ok: run: gitlab-exporter: (pid 15736) 0s ok: run: gitlab-kas: (pid 15738) 0s ok: run: gitlab-workhorse: (pid 15747) 1s ok: run: grafana: (pid 15755) 0s ok: run: logrotate: (pid 15765) 1s ok: run: nginx: (pid 15775) 0s ok: run: node-exporter: (pid 15781) 1s ok: run: postgres-exporter: (pid 15792) 0s ok: run: postgresql: (pid 15800) 0s ok: run: prometheus: (pid 15803) 0s ok: run: puma: (pid 15895) 0s ok: run: redis: (pid 15904) 1s ok: run: redis-exporter: (pid 15910) 0s ok: run: sidekiq: (pid 15918) 0s 

在Windows系统里C:\Windows\System32\drivers\etc\hosts 添加以下

192.168.100.17 gitlab.example.com

然后ping gitlab.example.com   是否能通

浏览器登录 gitlab    机器配置要大于4g内存,否则很容易启动不了,报502

Gitlab搭建详细步骤

浏览器登录 gitlab    https://gitlab.example.com/

Gitlab搭建详细步骤

 查看初始密码

[root@gitlab ~]# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: hms9K6+y9yBlIj1UgLcjmbQ5c1mFF/EHMaFQALPjNHQ=       为初始密码

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
[root@gitlab ~]# 

gitlab切换中文模式 

Gitlab搭建详细步骤

 更改初始密码

Gitlab搭建详细步骤

开始使用gitlab创建项目

Gitlab搭建详细步骤

1,创建一个测试项目 

Gitlab搭建详细步骤

2,复制仓库地址 

Gitlab搭建详细步骤

生成公钥私钥对出来,命令:ssh-keygen

进入密钥目录:cd .ssh/

[root@gitlab ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:tfCPmmz4NkdfloxsUjyfkO1eS6t7b81iqGw0KQKR26E  The key's randomart image is: +---[RSA 2048]----+ | . | | o . | | = .. .. o | | E . + .* . | | . S o+ B o | | . . *o+ O..| | o +.=.=.o+| | ..++o o +++| | +=+o. ++oo| +----[SHA256]-----+ [root@gitlab ~]# cd .ssh/ [root@gitlab .ssh]# ll 总用量 8 -rw------- 1 root root 1675 8月 10 09:44 id_rsa -rw-r--r-- 1 root root 405 8月 10 09:44 id_rsa.pub [root@gitlab .ssh]# cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFJIIh+4WbYDsmSr+ZdY1DTo9DHhpIuBjRghEGagYVWg3KgnjhC3Ic7nt9opH2AHHAnVqg84FIkBpzbeb0zAwaam0I6fEeXC2h2r7XEWrfDWt81N6QwV6hujG3tzL3hggFTVa3SWU8tVCQbjC9qUYrHvj+oU+m4iXjXqPYxo9piBGXvJovte28Izy36hk21jp9c0Qx6eAAFGX1t762s4DZyAXD5UH3EQwz6y9hMvbn7o+P2uNb8QDbcR4Luhl0TO89SISftBI81ABd+9ej+K9SsQNO1vk6yV2EAqKr662ErM76lktmyZPuofBtoLOpH2pL0xPx5d2xIplhzt5Tfrk1  [root@gitlab .ssh]# 

新建一个SSH密钥

Gitlab搭建详细步骤

Gitlab搭建详细步骤

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/221683.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 下午5:31
下一篇 2026年3月17日 下午5:32


相关推荐

  • 最大似然估计总结笔记

    最大似然估计总结笔记最大似然估计学习总结 MadTurtle1 作用在已知试验结果 即是样本 的情况下 用来估计满足这些样本分布的参数 把可能性最大的那个参数作为真实的参数估计 2 离散型设为离散型随机变量 为多维参数向量 如果随机变量相互独立且概率计算式为 P 则可得概率函数为 P 在固定时 上式表示的概率 当已知的时候 它又变成的函数 可以把它记为 称此函数为似然函数 似然函数值的大小意味着该样本值出现的可能性的大小 既然已经得到了样本值 那么它出现的可能性应该是较大的 即似然函数的值也应

    2026年3月19日
    1
  • sstream头文件

    sstream头文件之前的sscanf和sprintfsscanf函数原型为intsscanf(constchar*str,constchar*format,…),将参数str的字符串根据参数format字符串来转换并格式化数据,转换后的结果存于对应的参数内;#include<iostream>#include<cstdio>usingnamespacestd;i…

    2022年6月4日
    53
  • 给 Pycharm 安装 pytorch

    给 Pycharm 安装 pytorch问题在之前的文章Win10通过Anaconda下载安装PyTorch中,用Anacondaprompt在base环境中安装了PyTorch,并且能在Jupyternotebook中调用。但遇到了两个问题:使用Pycharm创建新project时,envs目录下找不到pytorch的选项;在Pycharm中运行>>>importtorch报错“Couldnotfindcondaenvironment:torch”

    2022年8月27日
    11
  • Anaconda:在Pycharm中使用Anaconda的解释器

    Anaconda:在Pycharm中使用Anaconda的解释器我先从我的认识简单总结一下 搭建 Python 环境的常见模式是安装一个 Python 的 IDE 集成开发环境 再使用 pip 或 conda 等命令安装特别扩展的第三方包 常见的 PythonIDE 平台简单列举如下 1 Python 自带的 IDE IDLE 优点是小巧 缺点是需要另外安装很多 Python 包 2 Anaconda 平台 优点是已包含很多 Python 第三方包 使用比较方便 缺点是

    2026年3月27日
    3
  • 使用MySQL实现分页查询[通俗易懂]

    使用MySQL实现分页查询[通俗易懂]本文关键字:MySQL、分页查询、真分页、假分页、LIMIT。在项目开发当中,经常要实现分页功能,在面试时也会经常被问到:什么是分页。这是因为在一个页面上能够显示的数据是有限的,而存放在数据库中的数据往往很多,我们必须将这些数据安放到不同的页面中去。

    2022年6月29日
    25
  • 各个数据库中substring截取字符串操作

    各个数据库中substring截取字符串操作SQL中的substring函数是用来抓出一个栏位资料中的其中一部分。这个函数的名称在不同的资料库中不完全一样:MySQL:SUBSTR(),SUBSTRING()

    2022年5月23日
    58

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号