经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » Git » 查看文章
GitLab (v16.x) 简述及安装部署
来源:cnblogs  作者:讲文张字  时间:2024/3/13 10:36:20  对本文有异议

GitLab 介绍

GitLab 的历史

  • GitLab 最初是一个完全免费的开源软件,根据 MIT 许可证分发。2013 年 7 月,它被分为两个不同的版本 - GitLab CE(社区版)和 GitLab EE(企业版)。GitLab EE 处于受限许可证下,但源代码仍然公开可见,而 GitLab CE 许可模型保持不变。2017 年,GitLab 宣布他们的代码将在 MIT 许可证下完全开源。

为什么使用 GitLab?

  • GitLab是在集中式服务器上管理git仓库的好方法。GitLab让你完全控制你的仓库或项目,并允许你免费决定它们是公开还是私有的。

  • 使用 GitLab 的主要好处是它允许所有团队成员在项目的每个阶段进行协作。GitLab 提供从规划到创建的跟踪,帮助开发人员自动化整个 DevOps 生命周期并实现最佳结果。越来越多的开发人员开始使用 GitLab,因为它具有广泛的功能和可用的代码块。

Git,GitHub 与 GitLab 的区别

  • Git是一种版本控制系统,是一种工具,用于跟踪修改和从远程资源推送或拉取代码的版本控制。

  • GitHub是一个目前全球最大的基于Git实现的在线代码仓库托管平台,是一个公开的、免费的服务,它要求所有的代码(除非你有一个付费账户)都是公开的。任何人都可以看到你推送到GitHub的代码,并提供改进建议。

  • GitLab是一个基于Git实现的在线代码仓库软件,你可以用GitLab自己搭建一个类似于GitHub一样的仓库,但是GitLab有完善的管理界面和权限控制,一般用于在企业、学校等内部网络搭建Git私服。

  • GitHub和GiLlab两个都是基于Web的Git远程仓库,它们都提供了分享开源项目的平台,为开发团队提供了存储、分享、发布和合作开发项目的中心化云存储的场所。从代码的私有性上来看,GitLab 是一个更好的选择。但是对于开源项目而言,GitHub 依然是代码托管的首选。

特点

  • GitLab免费托管您的(私有)软件项目。

  • GitLab是一个管理 Git 仓库的平台。

  • GitLab提供免费的公共和私有仓库、问题跟踪和维基。

  • GitLab是一个建立在Git之上的用户友好的网络界面层,它提高了使用Git的速度。

  • GitLab提供了自己的 持续集成 (CI)系统来管理项目,并提供用户界面和GitLab的其他功能。

优势

  • GitLab提供了 GitLab社区版 ,用户可以定位他们的代码在哪个服务器上。

  • GitLab免费提供无限数量的私有和公共仓库。

  • Snippet 部分可以分享一个项目中的少量代码,而不是分享整个项目。

缺点

  • 在推送和提取仓库时,它没有GitHub快。

  • GitLab的界面在从一个页面切换到另一个页面时需要时间。

先决条件

建议使用至少具有以下各项的服务器:

  • CPU 4 核是建议的最小核心数,最多支持500个用户。
  • 内存 4 GB RAM 是所需的最小内存大小,最多支持500个用户。

GitLab 还要求文件系统准备好用于存储 Git 仓库和各种其它文件。
请注意,如果您使用 NFS(网络文件系统),文件将通过网络传输,根据实现,该网络需要打开端口 111 和 2049

GitLab 架构图

