Centos7使用docker部署GitLab

1简介

在本次南京出差时,使用了SVN来管理代码的版本,由于SVN是集中式的版本管理工具,导致了一旦没有服务器的支持,无法进行版本日志的查看,也无法进行版本的回退,给开发带来了很大的不便。因此在空闲时间学习在Centos7上搭建GitLab环境。

2部署步骤

2.1配置阿里云yum源

2.1.1安装wget

[root@localhost ~]# yum -y install wget
Loaded plugins: fastestmirror
base                                                                                                          | 3.6 kB  00:00:00     
extras                                                                                                        | 3.4 kB  00:00:00     
updates                                                                                                       | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                             | 187 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                            | 3.4 MB  00:00:05     
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                      Arch                           Version                              Repository                    Size
=====================================================================================================================================
Installing:
 wget                         x86_64                         1.14-18.el7                          base                         547 k

Transaction Summary
=====================================================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7.x86_64.rpm                                                                                   | 547 kB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7.x86_64                                                                                           1/1 
  Verifying  : wget-1.14-18.el7.x86_64                                                                                           1/1 

Installed:
  wget.x86_64 0:1.14-18.el7                                                                                                          

Complete!
[root@localhost ~]# 

2.1.2使用wget拉取阿里源配置文件

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-03-28 22:13:33--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 218.98.9.102, 218.98.9.100, 218.98.9.101, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|218.98.9.102|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘Centos-7.repo’

100%[===========================================================================================>] 2,523       --.-K/s   in 0s      

2019-03-28 22:13:35 (108 MB/s) - ‘Centos-7.repo’ saved [2523/2523]


2.1.3修改文件名

[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# mv Centos-7.repo CentOS-Base.repo

2.1.4使配置文件生效

[root@localhost yum.repos.d]# yum clean all && yum makecache
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Loaded plugins: fastestmirror
base                                                                                                          | 3.6 kB  00:00:00     
extras                                                                                                        | 3.4 kB  00:00:00     
updates                                                                                                       | 3.4 kB  00:00:00     
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known"
Trying other mirror.
(1/12): extras/7/x86_64/filelists_db                                                                          | 235 kB  00:00:02     
(2/12): base/7/x86_64/group_gz                                                                                | 166 kB  00:00:02     
(3/12): extras/7/x86_64/primary_db                                                                            | 187 kB  00:00:01     
(4/12): extras/7/x86_64/other_db                                                                              | 120 kB  00:00:01     
(5/12): base/7/x86_64/other_db                                                                                | 2.6 MB  00:00:04     
(6/12): updates/7/x86_64/filelists_db                                                                         | 2.6 MB  00:00:12     
(7/12): updates/7/x86_64/other_db                                                                             | 456 kB  00:00:03     
base/7/x86_64/filelists_db     FAILED                                                              ] 215 kB/s | 8.8 MB  00:01:09 ETA 
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/a0ec5a4708a1026db100d4799c404c9ed48a9371a4bab234a1355f86628a244a-filelists.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/a0ec5a4708a1026db100d4799c404c9ed48a9371a4bab234a1355f86628a244a-filelists.sqlite.bz2: (28, 'Connection timed out after 30000 milliseconds')
Trying other mirror.
extras/7/x86_64/prestodelta    FAILED                                                              ] 211 kB/s | 8.9 MB  00:01:10 ETA 
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/6249194f201fd98d817318368f544472d1967d70034905e1ae94309fe0788390-prestodelta.xml.gz: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/6249194f201fd98d817318368f544472d1967d70034905e1ae94309fe0788390-prestodelta.xml.gz: (28, 'Connection timed out after 30001 milliseconds')
Trying other mirror.
(8/12): extras/7/x86_64/prestodelta                                                                           |  52 kB  00:00:02     
updates/7/x86_64/prestodelta   FAILED                                                              ] 597 kB/s |  12 MB  00:00:19 ETA 
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/98df664236c573aa7c83eeacc5866e893741ff8964a2ca12d61038372c12595b-prestodelta.xml.gz: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/98df664236c573aa7c83eeacc5866e893741ff8964a2ca12d61038372c12595b-prestodelta.xml.gz: (28, 'Connection timed out after 30002 milliseconds')
Trying other mirror.
updates/7/x86_64/primary_db    FAILED                                          -                   ] 609 kB/s |  13 MB  00:00:18 ETA 
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/1a9c538d6a9bf52b1b3f58ea0ad3899fca4c5709c5df561e58741c49ca8e9376-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/1a9c538d6a9bf52b1b3f58ea0ad3899fca4c5709c5df561e58741c49ca8e9376-primary.sqlite.bz2: (28, 'Connection timed out after 30001 milliseconds')
Trying other mirror.
(9/12): base/7/x86_64/filelists_db                                                                            | 7.1 MB  00:00:09     
(10/12): updates/7/x86_64/prestodelta                                                                         | 477 kB  00:00:06     
(11/12): updates/7/x86_64/primary_db                                                                          | 3.4 MB  00:00:15     
(12/12): base/7/x86_64/primary_db                                                                             | 6.0 MB  00:00:33     
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Metadata Cache Created

