中国平面设计网,企业网站优化多少钱,西宁网站建设君博首选,关键词挖掘爱网站作者#xff1a; 宋发元 最后更新时间#xff1a;2024-12-24 GitLab安装及使用教程
官方教程 https://docs.gitlab.com/ee/install/docker.html
Docker安装GitLab
宿主机创建容器持久化目录卷
mkdir -p /docker/gitlab/{config,data,logs}拉取GitLab镜像
docker pull gi… 作者 宋发元 最后更新时间2024-12-24 GitLab安装及使用教程
官方教程 https://docs.gitlab.com/ee/install/docker.html
Docker安装GitLab
宿主机创建容器持久化目录卷
mkdir -p /docker/gitlab/{config,data,logs}拉取GitLab镜像
docker pull gitlab/gitlab-ce:15.3.1-ce.0运行GitLab容器注意修改IP为你的宿主机IP
docker run -d \
-p 8888:80 \
-p 2222:22 \
-v /docker/gitlab/config:/etc/gitlab \
-v /docker/gitlab/data:/var/opt/gitlab \
-v /docker/gitlab/logs:/var/log/gitlab \
-e GITLAB_OMNIBUS_CONFIGexternal_url http://192.168.2.110; gitlab_rails[gitlab_shell_ssh_port] 2222; gitlab_rails[time_zone] Asia/Shanghai \
-e TZAsia/Shanghai \
--memory 16G \
--cpus8 \
--restart always \
--name gitlab \
gitlab/gitlab-ce:15.3.1-ce.0浏览器访问GitLab
查看初始密码
docker exec -it gitlab grep Password: /etc/gitlab/initial_root_password浏览器登录Gitlab http://IP:8888 账号root 密码【上一步查看的密码】 设置可见性和访问控制
操作路径Admin Area Settings General Visibility and access controls 修改超级管理员密码 关闭用户自动注册功能
以root权限登录在Gitlab的主菜单上选择Menu -- Admin如下所示
在弹出的页面中取消掉Sign-up enabled选项前面的勾然后点击底部的Save changes后就可以使得我们的配置生效了。这样在登录的时候就无法实现自动注册了。如下所示
创建用户
在首页找到管理员如图所示
点击小人图标
找到Users创建用户
填写相关信息 注意需要填写一下email用于给被创建用户发送初始登录密码。
创建组
Gitlab上创建项目时由于新项目的创建必须依赖于一个组因此我们在创建项目前先创建组如下所示 输入组的名称和描述组的URL会随着组名称的输入而自动出现在组的权限处我们选择Private配置完成后如下所示 点击最下方的Create Group就可以完成组的创建了。
创建项目
项目的创建与组的创建过程类似都是输入项目名称选择组的名称项目描述以及权限等。
建议直接在组下创建项目有三种方式创建空项目、根据模板创建、从其他代码仓库迁移根据个人情况选择
修改语言
系统默认为英文如果需要修改为中文操作如下。
刷新浏览器即可切换为中文显示
数据备份与恢复
数据备份
进入老Gitlab的docker容器
# 进入docker容器
docker exec -it gitlab bash备份数据
# 备份数据在gitlab容器内执行
gitlab-rake gitlab:backup:create /var/opt/gitlab/backups/# 备份结束信息
2024-12-24 03:01:37 0000 -- Dumping repositories ... done
2024-12-24 03:01:37 0000 -- Dumping uploads ...
2024-12-24 03:01:37 0000 -- Dumping uploads ... done
2024-12-24 03:01:37 0000 -- Dumping builds ...
2024-12-24 03:01:37 0000 -- Dumping builds ... done
2024-12-24 03:01:37 0000 -- Dumping artifacts ...
2024-12-24 03:01:41 0000 -- Dumping artifacts ... done
2024-12-24 03:01:41 0000 -- Dumping pages ...
2024-12-24 03:01:41 0000 -- Dumping pages ... done
2024-12-24 03:01:41 0000 -- Dumping lfs objects ...
2024-12-24 03:01:41 0000 -- Dumping lfs objects ... done
2024-12-24 03:01:41 0000 -- Dumping terraform states ...
2024-12-24 03:01:41 0000 -- Dumping terraform states ... done
2024-12-24 03:01:41 0000 -- Dumping container registry images ... [DISABLED]
2024-12-24 03:01:41 0000 -- Dumping packages ...
2024-12-24 03:01:41 0000 -- Dumping packages ... done
2024-12-24 03:01:41 0000 -- Creating backup archive: 1735009265_2024_12_24_15.3.1_gitlab_backup.tar ...
2024-12-24 03:01:42 0000 -- Creating backup archive: 1735009265_2024_12_24_15.3.1_gitlab_backup.tar ... done
2024-12-24 03:01:42 0000 -- Uploading backup archive to remote storage ... [SKIPPED]
2024-12-24 03:01:42 0000 -- Deleting old backups ... [SKIPPED]
2024-12-24 03:01:42 0000 -- Deleting tar staging files ...
2024-12-24 03:01:42 0000 -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
2024-12-24 03:01:42 0000 -- Cleaning up /var/opt/gitlab/backups/db
2024-12-24 03:01:42 0000 -- Cleaning up /var/opt/gitlab/backups/repositories
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz
2024-12-24 03:01:43 0000 -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz
2024-12-24 03:01:43 0000 -- Deleting tar staging files ... done
2024-12-24 03:01:43 0000 -- Deleting backups/tmp ...
2024-12-24 03:01:43 0000 -- Deleting backups/tmp ... done
2024-12-24 03:01:43 0000 -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
2024-12-24 03:01:43 0000 -- Backup 1735009265_2024_12_24_15.3.1 is done.拷贝备份文件1735009265_2024_12_24_15.3.1_gitlab_backup.tar到新服务器宿主机目录/docker/gitlab/data/backups/。
备份配置文件
把旧宿主机目录/docker/gitlab/config下的gitlab.rb和gitlab-secrets.json两个配置文件也备份并拷贝到新服务器宿主机目录/docker/gitlab/config下。
数据恢复
上传备份文件1735009265_2024_12_24_15.3.1_gitlab_backup.tar到新Gitlab的宿主机目录/docker/gitlab/data/backups/。
上传备份配置文件gitlab.rb和gitlab-secrets.json到新GitLab的宿主机目录/docker/gitlab/config。
修改权限
修改备份文件权限
# 修改备份文件权限
chown git.git 1735009265_2024_12_24_15.3.1_gitlab_backup.tar 数据恢复 # 进入docker容器docker exec -it gitlab bash# 停止相关数据连接服务gitlab-ctl stop unicorngitlab-ctl stop sidekiq# 备份文件数据恢复这里注意文件名gitlab-rake gitlab:backup:restore BACKUP备份文件编号gitlab-rake gitlab:backup:restore BACKUP1735009265_2024_12_24_15.3.1# 备份开始信息
2024-12-24 03:25:32 0000 -- Unpacking backup ...
2024-12-24 03:25:34 0000 -- Unpacking backup ... done
2024-12-24 03:25:34 0000 -- Restoring main_database ...
2024-12-24 03:25:34 0000 -- Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installationsBefore restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.Do you want to continue (yes/no)? yes
Removing all tables. Press Ctrl-C within 5 seconds to abort
2024-12-24 11:25:48 0800 -- Cleaning the database ...
2024-12-24 11:25:50 0800 -- done# 备份结束信息
2024-12-24 03:26:40 0000 -- Restoring repositories ... done
2024-12-24 03:26:40 0000 -- Restoring uploads ...
2024-12-24 03:26:40 0000 -- Restoring uploads ... done
2024-12-24 03:26:40 0000 -- Restoring builds ...
2024-12-24 03:26:40 0000 -- Restoring builds ... done
2024-12-24 03:26:40 0000 -- Restoring artifacts ...
2024-12-24 03:26:40 0000 -- Restoring artifacts ... done
2024-12-24 03:26:40 0000 -- Restoring pages ...
2024-12-24 03:26:40 0000 -- Restoring pages ... done
2024-12-24 03:26:40 0000 -- Restoring lfs objects ...
2024-12-24 03:26:40 0000 -- Restoring lfs objects ... done
2024-12-24 03:26:40 0000 -- Restoring terraform states ...
2024-12-24 03:26:40 0000 -- Restoring terraform states ... done
2024-12-24 03:26:40 0000 -- Restoring packages ...
2024-12-24 03:26:40 0000 -- Restoring packages ... done
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes2024-12-24 03:26:48 0000 -- Deleting tar staging files ...
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/db
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/repositories
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz
2024-12-24 03:26:48 0000 -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz
2024-12-24 03:26:48 0000 -- Deleting tar staging files ... done
2024-12-24 03:26:48 0000 -- Deleting backups/tmp ...
2024-12-24 03:26:48 0000 -- Deleting backups/tmp ... done
2024-12-24 03:26:48 0000 -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
2024-12-24 03:26:48 0000 -- Restore task is done.至此GitLab数据迁移已完成登录新的GitLab即可查看数据
问题解决
超级管理员密码重置
如果root账户密码不正确则需要重新设置步骤如下
# 首先进入gitlab容器内
docker exec -it gitlab /bin/bash
# 进入控制台这步需要等待一会
gitlab-rails console -e production
# 查询root用户即id为1
userUser.where(id:1).first
# 设置密码
user.password123456789
# 保存
user.save!
# 退出
exit修改权限
如果启动时报错各种权限问题可以执行这个指令。
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.mdIf this container fails to start due to permission problems try to fix it by executing:docker exec -it gitlab update-permissionsdocker restart gitlab修改配置暂未使用到
vim /docker/gitlab/config/gitlab.rb
# gitlab访问地址
external_url http://192.168.2.110
# ssh连接端口
gitlab_rails[gitlab_shell_ssh_port] 2222
# 时区
gitlab_rails[time_zone] Asia/Shanghai让配置生效
docker exec -it gitlab gitlab-ctl reconfigure重启gitlab服务
docker exec -it gitlab gitlab-ctl restart