CentOS7 安装配置 GitLab

CentOS7服务器上搭建Gitlab

Gitlab如何搭建?

  1. 安装gitlab所需要的依赖

    sudo yum install curl policycoreutils openssh-server openssh-clients

  2. 使sshd服务自动启动

    sudo systemctl enable sshd

  3. 启动sshd服务

    sudo systemctl start sshd

  4. 安装邮件服务器

    sudo yum install postfix

  5. 使邮件服务器postfix自启动

    sudo systemctl enable postfix

  6. 启动邮件服务器postfix

    sudo systemctl start postfix

  7. 开放防火墙

    sudo firewall-cmd --permanent --add-service=http

  8. 重启防火墙

如何启动GitLab?

  1. 启动,配置

    sudo gitlab-ctl reconfigure

  2. 修改gitlab配置文件指定服务器ip和自定义端口

    vim  /etc/gitlab/gitlab.rb
    
    修改 extenal_url="" 为自己服务器的访问ip+端口或域名

    ps:注意这里设置的端口不能被占用,默认是8080端口,可以定义其它端口,并在防火墙设置开放相对应端口。

    firewall-cmd --permanent --add-port=8888/tcp
    systemctl restart firewalld.service
  3. 重置并启动GitLab

    重新配置
    gitlab-ctl reconfigure
    
    重启
    gitlab-ctl restart

    访问gitlab:http://192.168.0.108:8099/ 或 你的域名
    说明一下,域名访问需要配置Nginx,可用Gitlab内置或外部独立的

  4. 502错误可能的原因

    1. 端口冲突
    2. 内存不足
    3. 外部Nginx访问权限不足
    4. Nginx访问请求连接被重置<我操作时Nginx配置有误导致这个问题,所以在这里mark一下>

如何使用外部Nginx?

  1. 禁用Gitlab内部的Nginx

    vim /etc/gitlab/gitlab.rb
    
    在配置中开启一下配置
    nginx['enable'] = false
  2. 修改外部Nginx配置

    upstream gitlab_server {
      server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
    }
    
    server {
      listen *:80;
    
      server_name gitlab.paipailicai.cn;
    
      server_tokens off;     # don't show the version number, a security best practice
      root /opt/gitlab/embedded/service/gitlab-rails/public;
    
      client_max_body_size 250m;
    
      access_log  /usr/local/ddanglc/gitlab/logs/gitlab_access.log;
      error_log   /usr/local/ddanglc/gitlab/logs/gitlab_error.log;
    
      location / {
        try_files $uri $uri/index.html $uri.html @gitlab;
      }
    
      location @gitlab {
    
        proxy_read_timeout 300; # Some requests take more than 30 seconds.
        proxy_connect_timeout 300; # Some requests take more than 30 seconds.
        proxy_redirect     off;
    
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $http_host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Frame-Options   SAMEORIGIN;
    
        proxy_pass http://gitlab_server;
      }
    
      location ~ ^/(assets)/  {
        root /opt/gitlab/embedded/service/gitlab-rails/public;
        expires max;
        add_header Cache-Control public;
      }
    
      error_page 502 /502.html;
    }
  3. 修改权限配置,让外部Nginx访问gitlab的socket文件

    sudo chmod -R o+x /var/opt/gitlab/gitlab-rails
  4. 重启 nginx, 重启gitlab

    sudo /usr/local/nginx/sbin/nginx -s reload
    sudo gitlab-ctl reconfigure

吃苦耐劳 啃硬骨头

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2
Fallingyou

好使吗?

3个月前

什么问题

[root@VM_0_14_centos ~]# systemctl status postfix.service
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-12-04 20:22:38 CST; 36s ago
  Process: 5899 ExecStart=/usr/sbin/postfix start (code=exited, status=1/FAILURE)
  Process: 5897 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 5893 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=75)

Dec 04 20:22:35 VM_0_14_centos systemd[1]: Starting Postfix Mail Transport Agent...
Dec 04 20:22:36 VM_0_14_centos aliasesdb[5893]: /usr/sbin/postconf: fatal: parameter inet_interfaces: no local interface found for ::1
Dec 04 20:22:37 VM_0_14_centos postfix/sendmail[5896]: fatal: parameter inet_interfaces: no local interface found for ::1
Dec 04 20:22:37 VM_0_14_centos aliasesdb[5893]: newaliases: fatal: parameter inet_interfaces: no local interface found for ::1
Dec 04 20:22:37 VM_0_14_centos postfix[5899]: fatal: parameter inet_interfaces: no local interface found for ::1
Dec 04 20:22:38 VM_0_14_centos systemd[1]: postfix.service: control process exited, code=exited status=1
Dec 04 20:22:38 VM_0_14_centos systemd[1]: Failed to start Postfix Mail Transport Agent.
Dec 04 20:22:38 VM_0_14_centos systemd[1]: Unit postfix.service entered failed state.
Dec 04 20:22:38 VM_0_14_centos systemd[1]: postfix.service failed.
3个月前

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!