安裝 docker 及 docker-compose
centos8 更新源
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
gitlab 伺服器 IP:192.168.0.666,埠 80
安裝 docker
### CentOS8 預設是會讀取centos.org的mirrorlist的,所以一般來說是不需要配置映象的。
(Refer to: https://www.linuxidc.com/Linux/2019-10/161212.htm)
# step 1: 安裝必要的一些系統工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# step 2: 更新 container.io 包, 否則可能會報 `package docker-ce-3:19.03.13-3.el7.x86_64 requires containerd.io >= 1.2.2-3, ...`的錯
# 可在 https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/Packages/ 下找最新版安裝
sudo dnf install -y --allowerasing https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/Packages/containerd.io-1.6.6-3.1.el8.x86_64.rpm
# Step 3: 安裝Docker-CE
sudo yum install -y docker-ce
# Step 4: 開啟Docker服務並設定開機自啟
sudo systemctl start docker && sudo systemctl enable docker
# 測試, 如輸出版本號則安裝成功
docker version
docker 安裝參考:https://www.jianshu.com/p/18c1abe97b2a
配置 gitlab
docker-compose.yml
version: '2'
services:
gitlab:
image: 'gitlab/gitlab-ce'
container_name: "gitlab"
restart: unless-stopped
privileged: true
hostname: 'gitlab.xxxx.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.xxxx.com'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
ports:
- '80:80'
volumes:
- /app/gitlab/config:/etc/gitlab
- /app/gitlab/data:/var/opt/gitlab
- /app/gitlab/logs:/var/log/gitlab
執行: docker-compose up -d
配置 nginx 指向 gitlab 服務
server {
server_name gitlab.xxxx.com;
listen 80;
keepalive_timeout 70;
location / {
proxy_pass_header Server;
proxy_redirect off;
set $outhost "gitlab.xxxx.com";
proxy_set_header Host $outhost;
proxy_pass http://192.168.0.666:80;
proxy_set_header x-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
}
}
重置 gitlab 賬號密碼,無法傳送郵件
docker exec -it gitlab gitlab-rails console
user = User.where(username:"xxxx").first
user.password="aabb12223"
user.save!
備份
將備份指令碼放到 /app/gitlab/data 目錄中
#獲取當前系統時間
date=`date +%Y_%m_%d`
#臨時備份目錄
out_dir='/var/opt/gitlab/backups/'
#備份存放路徑
tar_dir='/var/opt/gitlab/bak_tar/'
#DAYS=15代表刪除15天前的備份,即只保留近15天的備份
days='15'
tar_bak=$date'.tar.gz'
mkdir -p $tar_dir
cd $out_dir
rm -rf $out_dir*
#備份資料
gitlab-rake gitlab:backup:create
#最終儲存的資料庫備份檔案
bakfile=$(ls -lt $out_dir | grep tar | head -n 1 |awk '{print $9}')
cd $out_dir
#壓縮為.tar.gz格式
tar -zcvPf $tar_dir$tar_bak $bakfile
#刪除15天前的備份檔案
find $tar_dir -mtime +$days -delete
rm -rf $out_dir*
exit
執行備份:docker exec -i gitlab /bin/bash -c 'sh /var/opt/gitlab/gitlab_bak_data.sh'
將備份檔案複製到本地目錄,並刪除歷史 10 天前的檔案
echo 'bak gitlab'
scp -r root@192.168.0.666:/app/gitlab/data/bak_tar/ /d/gitlab/
./find.exe /d/gitlab/bak/ -mtime +10 -delete
echo
gitlab 備份還原參考:https://juejin.cn/post/7031027881484484644