版本管理 GitLab

Summary: Author: 张亚飞 | 阅读时间: 4 minute read | Published: 2016-08-08
Filed under Categories: DevOpsTags: Linux, Server, Software, DevOps,

GitLab 安装配置

Ubuntu 安装 GitLab 版本管理工具

  1. 准备安装环境
sudo apt update
sudo apt install curl openssh-server ca-certificates postfix
  1. 安装 Gitlab

在这一步中,我们将使用综合包来安装 GitLab. Omnibus 将安装在服务器上运行 GitLab 所需的所有软件包,服务和工具

使用 curl 命令添加 GitLab 存储库

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

然后使用 apt 命令安装 GitLab CE Community Edition

sudo apt install gitlab-ce

配置文件在 /etc/gitlab/gitlab.rb

注意: GitLab 自带 Nginx ,需关闭本机的 nginx 后才能启动 https://git.iirii.com 网站管理后台

  1. git.iirii.com 生成 SSL 证书

参见 letsencrypt 证书

  1. 配置 GitlabURL

/etc/gitlab/gitlab.rb

external_url ‘https://git.iirii.com’

nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/letsencrypt/archive/iirii.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/archive/iirii.com/privkey.pem"
nginx['ssl_dhparam'] = "/etc/letsencrypt/archive/certify/dhparam.pem" # Path to dhparams.pem, eg. /etc/gitlab/ssl/dhparams.pem
  1. 重载配置文件
sudo gitlab-ctl reconfigure
  1. 启动服务
sudo gitlab-ctl start
sudo gitlab-ctl status

如果禁止开机自启动服务…

sudo systemctl disable gitlab-runsvdir.service
  • 修改配置后重新执行 gitlab-ctl reconfigure 后卡在以下界面:
ruby_block[supervise_redis_sleep] action run

重开一个终端执行以下命令:

/opt/gitlab/embedded/bin/runsvdir-start &

Nginx 反向代理到 GitLab-Nginx 端口

  1. 由于服务器已安装了 Nginx,可以修改 GitLab-Nginx 端口,使用本地 Nginx 反向代理到 GitLab-Nginx

/etc/gitlab/gitlab.rb

nginx['redirect_http_to_https_port'] = 88
nginx['listen_port'] = 843

最终的配置为:

/etc/gitlab/gitlab.rb

external_url 'https://git.iirii.com'

nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
nginx['redirect_http_to_https'] = true
nginx['redirect_http_to_https_port'] = 88

nginx['ssl_certificate'] = "/etc/letsencrypt/archive/iirii.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/archive/iirii.com/privkey.pem"
nginx['ssl_dhparam'] = "/etc/letsencrypt/archive/certify/dhparam.pem"

nginx['listen_port'] = 843

重载配置后访问 https://git.iirii.com:843/

  1. 使用本机 Nginx 反向代理到 GitLab-Nginx 843 Https 端口

/etc/nginx/sites-coam/A_Common.IIRII.conf

upstream git{
    # 域名对应 gitlab配置中的 external_url
    # 端口对应 gitlab 配置中的 nginx['listen_port']
    server  git.iirii.com:843;
}

# https 跳转
server{
    listen 80;
    listen [::]:80;

    # 此域名是提供给最终用户的访问地址
    server_name git.iirii.com;

    # Common Server redirect rules
    include /etc/nginx/coam.include.d/common_server_redirect.conf;
}

server{
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # 此域名是提供给最终用户的访问地址
    server_name git.iirii.com;

    location / {
        # 这个大小的设置非常重要,如果 git 版本库里面有大文件,设置的太小,文件push 会失败,根据情况调整
        client_max_body_size 50m;

        proxy_redirect off;
        #以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # 反向代理到 gitlab 内置的 nginx
        proxy_pass https://git;
        index index.html index.htm;
    }
}

重启本地 Nginx 服务

sudo systemctl restart cs-nginx

重启 Nginx 后可直接访问 https://git.iirii.com

注意: 如果开启了 GitLab-Nginx 服务再重启 Nginx 失败,可能是端口有冲突,我设置 nginx['redirect_http_to_https_port'] = 88 解决此问题…

本次配置开启 GitLab-Nginx 843 Https 端口 ,如果要使用 80 端口,请参考以下配置:


GitLab 邮件服务

  • 腾讯企业邮箱
