Linux安装gitlab代码仓库

一、下载gitlab软件

1、通过国内资源(清华镜像)进行下载,地址为https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

rpm软件包.png

2、通过gitlab官网进行下载:https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-14.7.6-ce.0.el7.x86_64.rpm
通过yum仓库进行安装.png

二、安装gitlab

通过yum仓库进行安装

这种方式如截图所示:
1、添加gitlab到yum仓库中:
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
2、通过yum进行安装:
sudo yum install gitlab-ce-14.7.6-ce.0.el7.x86_64
如果是root用户,可以删除sudo
yum install gitlab-ce-14.7.6-ce.0.el7.x86_64

通过源码包进行安装

1、将文件通过scp命令传输到服务器中
scp gitlab-ce-14.7.6-ce.0.el7.x86_64.rpm root@192.168.10.150:/root/Downloads
2、安装相关依赖
yum -y install policycoreutils openssh-server openssh-clients postfix
3、开启postfix,支持gitlab邮件发送
systemctl start postfix
设置开机自启动:
systemctl enable postfix
4、安装gitlab
rpm -ivh gitlab-ce-14.7.6-ce.0.el7.x86_64.rpm

安装完成截图

5、修改gitlab配置文件指定服务器ip和自定义端口
vim /etc/gitlab/gitlab.rb
修改字段如下:external_url
image.png

6、重置并启动gitlab

gitlab-ctl reconfigure # 重置
gitlab-ctl restart # 重启
reconfigure成功截图.png

restart成功截图.png

7、gitlab初始密码:
初始密码存放在/etc/gitlab/initial_root_password
该密码在首次执行reconfigure24小时候自动删除。

问题合集

问题一:缺少依赖

image.png

解决方式:
yum install -y policycoreutils-python:安装对应的依赖即可
gitlab需要的依赖有:policycoreutils、openssh-server、openssh-clients、postfix

问题二:软件包下载失败

失败截图

解决方案:可能是由于网络原因下载失败,重新下载即可。

问题三:安装后没有设置自动重启,就把虚拟机给关闭了,再次打开虚拟机时,gitlab没有启动。

重启虚拟机后,gitlab启动失败

解决方案:

# 1、先启动对应的服务
systemctl start gitlab-runsvdir
# 2、通过gitlab-ctl重启gitlab
gitlab-ctl restart
成功截图

成功安装gitlab后,通过浏览器访问出现502

502错误

这个也没有弄懂为什么,我是通过修改端口后就可以了

# 修改对应的端口号为非常用的,如8081
vim /etc/gitlab/gitlab.rb 
# gitlab-ctl reconfigure
# gitlab-ctl restart
控制性信息

浏览器访问

root密码忘记

解决方案:
1、查看用户的id

curl http://gitlab的url/api/v4/users?username=root

查询用户id

2、重置密码
1)进入gitlab控制台:
gitlab-rails console production

Traceback (most recent call last):
    8: from bin/rails:4:in `<main>'
    7: from bin/rails:4:in `require'
    6: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands.rb:18:in `<top (required)>'
    5: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/command.rb:48:in `invoke'
    4: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/command/base.rb:69:in `perform'
    3: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    2: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    1: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
/opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands/console/console_command.rb:95:in `perform': wrong number of arguments (given 1, expected 0) (ArgumentError)
    9: from bin/rails:4:in `<main>'
    8: from bin/rails:4:in `require'
    7: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands.rb:18:in `<top (required)>'
    6: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/command.rb:48:in `invoke'
    5: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/command/base.rb:69:in `perform'
    4: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    3: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    2: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:20:in `run'
    1: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:34:in `rescue in run'
/opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/base.rb:525:in `handle_argument_error': ERROR: "rails console" was called with arguments ["production"] (Thor::InvocationError)
Usage: "rails console [options]"

通过上述命令无法进入gitlab的控制台,后来又试了一种
gitlab-rails console -e production
成功进入(ps:在gitlab官网找到对应版本的命令,但是我没有找到,有人找到麻烦留个言或者私信一下)

image.png

进入控制台后,陆续输入一下命令:

user = User.where(id: 1).first # 根据id找到用户
user.password = 'learngitlab' # 设置用户密码
user.password_confirmation = 'learngitlab' # 确认密码
user.save! # 保存密码
quit # 退出控制台
整体流程图
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容