官方gitlab docker 版本安装:
链接: https://docs.gitlab.com/omnibus/docker/
1 安装docker
下载路径: https://download.docker.com/linux/ubuntu/dists/ , ubuntu16选择xenial,选择pool,选择edge(目前docker19.03版本还不属于stable版本),选择amd64(一般都是这个,具体参照:https://www.debian.org/ports/index.zh-tw.html),下载containerd.io,docker-ce-cil,docker-ce,因为有依赖关系,按顺序安装,顺序错了会提示你。(dpkg -i 即可)
如果你安装了旧版的docker,需要先卸载:参考官网- https://docs.docker.com/install/linux/docker-ce/ubuntu/
安装:
sudo dpkg -i containerd.io_1.2.6-3_amd64.deb
sudo dpkg -i docker-ce-cli_19.03.9~3-0~ubuntu-xenial_amd64.deb
sudo dpkg -i docker-ce_19.03.9~3-0~ubuntu-xenial_amd64.deb
2 配置环境路径
在设置所有其他内容之前,请配置一个新的环境变量$ GITLAB_HOME,该变量指向配置, 日志和数据文件将保存的路径。
确保该目录已经存在并且已被授予适当的权限(权限这里我没看太懂)。
例如linux下设置: export GITLAB_HOME=/srv/gitlab # 自己的路径, 可以修改
The GitLab container uses host mounted volumes to store persistent data:
Local location | Container location | Usage |
---|---|---|
$GITLAB_HOME/data |
/var/opt/gitlab |
For storing application data |
$GITLAB_HOME/logs |
/var/log/gitlab |
For storing logs |
$GITLAB_HOME/config |
/etc/gitlab |
For storing the GitLab configuration files |
3 安装docker版本gitlab
sudo docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 222:22 --name gitlab --restart always --volume $GITLAB_HOME/config:/etc/gitlab --volume $GITLAB_HOME/logs:/var/log/gitlab --volume $GITLAB_HOME/data:/var/opt/gitlab gitlab/gitlab-ee:latest
其中: --publish对应一些端口, 我在配置的时候22端口被ssh占用了, 所以修改为222:22; --volume为路径映射, 可以参考上表.执行如下:
啊
安装成功.
4 配置访问路径......貌似没有配置也可以...直接访问内网IP地址
ps: 一些简单的常用命令:
sudo lsof -nP | grep LISTEN # 查看监听接口
sudo docker inspect gitlab1 | grep Mounts -A 20 # 查看挂载路径
sudo docker exec -it container_name /bin/bash # 进入container内部
sudo docker ps # 查看正在运行的container
sudo docker ps -a # 查看所有的container
sudo docker stop container-name # 停止正在运行的container
sudo docker start container-name # 运行停止的container
~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`
官方docker gitlab版本数据迁移:
链接: https://docs.gitlab.com/ee/raketasks/backup_restore.html
1. gitlab 12.1版本以后的新版本用下边的命令来备份docker安装的gitlab:(以前的用: For GitLab 12.1 and earlier, use gitlab-rake gitlab:backup:create
.)
user@server-name: docker exec -t <container name> gitlab-backup create
返回信息:
user@server-name:~/docker$ sudo docker exec -t gitlab1 gitlab-backup create
[sudo] password for user:
2020-09-07 09:29:56 +0000 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping repositories ...
* group-lab/pelvis-segmentation (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ...
* group-lab/pelvis-segmentation (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [DONE]
* group-lab/pelvis-segmentation (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [SKIPPED] Wiki
* group-lab/centernet (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ...
* group-lab/centernet (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... [DONE]
* group-lab/centernet (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... [SKIPPED] Wiki
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping uploads ...
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping builds ...
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping artifacts ...
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping pages ...
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping lfs objects ...
2020-09-07 09:29:58 +0000 -- done
2020-09-07 09:29:58 +0000 -- Dumping container registry images ...
2020-09-07 09:29:58 +0000 -- [DISABLED]
Creating backup archive: 1599470998_2020_09_07_13.3.4-ee_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
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.
Backup task is done.
其中gitlab.rb 和 gitlab-secrets.json 是你的配置文件, 在config文件夹下.
官方说明: https://docs.gitlab.com/ee/raketasks/backup_restore.html#additional-notes
GitLab provides a simple command line interface to back up your whole instance. It backs up your:
- Database
- Attachments
- Git repositories data
- CI/CD job output logs
- CI/CD job artifacts
- LFS objects
- Container Registry images
- GitLab Pages content
Warning: GitLab does not back up any configuration files, SSL certificates, or system files. You are highly advised to read about storing configuration files.
2. 备份配置文件
官方说明:
For Docker installations, you must back up the volume where the configuration files are stored. If you have created the GitLab container according to the documentation, it should be under
/srv/gitlab/config
.
3. 一些命令的配置选项说明
user@server-name:sudo gitlab-backup create STRATEGY=copy
user@server-name:sudo gitlab-backup create BACKUP=dump
user@server-name:sudo gitlab-backup create BACKUP=dump GZIP_RSYNCABLE=yes
user@server-name:sudo gitlab-backup create SKIP=db,uploads
user@server-name:sudo gitlab-backup create SKIP=tar
sudo GITLAB_ASSUME_YES=1 gitlab-backup restore
sudo gitlab-backup create GITLAB_BACKUP_MAX_CONCURRENCY=4 GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY=1
4. 恢复gitlab
The restore prerequisites section includes crucial information. Make sure to read and test the whole restore process at least once before attempting to perform it in a production environment.
You can only restore a backup to exactly the same version and type (CE/EE) of GitLab that you created it on, for example CE 9.1.0. (docker 版本库: https://hub.docker.com/r/gitlab/gitlab-ee/tags/)
If your backup is a different version than the current installation, you will need to downgrade your GitLab installation before restoring the backup.
恢复的时候, 希望新的路径应该是空的.
备份文件在$GITLAB_HOME/data下的backups中, 新服务器恢复时backup文件要在新服务器中对应就位. 权限不足自己修改吧, chmod 750/777 backups
# Stop the processes that are connected to the database
docker exec -it <name of container> gitlab-ctl stop unicorn
docker exec -it <name of container> gitlab-ctl stop puma
docker exec -it <name of container> gitlab-ctl stop sidekiq
# Verify that the processes are all down before continuing
docker exec -it <name of container> gitlab-ctl status
# Run the restore
docker exec -it <name of container> gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce
# 这里应该会提示你将gitlab.rc 和gitlab-secrets.json 手动备份过来
# Restart the GitLab container
docker restart <name of container>
# Check GitLab
docker exec -it <name of container> gitlab-rake gitlab:check SANITIZE=true
5. 修改本地代码设置
restore之后就可以直接使用新服务器的IP访问了. 然后重新设置你对应的本地代码的origin就可以了
$ git remote set-url origin http://IP/groups/repository.git
~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`
安装包版本安装:
1先下载对应的gitlab软件
wget https://link.zhihu.com/?target=https%3A//mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
2 安装gitlab服务器
rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
出现如下界面表示安装成功
3 进入gitlab.rb修改IP和端口,修改external url for gitlab为"http://gitlab.test1.test2.com"
vi /etc/gitlab/gitlab.rb
4 配置并启动gitlab
gitlab-ctl reconfigure
gitlab-ctl restart
5
未完待续...有待验证
数据迁移
1 先修改配置位置:
kani@ubuntu:/home1$ sudo vim /etc/gitlab/gitlab.rb
# 找到其中git_data_dirs修改为自己的位置
# git_data_dirs({
# "default" => {"path" => "/home1/git-data"}
# })
2 如果刚开始配置没有数据,可以直接sudo gitlab-ctl reconfigure,如果有数据的话按如下操作即可
# 先停止服务,防止期间有人上传
pbliu@ubuntu:/home1$ sudo gitlab-ctl stop
# 原始仓库默认存储位置为 /var/opt/gitlab/git-data/repositories,rsync通过到新位置
# 注:我尝试需要将git-data整个目录迁过来才行,只迁repositories好像会失败,可能是权限问题
pbliu@ubuntu:/home1$ rsync -av /var/opt/gitlab/git-data /home1/
# 然后再reconfigure,start就可以了
pbliu@ubuntu:/home1$ sudo gitlab-ctl reconfigure
pbliu@ubuntu:/home1$ sudo gitlab-ctl start