centos7系统GitLab服务器搭建(最新稳定版)

打印 上一主题 下一主题

主题 905|帖子 905|积分 2715

1、GitLab先容

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

假如某些步骤已经操作过了,则无需实行。
2.1 安装SSH依赖
  1. yum install -y curl policycoreutils-python openssh-server
复制代码
  
2.2 启动SSH服务
  1. [root@VM-8-8-centos lighthouse]# systemctl enable sshd
  2. [root@VM-8-8-centos lighthouse]# systemctl start sshd
复制代码
  1. # 查看启动状态
  2. [root@VM-8-8-centos lighthouse]# systemctl status sshd
  3. ● sshd.service - OpenSSH server daemon
  4.    Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
  5.    Active: active (running) since Fri 2024-05-24 11:35:45 CST; 2h 36min ago
  6.      Docs: man:sshd(8)
  7.            man:sshd_config(5)
  8. Main PID: 1636 (sshd)
  9.    CGroup: /system.slice/sshd.service
  10.            └─1636 /usr/sbin/sshd -D
复制代码
2.3 设置防火墙-启用IP转发功能(可直接关闭防火墙)
  1. vim /etc/sysctl.conf
  2. # 在文件末尾添加
  3. net.ipv4.ip_forward = 1
复制代码
2.4 安装并启动防火墙
  1. yum install firewalld systemd -y
  2. systemctl enable firewalld
  3. systemctl start firewalld
  4. systemctl status firewalld
复制代码
  1. #查看启动情况
  2. [root@VM-8-8-centos lighthouse]# systemctl status firewalld
  3. ● firewalld.service - firewalld - dynamic firewall daemon
  4.    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
  5.    Active: active (running) since Fri 2024-05-24 14:20:56 CST; 35s ago
  6.      Docs: man:firewalld(1)
  7. Main PID: 29060 (firewalld)
  8.    CGroup: /system.slice/firewalld.service
  9.            └─29060 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
复制代码
2.5 添加HTTP服务到firewalld
  1. [root@VM-8-8-centos lighthouse]# firewall-cmd --permanent --add-service=http
  2. success
  3. [root@VM-8-8-centos lighthouse]# systemctl reload firewalld
复制代码
其中,pemmanent 表示永世见效,若不加 --permanent 系统下次启动后就会失效。
2.6 安装Postfix以发送邮件
  1. yum install postfix
  2. systemctl enable postfix
  3. systemctl start postfix
  4. systemctl status postfix
复制代码
  1. # 查看启动情况
  2. [root@VM-8-8-centos lighthouse]# systemctl status postfix
  3. ● postfix.service - Postfix Mail Transport Agent
  4.    Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
  5.    Active: active (running) since Fri 2024-05-24 11:35:45 CST; 2h 50min ago
  6. Main PID: 1360 (master)
  7.    CGroup: /system.slice/postfix.service
  8.            ├─1360 /usr/libexec/postfix/master -w
  9.            ├─1378 qmgr -l -t unix -u
  10.            └─9367 pickup -l -t unix -u
复制代码
  1. vim /etc/postfix/main.cf
  2. # 修改inet_protocols = all为
  3. inet_protocols = ipv4
  4. #重启服务
  5. systemctl restart postfix
复制代码
2.7 添加gitlab镜像

在 /etc/yum.repos.d 目次下新建 gitlab-ce.repo 文件并保存,内容如下:
  1. [gitlab-ce]
  2. name=Gitlab CE Repository
  3. baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
  4. gpgcheck=0
  5. enabled=1
复制代码
  1. # 重新生成缓存
  2. yum makecache
复制代码
2.8 安装GitLab
  1. yum install -y gitlab-ce #最新稳定版<br><br>yum list gitlab-ce --showduplicates #查看yum源可安装的版本
复制代码
  1. yum install -y gitlab-ce-版本号
