【保姆级】centos 7 搭建 GitLab-EE

本文详细介绍了在CentOS7.6系统上安装和配置GitLab的过程,包括环境要求、SSH依赖、防火墙设置、安装Postfix、配置GitLab镜像源、安装及初始化步骤等。
摘要由CSDN通过智能技术生成
环境要求:centos7.6

最低配置:2核cpu、4G内存

推荐配置:4核cpu、8G内存

1、GitLab介绍
GitLab是一个用于管理Git存储库的 Web 应用程序。由于它是围绕 Git 构建的,因此它适合管理主要使用纯文本文件的任何项目,例如软件源代码、基于 TeX 的文档或 Markdown 中的会议记录。凭借其内置的问题和 wiki 系统,在某些情况下,它甚至可以成为管理没有任何文件的项目的正确工具。

2、GitLab安装
如果某些步骤已经操作过了,则无需执行,为了防止安装GitLab-CE后需要升级GitLab-EE,这里直接安装GitLab-EE,只要不续费功能就跟CE一样,如果不喜欢EE请更改下载地址或者软件源为CE即可。

2.1 安装SSH依赖
# 更新系统
sudo yum update -y
# 安装SSH协议
sudo yum install -y curl policycoreutils-python openssh-server perl
2.2 启动SSH服务
# 设置SSH服务开机自启动
sudo systemctl enable sshd
# 启动SSH服务
sudo systemctl start sshd
# 查看SSH状态
sudo systemctl status sshd
# 查看SSH启动状态
[root@VM-8-7-centos ~]# sudo systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-03-25 11:10:09 CST; 7min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1632 (sshd)
CGroup: /system.slice/sshd.service
└─1632 /usr/sbin/sshd -D
2.3 配置IPv4转发
配置转发
vim /etc/sysctl.conf
#配置转发
net.ipv4.ip_forward = 1
#重启服务,让配置生效
systemctl restart network
#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward
2.4 安装并启动防火墙
# 安装firewalld防火墙
sudo yum install firewalld systemd -y
# 设置firewalld防火墙自动启动
sudo systemctl enable firewalld
# 启动firewalld防火墙服务
sudo systemctl start firewalld
# 检查firewalld防火墙服务状态
sudo systemctl status firewalld
# 检查firewalld防火墙服务状态
systemctl status firewalld


[root@VM-8-7-centos ~]# sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-03-25 11:30:25 CST; 4s ago
Docs: man:firewalld(1)
Main PID: 15681 (firewalld)
CGroup: /system.slice/firewalld.service
└─15681 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
2.5 添加HTTP服务到firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
其中,pemmanent 表示永久生效,若不加 --permanent 系统下次启动后就会失效。

2.6 安装Postfix以发送邮件
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo systemctl status postfix
# 查看启动情况
[root@VM-8-7-centos ~]# sudo systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2024-03-25 11:10:08 CST; 24min ago
Main PID: 1352 (master)
CGroup: /system.slice/postfix.service
├─1352 /usr/libexec/postfix/master -w
├─1374 pickup -l -t unix -u
└─1375 qmgr -l -t unix -u
将网络协议指定为IP4,以修复PostFix发邮件错误

vim /etc/postfix/main.cf
# 修改inet_protocols = all为
inet_protocols = ipv4
systemctl restart postfix
2.7 添加gitlab镜像
1、将镜像源改为国内源
(1)在 /etc/yum.repos.d 目录下新建 gitlab-ce.repo 文件并保存

# 1.进入目录
cd /etc/yum.repos.d
# 2.新建文件
touch gitlab-ee.repo
# 3.编辑文件
vim gitlab-ee.repo
(2)给文件添加内容(vi:以编辑的方式打开文件,i:插入/编辑,ESC:退出编辑,:wq:保存退出),内容如下:

[gitlab-ee]
name=Gitlab EE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el$releasever/
gpgcheck=0
enabled=1
(3)由于刚刚修改了 yum 源,因此要重新生成缓存,执行:

# 重新生成缓存
yum makecache
2、添加GitLab软件包存储库

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
2.8 安装gitlab镜像
yum install -y gitlab-ee
或者是通过如下方式:

查看最新安装包:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7/

https://mirrors.cloud.tencent.com/gitlab-ee/yum/el7/

# 直接从tsinghua镜像下载安装包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7/gitlab-ee-16.11.0-ee.0.el7.x86_64.rpm

# 或从腾讯云镜像下载安装包