Gitlab组件:

  • repository:代码库,可以是硬盘或 分布式文件系统。

  • Nginx:Web 入口。

  • gitlab-workhorse:轻量级反向代理服务器,可以处理一些大的HTTP请求(磁盘上的 CSS、JS 文件、文件上传下载等),处理 Git Push/Pull 请求,处理到Rails 的连接会反向代理给后端的unicorn(修改由 Rails 发送的响应或发送给 Rails 的请求,管理 Rails 的长期 WebSocket 连接等)。

  • gitlab-shell:用于 SSH 交互,而不是 HTTP。gitlab-shell 通过 Redis 与 Sidekiq 进行通信,并直接或通过 TCP 间接访问 Unicorn。用于处理Git命令和修改authorized keys列表。

  • Unicorn:Gitlab 自身的 Web 服务器(Ruby Web Server),包含了 Gitlab 主进程,负责处理快速/一般任务,与 Redis 一起工作,配置参考:CPU核心数 + 1 = unicorn workers数量。工作内容包括:

    • 通过检查存储在 Redis 中的用户会话来检查权限。

    • 为 Sidekiq 制作任务。

    • 从仓库(warehouse)取东西或在那里移动东西。

  • Redis:缓存每个客户端的sessions和后台队列,负责分发任务。Redis需求的存储空间很小,大约每个用户25KB。

  • Gitaly:后台服务,专门负责访问磁盘以高效处理 gitlab-shell 和 gitlab-workhorse 的git 操作,并缓存耗时操作。所有的 git 操作都通过 Gitaly 处理,并向 GitLab web 应用程序提供一个 API,以从 git(例如 title, branches, tags, other meta data)获取属性,并获取 blob(例如 diffs,commits,files)。

  • Sidekiq:后台核心服务,可以从redis队列中提取作业并对其进行处理。后台作业允许GitLab通过将工作移至后台来提供更快的请求/响应周期。Sidekiq任务需要来自Redis。

  • 数据库(PostgreSQL/MySQL):包含以下信息:

    • repository 中的数据(元数据,issue,合并请求 merge request 等)。

    • 可以登录 Web 的用户(权限)。

  • mail_room:处理邮件请求。回复 GitLab 发出的邮件时,GitLab 会调用此服务处理Sidekiq、Unicorn 和 GitLab-shell 的任务 。

  • logrotate:日志文件管理,切割。

组件操作命令

  1. # nginx
  2. gitlab-ctl start|stop|restart|status nginx
  3. # unicorn
  4. gitlab-ctl start|stop|restart|status unicorn
  5. # sidekiq
  6. gitlab-ctl start|stop|restart|status sidekiq
  7. # postgresql
  8. gitlab-ctl start|stop|restart|status postgresql
  9. # redis
  10. gitlab-ctl start|stop|restart|status redis
  11. # gitlab
  12. gitlab-ctl start|stop|restart|status|reconfigure
  13. # supervisor
  14. systemctl start|stop|restart|status gitlab-runsvdir.service

GitLab部署过程

