yum+Docker两种方式部署GitLab

环境说明

系统:Centos 7.9
Docker:20.10.17

yum方式部署

添加gitlab的yum源仓库

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

或者使用清华源(推荐)

vim /etc/yum.repos.d/gitlab-ce.repo
## 添加下面的内容

[gitlab-ce]

name=Gitlab CE Repository

baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/

gpgcheck=0

enabled=1

安装gitlab

yum  -y  install  gitlab-ce

安装完成后配置gitlab默认端口

vim /etc/gitlab/gitlab.rb

修改端口和地址

##! Note: During installation/upgrades, the value of the environment variable
##! EXTERNAL_URL will be used to populate/replace this value.
##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP
##! address from AWS. For more details, see:
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
## external_url 'http://gitlab.example.com' ##将地址修改为主机IP+端口,也可以只改地址默认80端口
external_url 'http://192.168.0.66:8800'

##修改ssh端口
### GitLab Shell settings for GitLab
## 去掉注释后修改
gitlab_rails['gitlab_shell_ssh_port'] = 222 
# gitlab_rails['gitlab_shell_git_timeout'] = 800

初始化gitlab

gitlab-ctl reconfigure
#这一步需要时间较长

初始化完成后服务就启动了,可以登陆http://IP+端口 访问gitlab,默认账户为root,初始密码存储在/etc/gitlab/initial_root_password

# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: Jen0LBE6l7U3KcMdf1VwwNTjLAUs1jtDsMHgl2raiNU=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

如果忘记root密码可以使用命令重置

 gitlab-rake "gitlab:password:reset[root]"
## 输入2次密码后修改完成

到这里yum方式部署的gitlab就已经基本完成

Docker方式部署

创建持久化目录

mkdir -p /data/gitlab/{conf,logs,data}

拉取镜像(也可直接执行命令,先不拉取)

#不写版本即为最新镜像
docker pull gitlab/gitlab-ce

启动容器

docker run -d  -p 443:443 -p 8800:80 -p 222:22 --name gitlab --restart always -v /data/gitlab/conf:/etc/gitlab -v /data/gitlab/logs:/var/log/gitlab -v /data/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce

启动完成后修改配置文件

vim /data/gitlab/conf/gitlab.rb

#修改IP
external_url 'http://192.168.0.66'

#修改ssh,这个并不是实际ssh端口,是ssh方式克隆代码时候的端口
gitlab_rails['gitlab_shell_ssh_port'] = 222

重启gitlab容器后重新初始化

docker restart gitlab
#进入容器
docker exec -it gitlab /bin/bash
#执行初始化并重启
gitlab-ctl reconfigure
gitlab-ctl restart

访问宿主机IP+8800,默认账户root,因为已经对容器目录做了持久化,所以密码在/data/gitlab/conf/initial_root_password中

cat /data/gitlab/conf/initial_root_password中

[root@server-backend config]# cat  /docker/gitlib/config/initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: /Cs22USJrdsdlfj235ll3n6nlDwcat60vqk-

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

到此Docker方式部署GitLab也已经基本完成,无论哪种方式部署,在用户注册完成后建议关闭注册功能

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值