很久不用Linux和gitlab 的一些操作
挺久没有登陆 电脑 了
今天登陆 linux 主机突发 密码忘了 git的也忘了
好的是 之前用的登陆还在,修改IP直接登陆 然后
[root@localhost testuser]# passwd testuser
Changing password for user testuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost testuser]#
直接对应账号就行
然后发现gitlab密码也忘了 哎 ....
进入宿主
docker exec -it a63852603fac /bin/bash
vi /etc/gitlab/gitlab.rb
docker exec -it a63852603fac /bin/bash
------------------重置docker的gitlab密码---------------------
su - git
gitlab-rails console production //容易报错
gitlab-rails console -e production // 等待一会儿加载OK
user = User.where(id:1).first
user.password = '123123'
user.password_confirmation = '123123'
user.save!
exit
-----------------------------------------
ssh-keygen -t rsa -C “19@qq.com”
生成ssh 把老的ssh删掉
把这个pub的内容粘贴进来。
现在基本就能正常使用GitLab啦。。。
-----------------------------------------------------------------------------------备份一个以防万一----------------------------------------------------------------------------------
备份时需要保持gitlab处于正常运行状态,直接执行进行备份
docker exec -it a63852603fac /bin/bash
gitlab-rake gitlab:backup:create
这个文件在docker里的如下目录
/var/opt/gitlab/backups/
docker cp 容器名要拷贝的文件在容器里面的路径 要拷贝到宿主机的相应路径
docker cp gitlab:/var/opt/gitlab/backups/1606312481_2020_11_25_12.9.1_gitlab_backup.tar /home/mrg/
将备份拷贝出来 https://www.cnblogs.com/anliven/p/11954964.html
---------------------------------------------------------------------------------------------
或者把这个容器打包镜像
https://www.cnblogs.com/pjcd-32718195/p/11762079.html
//制作镜像
sudo docker commit -m "gitlab20201125 " -a "gitlab" gitlab mrg/gitlab:v1
sudo docker save -o /home/mrg/gitlabv1.tar mrg/gitlab:v1
保存到对应目录
发送到目标机器
scp "/home/mrg/gitlabv1.tar" root@192.168.2.10:/home/
上一步不成功 需要两台机器都安装scp功能
yum install openssh-clients -y
//直接还原
---------------------------------------------------------
docker load < gitlabv1.tar
docker images
docker run \ --detach \ --publish 8443:443 \ --publish 8090:80 \ --publish 222:22 \ --name gitlab \ --restart unless-stopped \ -v /mnt/gitlab/etc:/etc/gitlab \ -v /mnt/gitlab/log:/var/log/gitlab \ -v /mnt/gitlab/data:/var/opt/gitlab \ mrg/gitlab:v1
--name 容器名称 镜像ID 容器名称 版本号
docker run -d -p 4431:4431 -p 221:22 --name mrggitlab 565f1dd1e73a --restart always -v /run/media/root/data/home/gitlab/config:/etc/gitlab -v /run/media/root/data/home/gitlab/logs:/var/log/gitlab -v /run/media/root/data/home/gitlab/data:/var/opt/gitlab mrggitlab:v1
docker run -d -p 443:443 -p 80:80 -p 222:22 --name mrggitlab 565f1dd1e73a --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab
docker run -d -p 4431:4431 -p 221:22 --name mrggitlab 565f1dd1e73a --privileged=true --restart always -v /run/media/root/data/home/gitlab/config:/etc/gitlab -v /run/media/root/data/home/gitlab/logs:/var/log/gitlab -v /run/media/root/data/home/gitlab/data:/var/opt/gitlab mrggitlab:v1
gitlab-ctl reconfigure
gitlab-ctl restart
---------------------------------------------------------
sudo su
mv "/home/mrg/Desktop/1585125727_2020_03_25_12.6.1_gitlab_backup.tar" "/var/opt/gitlab/backups"
//恢复 不要 _gitlab_backup.tar
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=1585131631_2020_03_25_12.9.0
sudo gitlab-ctl restart
sudo gitlab-ctl status