准备环境

  1. [root@GitServer ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.9.2009 (Core)
  3. [root@GitServer ~]# uname -r
  4. 3.10.0-1160.el7.x86_64
  5. [root@GitServer ~]# setenforce 0
  6. [root@GitServer ~]# sed -i.bak '7s/enforcing/disabled/' /etc/selinux/config
  7. [root@GitServer ~]# systemctl stop firewalld
  8. [root@GitServer ~]# systemctl status firewalld
  9. firewalld.service - firewalld - dynamic firewall daemon
  10. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
  11. Active: inactive (dead)
  12. Docs: man:firewalld(1)
  13. [root@GitServer ~]# firewall-cmd --state
  14. not running

安装

  1. [root@GitLabServer ~]# yum install -y curl policycoreutils-python openssh-server perl postfix wget
  2. [root@GitLabServer ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.2-ce.0.el7.x86_64.rpm
  3. [root@GitLabServer ~]# yum localinstall gitlab-ce-16.4.2-ce.0.el7.x86_64.rpm
  4. It looks like GitLab has not been configured yet; skipping the upgrade script.
  5. *. *.
  6. *** ***
  7. ***** *****
  8. .****** *******
  9. ******** ********
  10. ,,,,,,,,,***********,,,,,,,,,
  11. ,,,,,,,,,,,*********,,,,,,,,,,,
  12. .,,,,,,,,,,,*******,,,,,,,,,,,,
  13. ,,,,,,,,,*****,,,,,,,,,.
  14. ,,,,,,,****,,,,,,
  15. .,,,***,,,,
  16. ,*,.
  17. _______ __ __ __
  18. / ____(_) /_/ / ____ _/ /_
  19. / / __/ / __/ / / __ `/ __ / /_/ / / /_/ /___/ /_/ / /_/ /
  20. \____/_/\__/_____/\__,_/_.___/
  21. Thank you for installing GitLab!
  22. GitLab was unable to detect a valid hostname for your instance.
  23. Please configure a URL for your GitLab instance by setting `external_url`
  24. configuration in /etc/gitlab/gitlab.rb file. # 注意:设置external_url
  25. Then, you can start your GitLab instance by running the following command:
  26. sudo gitlab-ctl reconfigure # 注意:执行重载配置
  27. For a comprehensive list of configuration options please see the Omnibus GitLab readme
  28. https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
  29. Help us improve the installation experience, let us know how we did with a 1 minute survey:
  30. https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-0
  31. Verifying : gitlab-ce-16.4.2-ce.0.el7.x86_64 1/1
  32. Installed:
  33. gitlab-ce.x86_64 0:16.4.2-ce.0.el7
  34. Complete!

修改GitLab配置

  1. [root@GitLabServer ~]# hostname -I
  2. 172.16.70.191
  3. [root@GitLabServer ~]# cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb_bak
  4. [root@GitLabServer ~]# diff /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb_bak
  5. 32c32
  6. # 例如1:external_url 'http://IP' # 默认端口80
  7. # 例如2:external_url 'http://IP:PORT'
  8. < external_url 'http://172.16.70.191:91' # 修改此行内容, 设置为本机IP:PORT
  9. ---
  10. > external_url 'http://gitlab.example.com'
  11. # 重载配置
  12. [root@GitLabServer ~]# gitlab-ctl reconfigure

可选设置

  1. # 启动ssh服务&设置为开机启动
  2. systemctl enable sshd && sudo systemctl start sshd
  3. # 设置postfix开机自启,并启动,postfix支持gitlab发信功能
  4. systemctl enable postfix && systemctl start postfix
  5. # 如系统防火墙是开启状态,则需设置允许策略
  6. firewall-cmd --permanent --add-service=http
  7. firewall-cmd --permanent --add-service=https
  8. firewall-cmd --zone=public --add-port=PORT/tcp --permanent
  9. systemctl reload firewalld

查看GitLab版本信息

  1. [root@GitLabServer ~]# gitlab-rake gitlab:env:info
  2. System information
  3. System:
  4. Current User: git
  5. Using RVM: no
  6. Ruby Version: 3.0.6p216
  7. Gem Version: 3.4.19
  8. Bundler Version:2.4.19
  9. Rake Version: 13.0.6
  10. Redis Version: 7.0.13
  11. Sidekiq Version:6.5.7
  12. Go Version: unknown
  13. GitLab information
  14. Version: 16.4.2
  15. Revision: 67c88353b76
  16. Directory: /opt/gitlab/embedded/service/gitlab-rails
  17. DB Adapter: PostgreSQL
  18. DB Version: 13.11
  19. URL: http://172.16.70.191:91
  20. HTTP Clone URL: http://172.16.70.191:91/some-group/some-project.git
  21. SSH Clone URL: git@172.16.70.191:some-group/some-project.git
  22. Using LDAP: no
  23. Using Omniauth: yes
  24. Omniauth Providers:
  25. GitLab Shell
  26. Version: 14.28.0
  27. Repository storages:
  28. - default: unix:/var/opt/gitlab/gitaly/gitaly.socket
  29. GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
  30. Gitaly
  31. - default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket
  32. - default Version: 16.4.2
  33. - default Git Version: 2.42.0

Gitlab目录结构

  1. /opt/gitlab/    # 主目录
  2. /etc/gitlab/    # 放置配置文件
  3. /var/opt/gitlab/    # 各个组件
  4. /var/log/gitlab/    # 放置日志文件
  5. /var/opt/gitlab/git-data/repositories    # 数据库的地址  
  6. /var/opt/gitlab/postgresql/data    # gitlab组和项目的地址
  7. /etc/gitlab/gitlab.rb # gitlab配置文件

端口信息

  1. [root@GitLabServer ~]# netstat -ntpl
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 2637/gitlab-workhor
  5. tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 2653/ruby
  6. tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 2222/puma 6.3.1 (un
  7. tcp 0 0 0.0.0.0:91 0.0.0.0:* LISTEN 2330/nginx: master # 对应前面设置external_url PORT
  8. tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 2252/sidekiq_export
  9. tcp 0 0 127.0.0.1:9236 0.0.0.0:* LISTEN 2599/gitaly
  10. tcp 0 0 127.0.0.1:8150 0.0.0.0:* LISTEN 2626/gitlab-kas
  11. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1270/sshd
  12. tcp 0 0 127.0.0.1:8151 0.0.0.0:* LISTEN 2626/gitlab-kas
  13. tcp 0 0 127.0.0.1:8153 0.0.0.0:* LISTEN 2626/gitlab-kas
  14. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 875/master
  15. tcp 0 0 127.0.0.1:8154 0.0.0.0:* LISTEN 2626/gitlab-kas
  16. tcp 0 0 127.0.0.1:8155 0.0.0.0:* LISTEN 2626/gitlab-kas
  17. tcp 0 0 127.0.0.1:8092 0.0.0.0:* LISTEN 2250/sidekiq 6.5.7
  18. tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 2330/nginx: master
  19. tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 2655/redis_exporter
  20. tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 2662/prometheus
  21. tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 2688/postgres_expor
  22. tcp 0 0 127.0.0.1:9093 0.0.0.0:* LISTEN 2678/alertmanager
  23. tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 2647/node_exporter
  24. tcp6 0 0 ::1:9168 :::* LISTEN 2653/ruby
  25. tcp6 0 0 :::22 :::* LISTEN 1270/sshd
  26. tcp6 0 0 ::1:25 :::* LISTEN 875/master
  27. tcp6 0 0 :::9094 :::* LISTEN 2678/alertmanager

GitLab 密码

获取初始登录密码,默认登录账号:root

设置初始密码:GitLab 14.0 开始引入。
默认情况下,Linux 软件包安装会自动为初始管理员用户账号 (root) 生成密码,并将其存储到 /etc/gitlab/initial_root_password 至少 24 小时。出于安全原因,24 小时后,此文件会被第一次 gitlab-ctl reconfigure 自动删除。

  1. [root@GitLabServer ~]# grep Password: /etc/gitlab/initial_root_password
  2. Password: JPbE/qElViuH3O1REgsnA+9hB669393vA0f19NAe8RY=

设置简体中文

其他设置

禁用注册

默认情况下,任何访问您的极狐GitLab 域名的用户都可以注册一个账户。对于运行面向公众的极狐GitLab 实例的客户,如果您不希望公众用户注册账户,我们强烈建议您考虑禁用新注册。

  1. 要禁用注册:
  2. 在左侧边栏中,选择 搜索或转到。
  3. 选择 管理中心。
  4. 选择 设置 > 通用。
  5. 展开 注册限制。
  6. 清除 已启用注册功能 复选框,然后选择 保存修改。

重置/修改root密码

使用Rake任务:GitLab 13.9 开始引入。
密码长度设置为最少8个字符,且必须符合复杂性要求。

  1. [root@GitLabServer ~]# gitlab-rake "gitlab:password:reset[root]"
  2. Enter password: # 输入新密码
  3. Confirm password: # 再次输入
  4. Password successfully updated for user with username root.

防止新用户创建顶级群组

  1. # 编辑 /etc/gitlab/gitlab.rb 并添加以下行:
  2. gitlab_rails['gitlab_default_can_create_group'] = false
  3. gitlab-ctl reconfigure
  4. gitlab-ctl restart

防止用户更改其用户名

默认情况下,新用户可以更改他们的用户名。要禁用您的用户更改其用户名的能力:

  1. 编辑 /etc/gitlab/gitlab.rb 并添加以下行:
  2. gitlab_rails['gitlab_username_changing_enabled'] = false
  3. gitlab-ctl reconfigure
  4. gitlab-ctl restart

原文链接:https://www.cnblogs.com/zhangwencheng/p/17848971.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号