centos7+docker快速搭建gitlab服务流程步骤

2023-06-01 00:00:00 搭建 步骤 流程

最近我打算整个docker swarm集群架构玩玩,安装好docker后第一步就是先整个gitlab

先天条件:

1.准备centos7系统, 配置好网络ip、修改主机名

  [[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  TYPE=Ethernet
  PROXY_METHOD=none
  BROWSER_ONLY=no
  BOOTPROTO=static
  DEFROUTE=yes
  IPV4_FAILURE_FATAL=no
  IPV6INIT=yes
  IPV6_AUTOCONF=yes
  IPV6_DEFROUTE=yes
  IPV6_FAILURE_FATAL=no
  IPV6_ADDR_GEN_MODE=stable-privacy
  NAME=eth0
  UUID=9a65b9e5-7f65-46d8-bbb3-112eee88a0e1
  DEVICE=eth0
  ONBOOT=yes
  IPADDR=172.18.1.150
  NETMASK=255.255.255.0
  GATEWAY=172.18.1.1
  DNS1=114.114.114.114
  IPV6_PRIVACY=no
  [[email protected] ~]# cat /etc/hostname 
  master
  //然后重启
  [[email protected] ~]# reboot 


2.修改ssh端口 (这里特别注意,配置好了之后在注销22端口)

  [[email protected] ~]# vi /etc/ssh/sshd_conf
  //修改如下
  #Port 22
  Port 22250
  //重启ssh
  [[email protected] ~]# systemctl restart sshd.service


3.关闭防火墙及SELinux,或添加ssh新端口

  [[email protected] ~]# semanage port -a -t ssh_port_t -p tcp 22250
  [[email protected] ~]# semanage port -l | grep ssh
  ssh_port_t                     tcp      22250, 22
  [[email protected] ~]# systemctl stop iptables.service
  [[email protected] ~]# systemctl stop firewalld.service


4.centos7中docker已经安装好

[[email protected] ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:41 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:44:05 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


5.配置一个阿里云镜像加速链接 (可配可不配,不配会时快时慢,反正我不配也挺快的)

[[email protected] ~]# cat /etc/docker/daemon.json 
{"registry-mirrors": ["https://ft5scn3r.mirror.aliyuncs.com"]}


废话不多说直接上代码:

//Docker启动一个Gitlab服务

[[email protected] ~]# sudo docker run -d --hostname master \
> --publish 443:443 --publish 80:80 --publish 22:22 \
> --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab \
> --volume /srv/gitlab/logs:/var/log/gitlab \
> --volume /srv/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:latest
Unable to find image 'gitlab/gitlab-ce:latest' locally
latest: Pulling from gitlab/gitlab-ce
ea362f368469: Pull complete 
25dab24d2430: Pull complete 
b8a4765ba2f3: Pull complete 
c51bd6a305fb: Pull complete 
9a857282747d: Pull complete 
3e55b49c1901: Pull complete 
e25bade12011: Pull complete 
53ff69e75c3c: Pull complete 
Digest: sha256:fcfd3bf76c60891fd8400e2984b706083739d49127b20eb788cd292b5e94846f
Status: Downloaded newer image for gitlab/gitlab-ce:latest
f4e24320bcdec5fec5874101313c35df9e587df461dd7cbdf3426f92ef009125

ps:

如果遇到下面错误

docker: Error response from daemon: driver failed programming external connectivity on endpoint gitlab (bb7b5466741624d55cc821de02e80d5f5e6a5b2d943efccd04e16d59a698f748):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 443 -j DNAT --to-destination 172.17.0.2:443 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1)).

解决方式:(docker服务启动时定义的自定义链被清掉了,需重启docker)

[[email protected] ~]# systemctl restart docker


//看看镜像跟容器

[[email protected] ~]# docker ps -a
CONTAINER ID   IMAGE                     COMMAND             CREATED          STATUS                             PORTS                                                                                                         NAMES
f4e24320bcde   gitlab/gitlab-ce:latest   "/assets/wrapper"   53 seconds ago   Up 51 seconds (health: starting)   0.0.0.0:22->22/tcp, :::22->22/tcp, 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   gitlab
[[email protected] ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED      SIZE
gitlab/gitlab-ce   latest    f9cc225c75e1   3 days ago   2.36GB


web访问看看

gitlab.png

到这你以为OK了吗? 

并没有,首次登录Gitlab需要重置密码,默认用户名为root


重置gitlab用户root的密码步骤:

[[email protected] ~]# docker exec -it f4e24320bcde /bin/sh
# ls
RELEASE  bin   dev  home  lib32  libx32   media  opt   root  sbin  sysusr
assets boot  etc  lib   lib64  linuxrc  mnt proc  run   srv   tmpvar
# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       14.6.3 (e085746f077) FOSS
 GitLab Shell: 13.22.1
 PostgreSQL:   12.7
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.4.1)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = '123456'
=> "123456"
irb(main):003:0> user.password_confirmation = '123456'
=> "123456"
irb(main):004:0> user.save!
Traceback (most recent call last):
        7: from (irb):13
        6: from lib/gitlab/database/load_balancing/connection_proxy.rb:77:in `transaction'
        5: from lib/gitlab/database/load_balancing/connection_proxy.rb:125:in `write_using_load_balancer'
        4: from lib/gitlab/database/load_balancing/load_balancer.rb:110:in `read_write'
        3: from lib/gitlab/database/load_balancing/load_balancer.rb:172:in `retry_with_backoff'
        2: from lib/gitlab/database/load_balancing/load_balancer.rb:112:in `block in read_write'
        1: from lib/gitlab/database/load_balancing/connection_proxy.rb:126:in `block in write_using_load_balancer'
ActiveRecord::RecordInvalid (Validation failed: Password is too short (minimum is 8 characters))
irb(main):005:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):006:0> user.password = 'htz123456'
=> "htz123456"
irb(main):007:0> user.password_confirmation = 'htz123456'
=> "htz123456"
irb(main):008:0> user.save!
=> true
irb(main):009:0> exit
# sh: turning off NDELAY mode

ps: 

注意那个错误是什么引起的

好了,到这就算是重置root密码为htz123456


web登录一下看看:

gitlab1.png


退出容器进入宿主机中操作 : (题外话)

按住Ctrl后先按p,在按q


相关文章