gitlab11.4.6的安装和代码迁移实战案例-cent7.x安装

1.gitlab11.4.6的安装
在192.168.171.128上安装:
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
上传gitlab包:
[root@localhost ~]# ls
gitlab-ce-11.4.6-ce.0.el7.x86_64.rpm
[root@localhost ~]# yum -y install policycoreutils-python #安装依赖包
[root@localhost ~]# yum install curl openssh-server openssh-clients postfix cronie -y
[root@localhost ~]# systemctl start postfix #如果不需要邮件,可以不启动
[root@localhost ~]# systemctl enable postfix
[root@localhost ~]# rpm -ivh gitlab-ce-11.4.6-ce.0.el7.x86_64.rpm
出现下面界面表示安装成功:

配置gitlab访问地址,配置邮件服务并启动gitlab:
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.171.128'   #若改变端口:http://192.168.171.128:8888  #此后是gitlab访问地址(仓库地址)
……
#下面如果不需要邮件发送,可以保持注释:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com" #修改成使用qq邮箱服务
gitlab_rails['smtp_port'] = 465 #qq邮箱的端口默认465,不用修改
gitlab_rails['smtp_user_name'] = "1441107787@qq.com" #开启smtp服务的qq邮箱
gitlab_rails['smtp_password'] = "txjkxkkocxwqfegf" #qq邮箱开启密保验证时返回的授权码,需要配置qq邮箱开启smtp服务时生成
gitlab_rails['smtp_domain'] = "qq.com" #域名,qq邮箱的域名
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true #修改成true
……
user['git_user_email'] = "1441107787@qq.com" #修改成开启smtp服务的qq邮箱
gitlab_rails['gitlab_email_from'] = '1441107787@qq.com' #修改成开启smtp服务的qq邮箱,作为发件者
wq
[root@localhost ~]# gitlab-ctl reconfigure
[root@localhost ~]# gitlab-ctl status
run: alertmanager: (pid 5239) 755s; run: log: (pid 5247) 755s
run: gitaly: (pid 5194) 757s; run: log: (pid 5201) 757s
run: gitlab-monitor: (pid 5212) 756s; run: log: (pid 5215) 756s
run: gitlab-workhorse: (pid 5178) 758s; run: log: (pid 5183) 758s
run: logrotate: (pid 4315) 961s; run: log: (pid 5188) 757s
run: nginx: (pid 4270) 968s; run: log: (pid 5189) 757s
run: node-exporter: (pid 4483) 944s; run: log: (pid 5202) 757s
run: postgres-exporter: (pid 5257) 755s; run: log: (pid 5262) 754s
run: postgresql: (pid 3790) 1077s; run: log: (pid 5165) 759s
run: prometheus: (pid 5224) 756s; run: log: (pid 5227) 756s
run: redis: (pid 3646) 1088s; run: log: (pid 5164) 759s
run: redis-exporter: (pid 4651) 932s; run: log: (pid 5216) 756s
run: sidekiq: (pid 4150) 980s; run: log: (pid 5167) 759s
run: unicorn: (pid 4078) 986s; run: log: (pid 5166) 759s
[root@localhost ~]# netstat -anput |grep 80
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 4136/unicorn master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4270/nginx: master
……
[root@localhost ~]# netstat -anput |grep redis
tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 4651/redis_exporter
tcp 0 0 127.0.0.1:9121 127.0.0.1:56818 ESTABLISHED 4651/redis_exporter
[root@bogon ~]# ps -ef |grep unicorn
有进程
[root@bogon ~]# ps -ef |grep nginx
有进程
[root@bogon ~]# ps -ef |grep redis
有进程
#注意:第一次启动服务需用命令:gitlab-ctl reconfigure配置和启动服务,此后,可以用命令:gitlab-ctl status查看状态,gitlab-ctl stop停止服务,gitlab-ctl start启动服务等操作。(且自动会启动两个端口80和8080端口,自动从自身nginx代理到后面8080端口服务,gitlab服务配置启动后,会自带启动一些服务,内置nginx服务和unicorn服务(web服务)和redis服务,若gitlab-ctl stop后,gitlb服务和自带的服务也就跟着停止了,当再gitlab-ctl start后,自带的服务也跟着起来)
客户端访问:http://192.168.171.128   回车后跳转到下面页面:

重置管理员用户密码:1234567890(不能短于8位),默认管理员是root

重置root密码后可用root管理员登陆gitlab,如下: 

创建一个test项目,如下: 

测试邮箱服务功能(参考):
[root@localhost ~]# gitlab-rails console #进入控制台(比较慢)
irb(main):001:0> Notify.test_email('1036981484@qq.com','this is title','hello').deliver_now #回车即可
上面是指定收件人的邮箱,使用配置的发件人1441107787@qq.com给收件人:1036981484@qq.com 邮箱发消息
此时:收件人1036981484@qq.com会收到邮件,表示邮件服务配置成功。

