gitlab搭建整体过程以及遇到的坑

爱被打了一巴掌 2023-07-04 04:49 16阅读 0赞

首先登陆这个网址选择你的虚拟机:https://about.gitlab.com/install

我选择了centos7,跳转至https://about.gitlab.com/install/#centos-7

就可以看到安装的步骤了,直接抄就可以。

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTIwNDUwNDU_size_16_color_FFFFFF_t_70

第一步:

  1. sudo yum install -y curl policycoreutils-python openssh-server
  2. sudo systemctl enable sshd
  3. sudo systemctl start sshd
  4. sudo firewall-cmd --permanent --add-service=http
  5. sudo firewall-cmd --permanent --add-service=https
  6. sudo systemctl reload firewalld

依次执行就可以。

在执行到 sudo firewall-cmd —permanent —add-service=http的时候可能会报错,说防火墙没有开或者防火墙进程被锁了(“firewalld.service: Unit is masked”)。解决方法见:https://blog.csdn.net/Searchin_R/article/details/83933232

可以通过以下方式解决。

1、启动防火墙:

systemctl start firewalld

2、关闭防火墙:

systemctl stop firewalld

3、添加放行端口:

firewall-cmd —zone=public —add-port=8161/tcp —permanent (—permanent永久生效,没有此参数重启后失效)

4、锁定防火墙服务(防止添加端口等操作):

systemctl mask firewalld

5、取消锁定:

systemctl unmask firewalld

第二步:

  1. sudo yum install postfix
  2. sudo systemctl enable postfix
  3. sudo systemctl start postfix

依次执行即可。

第三步:开始安装

离线下载gitlab-ce-11.7.5-ce.0.el7.x86_64.rpm ,地址为https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

上传到/opt 目录下

执行安装命令:rpm -ivh gitlab-ce-11.7.5-ce.0.el7.x86_64.rpm

第四步:

GitLab 的相关参数配置都存在 /etc/gitlab/gitlab.rb文件里。GitLab需要你设置好哪个url才是用户可以访问到GitLab,需要编辑下面这个文件

执行命令:vi /etc/gitlab/gitlab.rb

修改下面两个参数:

external_url ‘http://192.168.31.129:9901‘ external_url 应该是你的ip加你新定义的端口,这里我设置了9901,防止端口冲突

unicorn[‘port’] = 48080 这个端口号我设置为48080,也是为了防止端口冲突

第五步

# 配置并启动 gitlab-ctl reconfigure

第六步:

启动 gitlab-ctl start

gitlab-ctl status #查看服务状态;

第七步:端口开通:参考:https://blog.csdn.net/Honnyee/article/details/81535464

添加

firewall-cmd —zone=public —add-port=9901/tcp —permanent (—permanent永久生效,没有此参数重启后失效)

添加端口外部访问权限(这样外部才能访问)
firewall-cmd —add-port=9901/tcp

重新载入,添加端口后重新载入才能起作用

firewall-cmd —reload

这些之后,端口是开启成功的,如果没有成功,重启系统试试。

查看开启了哪些端口

firewall-cmd —list-ports

第八步:访问 http://192.168.31.129:9901 可以看到gitlab首页。可能会出现502,是因为gitlab比较耗费内存,所以需要修改一下虚拟机的配置。参考:https://www.cnblogs.com/zyb2016/p/11051917.html

  1. [root@yoyo sbin]# cat /proc/swaps
  2. Filename Type Size Used Priority
  3. [root@yoyo sbin]# free
  4. total used free shared buff/cache available
  5. Mem: 3881692 3219200 369316 52184 293176 360244
  6. Swap: 0 0 0
  7. [root@yoyo sbin]# dd if=/dev/zero of=/mnt/swap bs=512 count=8388616
  8. 8388616+0 records in
  9. 8388616+0 records out
  10. 4294971392 bytes (4.3 GB) copied, 38.5364 s, 111 MB/s
  11. [root@yoyo sbin]# mkswap /mnt/swap
  12. Setting up swapspace version 1, size = 4194304 KiB
  13. no label, UUID=1fa0acbf-ef66-49bd-ad05-e9fcf2727cc8
  14. [root@yoyo sbin]# vim /etc/sysctl.conf
  15. # vm.swappiness中的数值是否为0,如果为0则根据实际需要调整成60
  16. 修改前
  17. vm.swappiness = 0
  18. net.ipv4.neigh.default.gc_stale_time=120
  19. 修改后
  20. vm.swappiness = 60
  21. net.ipv4.neigh.default.gc_stale_time=120
  22. [root@yoyo sbin]# swapon /mnt/swap
  23. swapon: /mnt/swap: insecure permissions 0644, 0600 suggested.
  24. [root@yoyo sbin]# echo “/data/swap swap swap defaults 0 0 >> /etc/fstab
  25. [root@yoyo sbin]# cat /proc/swaps
  26. Filename Type Size Used Priority
  27. /mnt/swap file 4194304 0 -1
  28. [root@yoyo sbin]# free
  29. total used free shared buff/cache available
  30. Mem: 3881692 3387168 165488 52184 329036 200184
  31. Swap: 4194304 0 4194304

然后重新配置gitlab,gitlab-ctl reconfigure gitlab-ctl start 就会发现已经非常快了。

此时只是创建了root这一个用户,但是后续我们需要帮同事创建用户,创建用户的时候必须输入邮箱,因为需要给你发邮件来确认密码。这个时候有一个坑,就是你死活收不到邮件,解决方法见:https://blog.csdn.net/SirLZF/article/details/88998450

大致主要是两个原因,一个是默认端口号被限制了,一个是smtp邮箱有问题,直接上操作

vi /etc/gitlab/gitlab.rb

然后进行配置:

gitlab_rails[‘smtp_enable’] = true
gitlab_rails[‘smtp_address’] = “smtp.qq.com”
gitlab_rails[‘smtp_port’] = 465
gitlab_rails[‘smtp_user_name’] = “1332947109@qq.com
gitlab_rails[‘smtp_password’] = “ygeshvaberduhccg”
gitlab_rails[‘smtp_domain’] = “smtp.qq.com”
gitlab_rails[‘smtp_authentication’] = “login”
gitlab_rails[‘smtp_enable_starttls_auto’] = true
gitlab_rails[‘smtp_tls’] = true
gitlab_rails[‘gitlab_email_from’] = ‘1332947109@qq.com

然后重新配置gitlab

gitlab-ctl reconfigure
gitlab-ctl restart

gitlab-rails console

Notify.test_email(‘1332947109@qq.com’,’email title’,’email content desc’).deliver_now

此时你会发现可以收到邮件了,哈哈哈~

发表评论

表情:
评论列表 (有 0 条评论,16人围观)

还没有评论,来说两句吧...

相关阅读