CentOS 安装 GitLab

3,096 阅读2分钟

服务器内存最小为 4G。否则 502!

Let's go

  1. 下面的命令将打开系统防火墙中的HTTP、HTTPS和SSH访问。当前步骤遇到的问题
    // 安装 policycoreutils-python openssh-server
    yum install -y curl policycoreutils-python openssh-server 
    // 将 SSH 服务设置成开机自启动
    systemctl enable sshd
    // 启动 SSH 服务
    systemctl start sshd
    // 添加 http/https 服务到 firewalld, permanent 表示永久生效,若不加 --permanent 系统下次启动后就会失效。
    firewall-cmd --permanent --add-service=http
    firewall-cmd --permanent --add-service=https
    // 重启防火墙
    systemctl reload firewalld
    
  2. 安装 Postfix 用来发送通知邮件。
    // 安装 postfix
    yum install postfix
    // 将 postfix 服务设置成开机自启动
    systemctl enable postfix
    // 启动postfix
    systemctl start postfix
    
  3. 安装 wget 用于从外网下载插件。
    yum -y install wget 
    
  4. 安装 vim 编辑器。
    yum install vim -y
    
  5. 添加 GitLab 包存储库并安装安装包。各个版本安装包
    // 添加 GitLab 镜像
    wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-12.10.3-ce.0.el6.x86_64.rpm/download.rpm
    // 安装 GitLab
    rpm -i gitlab-ce-12.10.3-ce.0.el6.x86_64.rpm
    
  6. 修改 GitLab 配置文件指定服务器 ip 和自定义端口。当前步骤遇到的问题
    // 默认是 8080 端口,如果 8080 已被占用,需更改为其它端口,并在防火墙开放对应端口
    vim  /etc/gitlab/gitlab.rb
    // 修改配置文件中的 external_url 'http://ip:port'
    // 改完之后执行重置
    gitlab-ctl reconfigure
    // 重启
    gitlab-ctl restart
    
  7. 测试是否可以访问。当前步骤遇到的问题
    curl localhost:port/gitlab
    
  8. 提示如下则为成功。
    成功展示
  9. 页面访问 GitLab
    • 如果没有域名,直接输入服务器ip和端口访问
    • 第一访问直接重定向至更改密码界面进行更改密码

遇到的问题

  1. 执行 firewall-cmd --permanent --add-service=http 的时候提示 FirewallD is not running. 因为防火墙没有开启导致的

    • 通过 systemctl status firewalld 查看 firewalld 状态,发现当前是 dead 状态,即防火墙未开启。
    • 通过 systemctl start firewalld 开启防火墙。
    • 再次通过 systemctl status firewalld 查看 firewalld 状态,显示 running 即已开启了。
  2. 执行 gitlab-ctl reconfigure 时提示 ruby_block[wait for redis service socket] action run

    • Ctrl + C 强制结束。
    • 执行 systemctl restart gitlab-runsvdir
    • 再次执行 gitlab-ctl reconfigure
    • 再次执行 gitlab-ctl restart
  3. 执行 gitlab-ctl restart 提示 warning: redis: unable to open supervise/ok: file does not exist

  4. 如果 linux 可以访问,但是远程无法访问:这种情况多半是因为 Centos 的防火墙没有开放端口号。

    • 执行 firewall-cmd --zone=public --add-port=8090/tcp --permanent
    • --zone // 作用域
    • --add-port=8090/tcp // 添加端口,格式为:端口/通讯协议
    • --permanent // 永久生效,没有此参数重启后失效
    • systemctl stop firewalld.service // 关闭防火墙
    • systemctl start firewalld.service // 开启防火墙
    • firewall-cmd --reload // 重启防火墙
    • firewall-cmd --zone=public --query-port=80/tcp // 查看防火墙是否开启该端口,yes 表示已经开启
  5. GitLab 清除缓存

    • gitlab-rake cache:clear