服务器迁移docker镜像并部署gitlab-ce
公司服务器没有配置镜像源,并且启动的容器有点多,不敢动
直接部署gitlab
也很麻烦
就用自己服务器下载gitlab/gitlab-ce
镜像,并迁移到服务器上面
自己服务器下载
查看镜像
docker save df0fbe337c74 > /home/dockercheck/lqm/gitlab-ce.tar
拷贝到目标服务器
目标服务器
加载到docker
docker load < /home/ouhou/gitlab_ce/gitlab-ce.tar
加载成功后REPOSITORY和TAG显示none,需要我们修改标签
docker tag df0fbe337c74 gitlab/gitlab:16.10
补充:刚发现网盘不让分享tar文件,链接失效,我看看解决办法
部署
docker run -id -p 9080:80 -p 9022:22 \
-v /home/ouhou/gitlab_ce/config:/etc/gitlab\
-v /home/ouhou/gitlab_ce/log:/var/log/gitlab \
-v /home/ouhou/gitlab_ce/opt:/var/opt/gitlab \
--restart always \
--privileged=true\
--name gitlab \
gitlab/gitlab-ce:16.10
docker run -id -p 9080:80 -p 9022:22 -v /home/ouhou/gitlab_ce/config:/etc/gitlab -v /home/ouhou/gitlab_ce/log:/var/log/gitlab -v /home/ouhou/gitlab_ce/opt:/var/opt/gitlab --restart always --privileged=true --name gitlab gitlab/gitlab:16.10
修改密码
# 进入容器内部
docker exec -it gitlab /bin/bash
# 进入控制台
gitlab-rails console -e production
# 查询id为1的用户,id为1的用户是超级管理员
user = User.where(id:1).first
# 修改密码
user.password='abcd12345678'
# 保存
user.save!
# 退出
exit
修改配置文件
如果有配置邮件服务需要,建议和下方邮件配置一起操作,即一起修改配置文件
# 进入容器内部
docker exec -it gitlab /bin/bash
# 修改gitlab.rb
vi /etc/gitlab/gitlab.rb
# 加入如下内容
# gitlab访问地址,可以写域名。如果端口不写的话默认为80端口
external_url 'http://10.56.181.180'
# ssh主机ip
gitlab_rails['gitlab_ssh_host'] = '10.56.181.180'
# ssh连接端口
gitlab_rails['gitlab_shell_ssh_port'] = 9022
# Esc
# :wq 保存配置文件
# 让配置生效
gitlab-ctl reconfigure
### 注意不要重启,/etc/gitlab/gitlab.rb文件的配置会映射到gitlab.yml这个文件,由于咱们在docker中运行,在gitlab上生成的http地址应该是http://101.133.225.166:9080,所以,要修改下面文件
# 修改http和ssh配置
vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
gitlab:
host: 10.56.181.180
port: 9080 # 这里改为9080
https: false
# 重启
gitlab-ctl restart
# 退出容器
exit
配置邮件服务
建议和上面配置文件步骤一起操作,否则容易乱套
# 进入容器内部
docker exec -it gitlab /bin/bash
# 修改gitlab.rb
vi /etc/gitlab/gitlab.rb
## 在文件中插入或修改以下内容
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xxuser@163.com"
gitlab_rails['smtp_password'] = "授权码"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = "xxuser@163.com"
user["git_user_email"] = "xxuser@163.com"
gitlab_rails['gitlab_email_display_name'] = '发件人名称'
gitlab_rails['smtp_password'] = "授权码"
填写授权码,可参考如下链接
重启docker容器
# 让配置生效
gitlab-ctl reconfigure
# 重启
gitlab-ctl restart
# 退出容器
exit
验证邮箱服务
ssh密钥遇到的问题
因为部署邮件服务那里,导致重新docker run了一次容器,所以前后两次本地的ssh密钥冲突了,git clone的时候就会报错
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:/kUxi3S3xew1QUIEtlvEiJYRrqANJglECjyfvyiMSgM.
Please contact your system administrator.
Add correct host key in /c/Users/Administrator/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/Administrator/.ssh/known_hosts:4
ECDSA host key for [10.56.181.180]:9022 has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决
SSH 客户端在 /c/Users/Administrator/.ssh/known_hosts
文件中存储了旧的主机密钥,我们需要删除该密钥
ssh-keygen -R [**.**.**.**]:9022
再次尝试克隆仓库
The authenticity of host '[10.56.181.180]:9022' can't be established.
ECDSA key fingerprint is SHA256:/kUxi3S3xew1QUIEtlvEiJYRrqANJglECjyfvyiMSgM.
Are you sure you want to continue connecting (yes/no)?
输入yes
即可,这将添加新的主机密钥到 known_hosts
文件中