2.1.5使用yum 安装docker

[root@localhost yum.repos.d]# yum -y install docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-91.git07f3374.el7.centos will be updated
---> Package docker.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos will be an update
--> Processing Dependency: docker-common = 2:1.13.1-94.gitb2f74b2.el7.centos for package: 2:docker-1.13.1-94.gitb2f74b2.el7.centos.x86_64
--> Processing Dependency: docker-client = 2:1.13.1-94.gitb2f74b2.el7.centos for package: 2:docker-1.13.1-94.gitb2f74b2.el7.centos.x86_64
--> Running transaction check
---> Package docker-client.x86_64 2:1.13.1-91.git07f3374.el7.centos will be updated
---> Package docker-client.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos will be an update
---> Package docker-common.x86_64 2:1.13.1-91.git07f3374.el7.centos will be updated
---> Package docker-common.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                       Arch                   Version                                           Repository              Size
=====================================================================================================================================
Updating:
 docker                        x86_64                 2:1.13.1-94.gitb2f74b2.el7.centos                 extras                  18 M
Updating for dependencies:
 docker-client                 x86_64                 2:1.13.1-94.gitb2f74b2.el7.centos                 extras                 3.9 M
 docker-common                 x86_64                 2:1.13.1-94.gitb2f74b2.el7.centos                 extras                  96 k

Transaction Summary
=====================================================================================================================================
Upgrade  1 Package (+2 Dependent packages)

Total download size: 22 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): docker-client-1.13.1-94.gitb2f74b2.el7.centos.x86_64.rpm                                               | 3.9 MB  00:00:09     
(2/3): docker-common-1.13.1-94.gitb2f74b2.el7.centos.x86_64.rpm                                               |  96 kB  00:00:00     
(3/3): docker-1.13.1-94.gitb2f74b2.el7.centos.x86_64.rpm                                                      |  18 MB  00:00:15     
-------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                1.4 MB/s |  22 MB  00:00:15     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 2:docker-common-1.13.1-94.gitb2f74b2.el7.centos.x86_64                                                            1/6 
  Updating   : 2:docker-client-1.13.1-94.gitb2f74b2.el7.centos.x86_64                                                            2/6 
  Updating   : 2:docker-1.13.1-94.gitb2f74b2.el7.centos.x86_64                                                                   3/6 
  Cleanup    : 2:docker-1.13.1-91.git07f3374.el7.centos.x86_64                                                                   4/6 
  Cleanup    : 2:docker-client-1.13.1-91.git07f3374.el7.centos.x86_64                                                            5/6 
  Cleanup    : 2:docker-common-1.13.1-91.git07f3374.el7.centos.x86_64                                                            6/6 
  Verifying  : 2:docker-client-1.13.1-94.gitb2f74b2.el7.centos.x86_64                                                            1/6 
  Verifying  : 2:docker-1.13.1-94.gitb2f74b2.el7.centos.x86_64                                                                   2/6 
  Verifying  : 2:docker-common-1.13.1-94.gitb2f74b2.el7.centos.x86_64                                                            3/6 
  Verifying  : 2:docker-common-1.13.1-91.git07f3374.el7.centos.x86_64                                                            4/6 
  Verifying  : 2:docker-1.13.1-91.git07f3374.el7.centos.x86_64                                                                   5/6 
  Verifying  : 2:docker-client-1.13.1-91.git07f3374.el7.centos.x86_64                                                            6/6 

