Ubuntu 16.04 搭建 Gitlab

创建
阅读 530

Gitlab 可以用来搭建自己的 git 仓库

目前自建 Gitlab 服务已关闭,因为使用率太低(一个人用),程序太占内存,需要单开一台VPS,不划算,选择 GitHub 会更好~

安装 Gitlab

官方推荐配置

  • 2 cores 以上
  • 2GB of RAM 以上

如果想省一点,1 cores and 1GB of RAM 也是可以安装的(这应该是最低配置了,再低就跑不动了),如果用这样配置必须使用虚拟内存 swap 链接在此

⚠️ 注意:安装时,请 gitlab.yifiankuaile.com 替换成你的域名

  1. 安装依赖环境

    sudo apt-get update
    sudo apt-get install ca-certificates curl openssh-server postfix
    
  2. 安装 Gitlab

    cd /tmp
    curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
    
    sudo bash /tmp/script.deb.sh
    
    sudo apt-get install gitlab-ce
    
  3. 编辑 /etc/gitlab/gitlab.rb 配置文件

    sudo vim /etc/gitlab/gitlab.rb
    

    修改

    external_url 'http://gitlab.yifiankuaile.com'
    

    使配置文件生效

    sudo gitlab-ctl reconfigure
    
  4. 安装完成

    http://gitlab.yifiankuaile.com

配置 Let's Encrypt

安装 Let's Encrypt 客户端

sudo apt-get update
sudo apt-get install letsencrypt

准备 Let's Encrypt 验证 WEB 目录

sudo mkdir -p /var/www/letsencrypt

编辑 gitlab.rb 配置文件

sudo vi /etc/gitlab/gitlab.rb

将下面配置文件加入到添加 gitlab.rb

['custom_gitlab_server_config'] = "location ^~ /.well-known { root /var/www/letsencrypt; }"

是配置文件生效

    sudo gitlab-ctl reconfigure

获取 Let's Encrypt 证书 (将 gitlab.yifiankuaile.com 替换成你的域名)

sudo letsencrypt certonly -a webroot -w /var/www/letsencrypt -d gitlab.yifiankuaile.com

编辑gitlab.rb配置文件

sudo vi /etc/gitlab/gitlab.rb

将 URL 修改为以 https 开头

external_url 'https://gitlab.yifiankuaile.com'

配置 nginx 部分,添加你的证书路径

nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/letsencrypt/live/gitlab.yifiankuaile.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/gitlab.yifiankuaile.com/privkey.pem"

使配置文件生效

sudo gitlab-ctl reconfigure

这时你访问你的网站时候,将自动重 http 跳转到 https。

http://gitlab.yifiankuaile.com

配置 Let's Encrypt 自动更新

sudo crontab -e 加入以下内容

 0 0 1 * * /usr/bin/letsencrypt renew >> /var/log/le-renew.log
 5 0 1 * * /usr/bin/gitlab-ctl restart nginx

这样 Let's Encrypt 证书会每月自动更新

更新日志

  • 2016 年 09 月 11 日 首次发布
  • 2016 年 12 月 01 日 添加 Let's Encrypt 自动更新
  • 2017 年 3 月 06 日 关闭自建 Gitlab 服务。

参考链接:

  1. GitLab 下载
  2. How To Install and Configure GitLab on Ubuntu 16.04
  3. How To Secure GitLab with Let's Encrypt on Ubuntu 16.04

本文链接 https://www.yidiankuaile.com/post/ubuntu-install-gitlab