gitlab-ce搭建和数据迁移

本文提供了一套详细的步骤来帮助您在CentOS 7上安装和配置GitLab,包括设置服务器环境、安装GitLab软件包、配置基本参数、数据备份与恢复流程等关键环节。

2022年11月1日08:26:03

centos7国内地址 :注意对应的系统版本,下一个最新版本

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

因为数据导入导出使用的是gitlab导出 gitlab导入,不需要在乎版本是否匹配,只要能到出,导入成功即可

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.5.1-ce.0.el7.x86_64.rpm

yum -y install policycoreutils openssh-server openssh-clients postfix policycoreutils-python curl
yum install gitlab-ce-15.5.1-ce.0.el7.x86_64.rpm

系统默认密码:cat /etc/gitlab/initial_root_password

修改防火墙和selinux
vi /etc/selinux/config,将SELINUX=enforcing改为SELINUX=disabled

systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service

修改配置后的初始化
gitlab-ctl reconfigure
启动
sudo gitlab-ctl start
停止
sudo gitlab-ctl stop
重启
sudo gitlab-ctl restart
开机启动
systemctl enable gitlab-runsvdir.service
禁止开
### 搭建 GitLab 17.4.1 版本并集成 Jenkins 实现 CI/CD 流水线 #### 一、GitLab 17.4.1 的安装与配置 为了搭建 GitLab 17.4.1,可以通过 Docker 部署的方式快速启动服务: ```bash docker stop gitlab-previous-version-container-name vim gitlab-update-to-latest.sh #!/bin/bash GITLAB_HOME='/opt/gitlab' docker run -d --hostname gitlab.example.com \ -p 443:443 -p 80:80 -p 2222:22 \ --name gitlab-17.4.1-ce.0 \ -v $GITLAB_HOME/config:/etc/gitlab:Z \ -v $GITLAB_HOME/logs:/var/log/gitlab:Z \ -v $GITLAB_HOME/data:/var/opt/gitlab:Z \ --shm-size 256m \ gitlab/gitlab-ce:17.4.1-ce.0 sh gitlab-update-to-latest.sh docker logs -f gitlab-17.4.1-ce.0 ``` 上述脚本用于更新到指定版本的 GitLab[^1]。 #### 二、Jenkins 集成实现 CI/CD 流水线 要将 GitLab 与 Jenkins 集成以支持 CI/CD 流程,需执行以下操作: 1. **创建 Webhook** 在 GitLab 中进入目标仓库设置 -> Webhooks 页面,添加一个新的 webhook 地址指向 Jenkins Server URL (e.g., `http://jenkins-server-url/job/project/build?token=TOKEN`)。 2. **配置 Jenkins 插件** 安装并启用 “GitLab Plugin”,在 Jenkins 系统管理中配置 GitLab 连接信息(API Token Host)。随后,在构建任务中选择触发器为“Build when a change is pushed to GitLab”。 3. **定义流水线脚本** 使用 Jenkinsfile 或手动编写 Pipeline 脚本来描述完整的 CI/CD 步骤。例如: ```groovy pipeline { agent any stages { stage('Checkout') { steps { git branch: 'main', url: 'https://gitlab.example.com/group/repo.git' } } stage('Test') { steps { echo 'Running tests...' sh './run-tests.sh' } } stage('Deploy') { steps { echo 'Deploying application...' sh './deploy-wordpress.sh' } } } } ``` 此脚本会依次完成代码拉取、测试运行以及应用部署的任务[^4]。 #### 三、WordPress 代码托管于 GitLab 将 WordPress 应用程序存储库迁移到 GitLab 上非常简单。只需初始化本地 Git 仓库并将远程地址设为新建立好的 GitLab Repository 即可推送全部历史记录过去。 ```bash cd /path/to/wordpress/ git init . git add . git commit -m "Initial import of WordPress project" git remote add origin https://gitlab.example.com/user-or-group/wordpress-repository.git git push -u origin main ``` 这样就完成了从现有环境向 GitLab 托管转移的过程。 #### 四、GitLab 数据备份与恢复策略 对于定期维护而言,实施有效的数据保护措施至关重要。以下是基于命令行工具制作完整快照的方法: ##### 备份过程 利用官方提供的指令生成压缩包形式的数据副本存放在默认路径下 `/var/opt/gitlab/backups` 文件夹里。 ```bash sudo gitlab-backup create STRATEGY=copy cp -a /etc/gitlab/gitlab.rb{,.bak} && cp -a /etc/gitlab/gitlab-secrets.json{,.bak} tar czvf ~/backup-gitlab-config.tar.gz /etc/gitlab/* rsync -avz /var/opt/gitlab/* /mnt/storage/gitlab_backup/ ``` 以上步骤涵盖了数据库表单结构连同附件在内的全方位保存机制[^2]。 ##### 恢复流程 当发生意外丢失情况时,则按照如下指南重新导入先前保留下来的档案资料集回到当前实例当中去。 ```bash mv /var/opt/gitlab/backups/<timestamp>_gitlab_backup.tar /tmp/ chown git:git /tmp/<timestamp>_gitlab_backup.tar gitlab-rake gitlab:backup:restore BACKUP=<timestamp> systemctl restart gitlab-runsvdir.service ``` 注意替换 `<timestamp>` 参数值为你实际拥有的有效时间戳编号。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值