#gitlab_rails['smtp_enable'] = true
#gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
#gitlab_rails['smtp_port'] = 465
#gitlab_rails['smtp_user_name'] = "zyf@lonal.com"
#gitlab_rails['smtp_password'] = "ZYF_bin312"
#gitlab_rails['smtp_authentication'] = "login"
#gitlab_rails['smtp_enable_starttls_auto'] = true
#gitlab_rails['smtp_tls'] = true
#gitlab_rails['gitlab_email_from'] = 'zyf@lonal.com'
  • Aliyun Direct Mail(阿里云邮件推送)
gitlab_rails['gitlab_email_from'] = 'sy@mail.coam.co'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtpdm.aliyun.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "sy@mail.coam.co"
gitlab_rails['smtp_password'] = "COAMbin312"
gitlab_rails['smtp_domain'] = "mail.coam.co"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_ssl'] = true

注意: 阿里云 DirectMail 邮件推送服务 gitlab_rails['gitlab_email_from']gitlab_rails['smtp_user_name'] 必须一致,否则发送邮件提示如下错误:

Net::SMTPServerBusy: 436 “MAIL FROM” doesn’t conform with authentication @sm060104

  • 重载配置文件
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
  • 测试邮件推送服务
Notify.test_email('zyf@lonal.com', 'Message Subject', 'Message Body').deliver_now
Sun Sep 03 11:42:52 coam@as:/etc/gitlab$ sudo gitlab-rails console
Loading production environment (Rails 4.2.8)
irb(main):002:0> Notify.test_email('zyf@lonal.com', 'Message Subject', 'Message Body').deliver_now

Notify#test_email: processed outbound mail in 0.8ms

Sent mail to zyf@lonal.com (595.4ms)
Date: Sun, 03 Sep 2017 11:45:08 +0800
From: GitLab <sy@mail.coam.co>
Reply-To: GitLab <noreply@git.iirii.com>
To: zyf@lonal.com
Message-ID: <59ab7ac4383ad_24d3fb34f1db10898929@as.mail>
Subject: Message Subject
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>Message Body</p></body></html>

=> #<Mail::Message:70039192515220, Multipart: false, Headers: <Date: Sun, 03 Sep 2017 11:45:08 +0800>, <From: GitLab <sy@mail.coam.co>>, <Reply-To: GitLab <noreply@git.iirii.com>>, <To: zyf@lonal.com>, <Message-ID: <59ab7ac4383ad_24d3fb34f1db10898929@as.mail>>, <Subject: Message Subject>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):003:0>

项目自动部署 WebHooks


GitLab 汉化


GitLab 上传问题

上传文件使用 https 方式上传完后卡顿,据说是要修改 https 缓存区,或者切换为 git 方式上传

否则会出现如下错误:

coam@MacPro:~/ServerCoam/wsa$ git push origin master
Counting objects: 9466, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9019/9019), done.
Writing objects: 100% (9466/9466), 66.30 MiB | 588.00 KiB/s, done.
Total 9466 (delta 1713), reused 0 (delta 0)
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@error: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502 Bad Gateway
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Everything up-to-date

我选择第二种方式,修改为 git 模式:

#remote.origin.url=https://git.iirii.com/hospital/Wsa.git
remote.origin.url=git@git.iirii.com:hospital/Wsa.git

但是由于我的 git 服务是开的 SSH 端口是 22312 而不是默认的 22,造成如下错误:

coam@MacPro:~/ServerCoam/wsa$ git push origin master
ssh: connect to host git.iirii.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决办法是在本机设置 ~/.ssh/config 主机端口号

~/.ssh/config

Host git.iirii.com
  Hostname git.iirii.com
  Port 22312

参考列表

Comments

  • Allennex says: 2020-04-09 16:00:02

    Hello everyone! Seek out a demo of the game named X-Hex<a href=http://darude.site>.</a> The idea of the game is this<a href=http://darude.website>.</a> Field rhombuses<a href=http://brodis.website>.</a> On the fields put labels<a href=http://brodis.site>.</a> Thanks to these marks the field grows and becomes bigger<a href=http://brodis.online>.</a> When it begins to touch the opponent’s field<a href=http://gl-grand.website>.</a> Tags begin run across now to the enemy, then back. The winner is the one who conquers the entire field. There bonuses, a call to an aircraft that randomly bombes the enemy’s fields and can hurt yours. Very interesting toy. P<a href=http://adibodobe.site>.</a>S<a href=http://darude.online>.</a> Thanks anyway You can reply to the mail<a href=http://adibodobe.online>:</a> judbayneoranderson@gmail<a href=http://adibodobe.website>.</a>com

Cor-Ethan, the beverage → www.iirii.com