世上有可以挽回的和不可挽回的事,而时间经过就是一种不可挽回的事。 —《国境以南太阳以西》村上春树.

|

eye_code

园龄:5年6个月粉丝:2关注:2

CentOS 7 安装和配置 GitLab

前言

1. GitLab是什么?

GitLab一个开源的git仓库管理平台,方便团队协作开发、管理。在GitLab上可以实现完整的CI(持续集成)、CD(持续发布)流程。而且还提供了免费使用的Plan,以及免费的可以独立部署的社区版本(https://gitlab.com/gitlab-org/gitlab-ce )。

官网:https://about.gitlab.com/

2. 环境

工具/环境 版本
Linux Server CentOS 7
GitLab 14.7.3
  • 搭建于虚拟机:

建议
2处理器,4GB内存(最低),生产环境要根据实际需要,此软件还是比较吃内存的

安装

1. 更换阿里yum源

原始的yum源可能无法访问,所以更换到国内源(已经更换好源的可以省略这一步)

  • 安装wget
yum install -y wget
  • 备份默认的yum
mv /etc/yum.repos.d/ /etc/yum.repos.d.backup
  • 创建新的yum目录
mkdir /etc/yum.repos.d/
  • 下载阿里yum源到创建的目录中
wget -O /etc/yum.repos.d/CentOS-BAse.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  • 重建缓存
yum clean all

yum makecache

2. 部署社区版GitLab

  • 安装GitLab的依赖项
yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python

注意:10.x版本以后开始依赖policycoreutils-python,9.x之前没有依赖项

  • 启动ssh && postfix并设置为开机启动
#启动ssh服务&设置为开机启动

systemctl enable sshd

systemctl start sshd

# Postfix是一个邮件服务器,GitLab发送邮件需要用到 && 设置为开机启动

systemctl enable postfix

systemctl start postfix
  • 设置防火墙
# 开放ssh以及http服务(80端口)
firewall-cmd --add-service=ssh --permanent
firewall-cmd --add-service=http --permanent

# 重载防火墙规则
firewall-cmd --reload
  • 获取GitLab的rpm包

访问清华大学开源软件镜像站查找目标版本的GitLab rpm包,复制地址,通过wget下载

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.7.3-ce.0.el7.x86_64.rpm
  • 通过"rpm -i"命令来安装下载好的rpm包
rpm -i gitlab-ce-14.7.3-ce.0.el7.x86_64.rpm 

出现如下图示,则表示安装成功

根据提示,继续执行命令配置

  • 借助"vim"编辑配置文件

GitLab默认的配置文件路径是/etc/gitlab/gitlab.rb

默认的站点Url配置项是:external_url 'http://gitlab.example.com'

根据自己需求配置,推荐使用域名或服务器IP

vim /etc/gitlab/gitlab.rb

这里提示一下,按照上面的配置方式只设置URL可能会报错,配置文件版本上有所不同,14 的版本,unicorn 已经弃用,若要修改端口等需要切换到 Puma ;

可以参考官网的文档:https://docs.gitlab.com/ee/administration/operations/puma.html

配置好后,需要重新加载配置内容

gitlab-ctl reconfigure

gitlab-ctl restart
  • 查看GitLab版本
head -1 /opt/gitlab/version-manifest.txt

3. 设置管理员密码

浏览器访问GitLab所在服务器IP,首次登陆需要修改密码

# 使用gitlab-rails console修改密码

[root@lp Downloads]# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       14.7.3 (293f6bb322b) FOSS
 GitLab Shell: 13.22.2
 PostgreSQL:   12.7
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.4.4)
irb(main):001:0> user = User.where(id:1).first # id为1的表示超级管理员
=> #<User id:1 @root>
irb(main):002:0> user.password='123456789' # 密码至少8个字符
=> "123456789"
irb(main):003:0> user.password_confirmation='123456789'
=> "123456789"  # 确认密码
irb(main):004:0> user.save!  # 保存,如果没有问题返回true
=> true
irb(main):005:0> exit  # 退出

  • 访问服务器IP,登录进入GitLab

gitlab-ctl常用命令介绍

命令 说明
check-config 检查在gitlab中是否有任何配置。在指定版本中删除的rb
deploy-page 安装部署页面
diff-config 将用户配置与包可用配置进行比较
remove-accounts 删除所有用户和组
upgrade 升级
service-list 查看所有服务
once 如果GitLab服务停止了就启动服务,如果已启动就不做任何操作
restart 重启GitLab服务
start 如果GitLab服务停止了就启动服务,如果已启动就重启服务
stop 停止GitLab服务
status 查看GitLab服务状态
reconfigure reconfigure重新配置GitLab并启动

本文作者:wait_code

本文链接:https://www.cnblogs.com/waitCode/p/15911793.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   eye_code  阅读(124)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 1967 ゴンチチ
  2. 2 Audio name Audio artist
1967 - ゴンチチ
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.