在CentOS8中安装gitlab

安装 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

posted @ 2022-12-21 08:35  易墨  阅读(905)  评论(0编辑  收藏  举报
Fork me on GitHub