gitlab的简单使用:注意:下面通用:
管理员用户:root,密码:1234567890,配置文件配置了邮件服务,发邮件人:1441107787@qq.com
普通用户shi,密码:123456789 1036981481@qq.com
普通用户shi2,密码:1234567890 1036981484@qq.com
注意:开启邮箱验证前可以随便注册的邮箱,开启邮箱验证后,需要通过验证才可以注册的邮箱(参考)
1).gitlab管理员root用户更改密码:
登录gitlab后,点击最右上角的用户图标——Settings——Password——填写当前密码和新密码——save password即可。
2).gitlab普通用户shi更改密码:
登录gitlab后,点击最右上角用户图标——Settings——Password——填写当我密码和新密码——save password即可。
3).gitlab管理员root用户查看所注册的gitlab普通用户情况(查看所有的普通用户)
点击Admin area——Users可查看所有注册的gitlab普通用户。
4).用户在gitlab创建仓库(以root用户为例,其他用户类似)
[root@localhost ~]# yum -y install git #客户端机器,也可用服务器作为客户端
[root@localhost ~]# git config --global user.name "Administrator"
[root@localhost ~]# git config --global user.email "admin@example.com"
[root@localhost ~]# mkdir /test1
[root@localhost ~]# cd /test1/
[root@localhost test1]# ls -a
. ..
[root@localhost test1]# git clone http://192.168.171.128/root/test.git
输入root用户名和密码:1234567890
[root@localhost test1]# ls -a
. .. test
[root@localhost test1]# ls test/
空 #克隆的空仓库
[root@localhost test1]# cd test/
[root@localhost test]# echo 111 > 1.txt
[root@localhost test]# echo 222 > 2.txt
[root@localhost test]# echo 333 > 3.txt
[root@localhost test]# echo 444 > 4.txt
[root@localhost test]# ls
1.txt 2.txt 3.txt 4.txt
[root@localhost test]# git add .
[root@localhost test]# git commit -m "add files"
[root@localhost test]# git push http://192.168.171.128/root/test.git master #推送到远程仓库master分支
输入root用户名和密码:1234567890
远程仓库即可查看到推送来的文件:

2.gitlab11.4.6的代码迁移(gitlab上所有项目代码全量迁移,此处仅创建了一个test项目,以一个项目为例,如果有多个,会全部迁移过去)
参考文档: GitLab从旧服务器迁移到新服务器_楚游香的博客-CSDN博客
注意: 迁移的两个gitlab版本必须保持一样

机器规划:
原gitlab: 192.168.171.128 root 1234567890
新gitlab: 192.168.171.129 root 123456.com

迁移步骤:
1).搭建原gitlab并创建test项目,开发相应代码,如下:
http://192.168.171.128/ root/1234567890

 

 

2).搭建新gitlab,项目代码为空,如下:
http://192.168.171.129/ root/123456.com

3).gitlab代码迁移,原gitlab上全量备份代码(备份旧服务器的文件): 在192.168.171.128上操作
[root@localhost ~]# ls /var/opt/gitlab/backups/
为空
[root@localhost ~]# gitlab-rake gitlab:backup:create
[root@localhost ~]# ls /var/opt/gitlab/backups/
1687060340_2023_06_18_11.4.6_gitlab_backup.tar #默认将会在 /var/opt/gitlab/backups/ 目录下生成备份文件。
将备份文件发送到新gitlab机器的对应目录里:
# scp /var/opt/gitlab/backups/1687060340_2023_06_18_11.4.6_gitlab_backup.tar root@192.168.171.129:/var/opt/gitlab/backups/

4).gitlab代码迁移,新gitlab上全量恢复代码(使用旧服务器的备份文件): 在192.168.171.129上操作
[root@localhost ~]# ls /var/opt/gitlab/backups/ #查看备份文件
1687060340_2023_06_18_11.4.6_gitlab_backup.tar
[root@localhost ~]# chmod -R 777 /var/opt/gitlab/backups/1687060340_2023_06_18_11.4.6_gitlab_backup.tar #防止无权限
[root@localhost ~]# gitlab-ctl status #查看gitlab服务状态
run: alertmanager: (pid 9928) 2566s; run: log: (pid 9936) 2565s
run: gitaly: (pid 9869) 2568s; run: log: (pid 9890) 2567s
run: gitlab-monitor: (pid 9899) 2567s; run: log: (pid 9902) 2567s
run: gitlab-workhorse: (pid 9855) 2568s; run: log: (pid 9860) 2568s
run: logrotate: (pid 9484) 2605s; run: log: (pid 9861) 2568s
run: nginx: (pid 9460) 2611s; run: log: (pid 9862) 2568s
run: node-exporter: (pid 9688) 2593s; run: log: (pid 9889) 2567s
run: postgres-exporter: (pid 9943) 2565s; run: log: (pid 10022) 2565s
run: postgresql: (pid 9184) 2647s; run: log: (pid 9846) 2568s
run: prometheus: (pid 9911) 2566s; run: log: (pid 9920) 2566s
run: redis: (pid 9108) 2653s; run: log: (pid 9848) 2568s
run: redis-exporter: (pid 9718) 2590s; run: log: (pid 9901) 2567s
run: sidekiq: (pid 9430) 2620s; run: log: (pid 9845) 2568s
run: unicorn: (pid 9384) 2626s; run: log: (pid 9847) 2568s
[root@localhost ~]# gitlab-ctl stop unicorn #停止数据连接服务
[root@localhost ~]# gitlab-ctl stop sidekiq #停止数据连接服务
[root@localhost ~]# gitlab-rake gitlab:backup:restore BACKUP=1687060340_2023_06_18_11.4.6 #全量恢复gitlab代码
恢复格式如下:
# gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
例如:备份文件名为1687060340_2023_06_18_11.4.6_gitlab_backup.tar,则编号为1687060340_2023_06_18_11.4.6。
在提示中敲入yes继续。
[root@localhost ~]# gitlab-ctl restart #恢复完成后重启gitlab
重新登录新gitlab,最后检查新旧GitLab的内容,完全一模一样,迁移成功:
http://192.168.171.129/ root/1234567890 注意:此时的密码应该为原来gitlab的密码

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维实战课程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值