Menu Close

Linux 安装GitLab服务

操作系统:CentOS Linux release 7.8.2003 (Core)

1. GitLab安装

1.1. 新建YUM源

~]# vim /etc/yum.repos.d/gitlab-ce.repo
#内容如下:yum源设置为腾讯
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.cloud.tencent.com/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

更新本地yum缓存

~]# yum makecache

file

1.2. 安装gitlab社区版

yum install gitlab-ce        # 自动安装最新版
yum install gitlab-ce-x.x.x  # 安装指定版本

file

1.3. GitLab日常命令

gitlab-ctl start    # 启动所有 gitlab 组件;
gitlab-ctl stop     # 停止所有 gitlab 组件;
gitlab-ctl restart  # 重启所有 gitlab 组件;
gitlab-ctl status   # 查看服务状态;
gitlab-ctl reconfigure        # 启动服务;
vim /etc/gitlab/gitlab.rb     # 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
gitlab-ctl tail     # 查看日志;

2. GitLab配置

2.1. 修改地址与端口

vim /etc/gitlab/gitlab.rb

找到这一段,修改端口并保存:

## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
##!
##! Note: During installation/upgrades, the value of the environment variable
##! EXTERNAL_URL will be used to populate/replace this value.
##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP
##! address from AWS. For more details, see:
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://localhost:9999'

file

重新配置gitlab并重启组件

gitlab-ctl reconfigure
gitlab-ctl restart

执行gitlab-ctl reconfigure命令时间比较长,它会修改 /var/opt/gitlab/gitlab-rails/etc/gitlab.yml /var/opt/gitlab/nginx/conf/gitlab-http.conf等文件中的端口配置

2.2. 登录页面

file

搭建好GitLab服务,打开页面后,需要输入用户名密码。但它们是什么呢?初始管理员用户为root,密码在安装过程中已随机生成并保存在/etc/gitlab/initial_root_password中,有效期24小时。

file

file

提示的中文意思为:您的GitLab实例允许任何人注册帐户,这是面向公众的GitLab实例的安全风险。如果公众用户不希望注册帐户,您应该停用新的注册。(停用、确认)

2.3. 切换中文语言

要切换 GitLab Community Edition v16.9.1 的语言,可以按照以下步骤进行操作:

  1. 登录到 GitLab Community Edition。
  2. 点击用户头像,然后选择 "Settings"(设置)。
  3. 在 "User Settings"(用户设置)页面,选择 "Preferences"(首选项)选项卡。
  4. 滚动页面下方,找到 "Localization"(本地化)部分。
  5. 在 "Language"(语言)下拉菜单中,选择你想要切换的语言。
  6. 点击页面底部的 "Save changes"(保存更改)按钮,以保存语言偏好设置。

切换语言后,GitLab Community Edition 的界面将会显示为你选择的语言。

file

2.4. gitlab 忘记密码、数据库方式修改密码

参见官方文档:https://docs.gitlab.com/ee/security/reset_user_password.html

~]# cd /opt/gitlab/bin/
~]# gitlab-rails console
irb(main):001:0> u=User.where(id:1).first   # 查找与切换账号(User.all 可以查看所有用户)
=> #<User id:1 @root>
irb(main):002:0> u.password='12345678'     # 设置密码为12345678
=> "12345678"
irb(main):003:0> u.password_confirmation='12345678'        # 再次确认密码
=> "12345678"
irb(main):004:0> u.save!     # 进行保存(切记切记 后面的 !)
=> true
irb(main):005:0> exit        # 退出

file

附录

附录A. 相关联的文章

附录B. 参考