GitLab部署教程(Ubuntu)

  1. 你需要一台服务器,可以各大服务商处嫖一个也可以买;配置最好2G运存,不然挺卡的。

  2. 使用SSH登录服务器(使用 Ubuntu 镜像创建的实例默认禁用 root 用户名通过密码的方式登录实例。如需开启,请参考 Ubuntu系统如何使用root用户登录实例?)。

  1. 前期准备: 测试测试???????????

sudo apt-get update

sudo apt-get install -y curl openssh-server ca-certificates

sudo apt-get install -y postfix

使用左右键和回车键选择确定、取消,弹出列表选项的时候,选择 Internet Site

接着信任 GitLab 的 GPG 公钥:

curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null

配置镜像路径

由于国外的下载速度过慢,所以配置清华大学镜像的路径:

https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

vi /etc/apt/sources.list.d/gitlab-ce.list

写入:(Ubuntu 18.04 LTS)

deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main

  1. 安装配置gitlab-ce并汉化

sudo apt-get update

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/gitlab-ce_12.3.5-ce.0_amd64.deb

dpkg -i gitlab-ce_12.3.5-ce.0_amd64.deb

vim /etc/gitlab/gitlab.rb

external_url修改为你的ip或域名

:wq保存退出

补丁方式汉化:(注意:汉化之前是必须设置 root 密码登录过的,否则有些必须文件没有生成,汉化不成功。但是我第一次配置失败后再次patch又行了)

git clone https://gitee.com/dicer/gitlab.git

cd gitlab

gitlab_version=$(sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION)

cd ..

patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ${gitlab_version}-zh.diff

(报错就一直按住回车,因为有新文件加入)

因为垃圾服务器,要设置swap交换分区,不然不行(可以用free -h查看):

sudo fallocate -l 2G /swapfile(创建文件)

sudo chmod 600 /swapfile(设置权限使该文件只能由root访问)

sudo mkswap /swapfile(将文件标记为swap空间)

sudo swapon /swapfile(启用swap文件)

永久化swap文件:

sudo cp /etc/fstab /etc/fstab.bak

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

调整Swappiness参数:

sudo sysctl vm.swappiness=10

  1. 登录网页配置

参考网页:https://xkcoding.com/2018/01/03/devops-gitlab.html