复制代码
安装信息:
  1. [root@VM-8-8-centos yum.repos.d]# yum install -y gitlab-ce
  2. Loaded plugins: fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package gitlab-ce.x86_64 0:17.0.1-ce.0.el7 will be installed
  7. --> Finished Dependency Resolution
  8. Dependencies Resolved
  9. ====================================================================================================================================
  10. Package                       Arch                       Version                               Repository                     Size
  11. ====================================================================================================================================
  12. Installing:
  13. gitlab-ce                     x86_64                     17.0.1-ce.0.el7                       gitlab-ce                     918 M
  14. Transaction Summary
  15. ====================================================================================================================================
  16. Install  1 Package
  17. Total download size: 918 M
  18. Installed size: 2.5 G
  19. Downloading packages:
  20. gitlab-ce-17.0.1-ce.0.el7.x86_64.rpm                                                                         | 918 MB  00:01:22     
  21. Running transaction check
  22. Running transaction test
  23. Transaction test succeeded
  24. Running transaction
  25.   Installing : gitlab-ce-17.0.1-ce.0.el7.x86_64                                                                                 1/1
  26. It looks like GitLab has not been configured yet; skipping the upgrade script.
  27.        *.                  *.
  28.       ***                 ***
  29.      *****               *****
  30.     .******             *******
  31.     ********            ********
  32.    ,,,,,,,,,***********,,,,,,,,,
  33.   ,,,,,,,,,,,*********,,,,,,,,,,,
  34.   .,,,,,,,,,,,*******,,,,,,,,,,,,
  35.       ,,,,,,,,,*****,,,,,,,,,.
  36.          ,,,,,,,****,,,,,,
  37.             .,,,***,,,,
  38.                 ,*,.
  39.   
  40.      _______ __  __          __
  41.     / ____(_) /_/ /   ____ _/ /_
  42.    / / __/ / __/ /   / __ `/ __ \
  43.   / /_/ / / /_/ /___/ /_/ / /_/ /
  44.   \____/_/\__/_____/\__,_/_.___/
  45.   
  46. Thank you for installing GitLab!
  47. GitLab was unable to detect a valid hostname for your instance.
  48. Please configure a URL for your GitLab instance by setting `external_url`
  49. configuration in /etc/gitlab/gitlab.rb file.
  50. Then, you can start your GitLab instance by running the following command:
  51.   sudo gitlab-ctl reconfigure
  52. For a comprehensive list of configuration options please see the Omnibus GitLab readme
  53. https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
  54. Help us improve the installation experience, let us know how we did with a 1 minute survey:
  55. https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=17-0
  56.   Verifying  : gitlab-ce-17.0.1-ce.0.el7.x86_64                                                                                 1/1
  57. Installed:
  58.   gitlab-ce.x86_64 0:17.0.1-ce.0.el7                                                                                                
  59. Complete!
复制代码
2.9 修改gitlab设置文件
  1. vim  /etc/gitlab/gitlab.rb
  2. # 指定服务器ip和自定义端口
  3. external_url 'http://192.168.164.195:8000'<br># 修改alertmanager 监听地址防止alertmanager组件无法启动<br><br>alertmanager['listen_address'] = '0.0.0.0:9093'
复制代码
  1. [/code][code]# 将8000端口添加到防火墙中
  2. firewall-cmd --zone=public --add-port=8000/tcp --permanent
复制代码
  1. # 重启防火墙
  2. systemctl reload firewalld
复制代码
2.10 重置gitlab
  1. gitlab-ctl reconfigure
复制代码
  1. # 出现下面信息代表充值成功
  2. Notes:
  3. Default admin account has been configured with following details:
  4. Username: root
  5. Password: You didn't opt-in to print initial root password to STDOUT.
  6. Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
  7. 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.
  8. [2024-05-24T16:47:38+08:00] WARN: This release of Cinc Client became end of life (EOL) on May 1st 2024. Please update to a supported release to receive new features, bug fixes, and security updates.
  9. gitlab Reconfigured!
复制代码
2.11 启动gitlab
  1. gitlab-ctl restart
复制代码
  1. [root@VM-8-8-centos yum.repos.d]# gitlab-ctl restart
  2. ok: run: alertmanager: (pid 11174) 0s
  3. ok: run: gitaly: (pid 11203) 0s
  4. ok: run: gitlab-exporter: (pid 11219) 0s
  5. ok: run: gitlab-kas: (pid 11280) 0s
  6. ok: run: gitlab-workhorse: (pid 11289) 0s
  7. ok: run: logrotate: (pid 11299) 1s
  8. ok: run: nginx: (pid 11306) 0s
  9. ok: run: node-exporter: (pid 11312) 1s
  10. ok: run: postgres-exporter: (pid 11319) 0s
  11. ok: run: postgresql: (pid 11332) 0s
  12. ok: run: prometheus: (pid 11334) 0s
  13. ok: run: puma: (pid 11352) 0s
  14. ok: run: redis: (pid 11361) 0s
  15. ok: run: redis-exporter: (pid 11368) 1s
  16. ok: run: sidekiq: (pid 11383) 0s
复制代码
注意:
alertmanager报错Failed to get final advertise address: No private IP address found, and explicit IP no

修改/etc/gitlab/gitlab.rb
alertmanager['listen_address'] = '0.0.0.0:9093'
2.12 访问Gitlab页面

通过服务器ip和指定端口进行访问:

查看初始化密码:
  1. [root@VM-8-8-centos yum.repos.d]# cat /etc/gitlab/initial_root_password
  2. # WARNING: This value is valid only in the following conditions
  3. #          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).
  4. #          2. Password hasn't been changed manually, either via UI or via command line.
  5. #
  6. #          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.
  7. Password: PECffl07TzWOvpTiwZ/Yf8QI7IdTLqHnEbDhvyBBQAE=
  8. # NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
复制代码
 
gitlab完全卸载
  1. [root@sasac-169 ~]# gitlab-ctl stop
  2. ok: down: alertmanager: 0s, normally up
  3. ok: down: gitaly: 1s, normally up
  4. ok: down: gitlab-exporter: 0s, normally up
  5. ok: down: gitlab-workhorse: 0s, normally up
  6. ok: down: grafana: 0s, normally up
  7. ok: down: logrotate: 0s, normally up
  8. ok: down: nginx: 1s, normally up
  9. ok: down: node-exporter: 0s, normally up
  10. ok: down: postgres-exporter: 1s, normally up
  11. ok: down: postgresql: 0s, normally up
  12. ok: down: prometheus: 0s, normally up
  13. ok: down: puma: 0s, normally up
  14. ok: down: redis: 1s, normally up
  15. ok: down: redis-exporter: 0s, normally up
  16. ok: down: sidekiq: 0s, normally up
  17. [root@sasac-169 ~]# rpm -e gitlab-ce
  18. [root@sasac-169 ~]# ps aux | grep gitlab
  19. root      3142  0.0  0.0   4384   484 ?        Ss   00:48   0:00 runsvdir -P /opt/gitlab/service log: ...........................................................................................................................................................................................................................................................................................................................................................................................................
  20. root      3150  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/postgresql
  21. root      3152  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/redis
  22. root      3155  0.0  0.0   4232   348 ?        Ss   00:48   0:00 runsv gitlab-workhorse
  23. root      3159  0.0  0.0   4376   348 ?        S    00:48   0:00 svlogd /var/log/gitlab/sidekiq
  24. root      3161  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/puma
  25. root      3163  0.0  0.0   4232   348 ?        Ss   00:48   0:00 runsv gitlab-exporter
  26. root      3167  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/logrotate
  27. root      3171  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/gitlab-exporter
  28. root      3176  0.0  0.0   4376   544 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/alertmanager
  29. root      3177  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/node-exporter
  30. root      3181  0.0  0.0   4376   544 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/postgres-exporter
  31. root      3182  0.0  0.0   4376   544 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/grafana
  32. root      3183  0.0  0.0   4376   344 ?        S    00:48   0:00 svlogd /var/log/gitlab/gitlab-workhorse
  33. root      3187  0.0  0.0   4376   348 ?        S    00:48   0:00 svlogd /var/log/gitlab/gitaly
  34. root      3190  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/nginx
  35. root      3197  0.0  0.0   4376   540 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/redis-exporter
  36. root      3207  0.0  0.0   4376   544 ?        S    00:48   0:00 svlogd -tt /var/log/gitlab/prometheus
  37. root     20014  0.0  0.0 112812   968 pts/0    S+   01:45   0:00 grep --color=auto gitlab
  38. [root@sasac-169 ~]# kill -9 3142
  39. [root@sasac-169 ~]# find / -name gitlab | xargs rm -rf
复制代码
 
参考连接 :
https://blog.csdn.net/weidu01/article/details/139173493
https://www.cnblogs.com/sylvia-liu/p/15598085.html

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

北冰洋以北

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表