wget https://mirrors.cloud.tencent.com/gitlab-ee/yum/el7/gitlab-ee-16.11.0-ee.0.el7.x86_64.rpm

# 安装包gitlab-ee
rpm -i gitlab-ee-16.11.0-ee.0.el7.x86_64.rpm
安装信息:

[root@VM-12-11-centos yum.repos.d]# yum install -y gitlab-ee
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ee.x86_64 0:16.10.0-ee.0.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
gitlab-ee x86_64 16.10.0-ee.0.el7 gitlab-ee 1.1 G

Transaction Summary
===========================================================================================================
Install 1 Package

Total download size: 1.1 G
Installed size: 2.9 G
Downloading packages:
gitlab-ee-16.10.0-ee.0.el7.x86_64.rpm | 1.1 GB 00:01:45
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gitlab-ee-16.10.0-ee.0.el7.x86_64 1/1
It looks like GitLab has not been configured yet; skipping the upgrade script.

*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.



_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-10

Verifying : gitlab-ee-16.10.0-ee.0.el7.x86_64 1/1

Installed:
gitlab-ee.x86_64 0:16.10.0-ee.0.el7

Complete!
2.9 修改gitlab配置文件
vim /etc/gitlab/gitlab.rb
# 指定服务器ip和自定义端口
external_url 'http://ip:80'
# 将80端口添加到防火墙中
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重启防火墙
systemctl reload firewalld
2.10 重置gitlab
gitlab-ctl reconfigure
# 出现下面信息代表重置成功
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.

NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

gitlab Reconfigured!
2.11 启动gitlab
gitlab-ctl restart
[root@VM-12-11-centos yum.repos.d]# gitlab-ctl restart
ok: run: alertmanager: (pid 13530) 0s
ok: run: gitaly: (pid 13539) 0s
ok: run: gitlab-exporter: (pid 13555) 1s
ok: run: gitlab-kas: (pid 13601) 0s
ok: run: gitlab-workhorse: (pid 13628) 1s
ok: run: logrotate: (pid 13643) 0s
ok: run: nginx: (pid 13650) 0s
ok: run: node-exporter: (pid 13656) 1s
ok: run: postgres-exporter: (pid 13662) 0s
ok: run: postgresql: (pid 13674) 1s
ok: run: prometheus: (pid 13677) 0s
ok: run: puma: (pid 13695) 0s
ok: run: redis: (pid 13701) 0s
ok: run: redis-exporter: (pid 13709) 1s
ok: run: sidekiq: (pid 13721) 0s
查看初始化密码:

cat /etc/gitlab/initial_root_password
[root@zsx ~]# 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: hMUHtYJppbM4qP/4cqdpNVZLqxfADjTh5pG+wMOwwZI=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
请24小时内在GitLab-Password内更改密码,否则失效 。

2.13 添加公钥至gitlab
为了安全性考虑,需要创建 public key:

# 在机器上生成public key
ssh-keygen
然后一路回车,中间若出现是否重写选择 Y

cd ~/.ssh
ls
cat id_rsa.pub
复制 id_rsa.pub 文件的 public key:

[root@VM-8-7-centos .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCaN5w4YWW64yt/YgGO24a1SELKmPNUmK92gREEEePCuFp3cJ/IUqci6GpaTMVIZaFkM4sSW09TGRoKGAeA7ExfOQsg3VtMqvRVx8xpzaS9hj9ut4eNieRVXL1UwBHLIXykviTHpOeWS3UWDdrrDmHkLSdJAZyDEkaFqrONzT56cp34kWxBAsfaKNRHTGtSV7gtL2s327ZyCT4Ns72wkRi8KmAKkoYTn+HjzQ+St6W7emRERNq2WibNk+gBFP57hvAQsng2Q7kx58i4LdmYxvxExW1SyFpmaMwlS+pPyjHCmh6qrHo4o21O6SnW116uc3dSFE0aUq78d8nW1+Y5rz5T your_email@example.com
在GitLab-Preferences-SSH Keys点击 Add new key,在Key输入public key,接着点击Add key

2.14 常用的操作命令
# 启动服务
gitlab -ctl start

# 查看状态
gitlab -ctl status

# 停掉服务
gitlab -ctl stop

# 重启服务
gitlab -ctl restart

# 让配置生效
gitlab -ctl reconfigure
至此,GiLab搭建完毕!
————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/m0_69525149/article/details/137000235

posted @   小强找BUG  阅读(301)  评论(1编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示