Updated:
  docker.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos                                                                                    

Dependency Updated:
  docker-client.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos            docker-common.x86_64 2:1.13.1-94.gitb2f74b2.el7.centos           

Complete!
[root@localhost yum.repos.d]# 

2.2配置阿里云docker

使用docker配置docker阿里源加速,参见docker通过修改配置文件使用阿里云镜像,不再赘述。

2.3拉取docker

[root@localhost yum.repos.d]# docker pull gitlab/gitlab-ce
Using default tag: latest
Trying to pull repository docker.io/gitlab/gitlab-ce ... 
latest: Pulling from docker.io/gitlab/gitlab-ce
34667c7e4631: Already exists 
d18d76a881a4: Already exists 
119c7358fbfc: Already exists 
2aaf13f3eff0: Already exists 
0419940fe7a7: Pull complete 
fdfc98a5a88c: Pull complete 
528a77b4f9fa: Pull complete 
a274d023db8d: Pull complete 
fa17b2420391: Pull complete 
5d4c6614ea1f: Pull complete 
Digest: sha256:f2bc4be86013843d5c5ae21452032e50836095f7efd8ce64801b6e707198bdbf
Status: Downloaded newer image for docker.io/gitlab/gitlab-ce:latest

[root@localhost yum.repos.d]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
docker.io/gitlab/gitlab-ce   latest              e55a3e903832        2 days ago          1.76 GB
docker.io/gitlab/gitlab-ce   <none>              95c525dbb80f        2 weeks ago         1.62 GB
[root@localhost yum.repos.d]# docker rmi 95c525dbb80f
Untagged: docker.io/gitlab/gitlab-ce@sha256:e942c9d7f4d97b992649ca7bf8c82e4954eece26322146de2fe99ecfc9f30661
Deleted: sha256:95c525dbb80fb1e95b9081dada0791714f5c2678783ae78c4b82d3d69357d1a4
Deleted: sha256:52a4d4030c5b476617c3f020f0bab4c821f920eb8b162751ea70a335072c6083
Deleted: sha256:a4c4075f663f1801830cb896940ea1405d28a20fa5a67d2a0a15b7b3e8f012ce
Deleted: sha256:d4e59505eeaea837fac98b63dcaf8ffb8868b01fd0c3514e34fd648d1751c77e
Deleted: sha256:b59fef02e8f5cfd07b373993c3d08867bf6ec330891d06def09510c900cebb5c
Deleted: sha256:cd3141d9ff3b5edf73d56b8ae922983a06a14440d95b58ce8d134ba94551344e
Deleted: sha256:414dcd75a87a08ef8b29de7d93edd25d827cbe1cc937d6d29e1dbbeead14c626
[root@localhost yum.repos.d]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
docker.io/gitlab/gitlab-ce   latest              e55a3e903832        2 days ago          1.76 GB

2.4配置

2.4.1禁用Selinux和防火墙

setenforce 0 #临时禁用
# vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled  # 修改为disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

同时禁用防火墙

systemctl stop firewalld
systemctl status firewalld
systemtl restart network

2.4.2创建目录

[root@localhost yum.repos.d]# mkdir /usr/local/gitlab
[root@localhost yum.repos.d]# mkdir /usr/local/gitlab/config
[root@localhost yum.repos.d]# mkdir /usr/local/gitlab/log
[root@localhost yum.repos.d]# mkdir /usr/local/gitlab/opt

2.4.2创建容器

[root@localhost yum.repos.d]# docker run -d \
> --hostname 192.168.74.205 \ # 此处填写虚拟机的IP即可。
> -p 9443:443 \
> -p 9480:80 \
> -p 9422:22 \
> --name gitlab \
> --restart always \
> -v /usr/local/gitlab/config/:/etc/gitlab \
> -v /usr/local/gitlab/log:/var/log/gitlab \
> -v /usr/local/gitlab/opt/:/var/opt/gitlab \
> gitlab/gitlab-ce:latest
0ebd8612ae0ce6129502157f8e38d15966d0469635d65e6258c9afdfe5ffa327



[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                         PORTS               NAMES
0ebd8612ae0c        gitlab/gitlab-ce:latest   "/assets/wrapper"   8 minutes ago       Restarting (1) 2 seconds ago                       gitlab
[root@localhost yum.repos.d]# docker restart 0ebd8612ae0c
0ebd8612ae0c
[root@localhost yum.repos.d]# docker restart 0ebd8612ae0c
0ebd8612ae0c
[root@localhost yum.repos.d]# docker inspect gitlab --format "{{.State.Status}}"
running
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                            PORTS                                                               NAMES
0ebd8612ae0c        gitlab/gitlab-ce:latest   "/assets/wrapper"   8 minutes ago       Up 2 seconds (health: starting)   0.0.0.0:9422->22/tcp, 0.0.0.0:9480->80/tcp, 0.0.0.0:9443->443/tcp   gitlab
[root@localhost yum.repos.d]# docker inspect gitlab --format "{{.State.Status}}"
running

2.4.3配置web请求地址

[root@localhost yum.repos.d]# vim /usr/local/gitlab/config/gitlab.rb
[root@localhost yum.repos.d]# cat /usr/local/gitlab/config/gitlab.rb
~~external_url 'http://192.168.74.204'~~ 
external_url 'http://192.168.74.204:9480' #需要添加上端口

2.4.4配置重载

[root@localhost yum.repos.d]# docker logs 0ebd8612ae0c
Thank you for using GitLab Docker Image!
Current version: gitlab-ce=11.9.1-ce.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
  docker exec -it gitlab vim /etc/gitlab/gitlab.rb
  docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:
  docker exec -it gitlab update-permissions
  docker restart gitlab
Installing gitlab.rb config...
cp: cannot create regular file '/etc/gitlab/gitlab.rb': Permission denied
Thank you for using GitLab Docker Image!
Current version: gitlab-ce=11.9.1-ce.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
  docker exec -it gitlab vim /etc/gitlab/gitlab.rb
  docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:
  docker exec -it gitlab update-permissions
  docker restart gitlab
Installing gitlab.rb config...
cp: cannot create regular file '/etc/gitlab/gitlab.rb': Permission denied
Thank you for using GitLab Docker Image!
Current version: gitlab-ce=11.9.1-ce.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
  docker exec -it gitlab vim /etc/gitlab/gitlab.rb
  docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:
  docker exec -it gitlab update-permissions
  docker restart gitlab
Installing gitlab.rb config...
cp: cannot create regular file '/etc/gitlab/gitlab.rb': Permission denied
Thank you for using GitLab Docker Image!
Current version: gitlab-ce=11.9.1-ce.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
  docker exec -it gitlab vim /etc/gitlab/gitlab.rb
  docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:
  docker exec -it gitlab update-permissions
  docker restart gitlab
Generating ssh_host_rsa_key...
Generating public/private rsa key pair.
Saving key "/etc/gitlab/ssh_host_rsa_key" failed: Permission denied

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                            PORTS                                                               NAMES
0ebd8612ae0c        gitlab/gitlab-ce:latest   "/assets/wrapper"   24 hours ago        Up 2 minutes (health: starting)   0.0.0.0:9422->22/tcp, 0.0.0.0:9480->80/tcp, 0.0.0.0:9443->443/tcp   gitlab

注意:该博客暂时无效

2.5运行

3总结

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值