一、安裝Docker
1.安裝docker依賴包
[root@gitlab ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
2.新增Docker-ce映象源並安裝
1.1)國外源(適合在國外工作的朋友)
[root@gitlab ~]# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
1.2)國內阿里雲源(適合在國內工作的朋友)
[root@gitlab ~]# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2)伺服器的包資訊下載到本地電腦快取起來
[root@gitlab ~]# yum makecache fast
3)安裝docker CE
[root@gitlab ~]# yum -y install docker-ce
4)配置下載docker映象加速器
國外加速器:
[root@gitlab ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://bc437cce.m.daocloud.io
國內阿里雲加速器:
vim /etc/docker/daemon.json
#輸入下面內容並儲存:
{
"registry-mirrors": [https://9w1hl6qt.mirror.aliyuncs.com]
}
5)過載systemctl並自動和開啟自啟動docker
[root@gitlab ~]# systemctl daemon-reload
[root@gitlab ~]# systemctl start docker
[root@gitlab ~]# systemctl enable docker
[root@gitlab ~]# docker --version
Docker version 18.09.0, build 4d60db4
二、安裝Docker-compose
下載Docker-compose二進位制檔案並新增執行許可權
[root@gitlab ~]# curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s-uname -m` -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 590 0 --:--:-- 0:00:01 --:--:-- 590
100 11.2M 100 11.2M 0 0 498k 0 0:00:23 0:00:23 --:--:-- 737k
[root@gitlab ~]# chmod +x /usr/local/bin/docker-compose
[root@gitlab ~]# docker-compose --version
docker-compose version 1.23.2, build 1110ad01
三、安裝Gitlab
1)編輯docker-compose的yml檔案
[root@gitlab ~]# mkdir gitlab
[root@gitlab ~]# cd gitlab
[root@gitlab gitlab]# vim docker-compose.yml
version: '2'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh:latest'
container_name: "gitlab"
restart: unless-stopped
privileged: true
hostname: 'gitlab'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://ip或者用nginx做反代的域名'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxx@163.com"
gitlab_rails['smtp_password'] = "授權碼"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxxxx@163.com'
gitlab_rails['gitlab_shell_ssh_port'] = 22
ports:
- '8181:80'
- '8443:443'
- '22:22'
volumes:
- /opt/gitlab/config:/etc/gitlab
- /opt/gitlab/data:/var/opt/gitlab
- /opt/gitlab/logs:/var/log/gitlab
埠對映說明以及注意事項:
gitlab映象官方推薦容器80埠對映宿主機8181埠
gitlab映象官方推薦容器443埠對映宿主機8443埠
gitlab映象官方推薦容器22埠對映宿主機22埠
⭐️頭兩行不能頂頭寫,要分別都空一行,可以去yml檔案檢測網站進行檢測:
www.bejson.com/validators/yaml_edi...
2)建立相關目錄
[root@gitlab gitlab]# mkdir -p /opt/gitlab/{config,data,logs}
[root@gitlab gitlab]# ls -l /opt/gitlab/
total 0
drwxr-xr-x 2 root root 6 Dec 22 12:03 config
drwxr-xr-x 2 root root 6 Dec 22 12:03 data
drwxr-xr-x 2 root root 6 Dec 22 12:03 logs
目錄說明如下:
config 儲存 GitLab 配置資訊
data 儲存資料庫
logs 儲存日誌
3)拉取gitlab中文版映象
[root@gitlab gitlab]# docker pull twang2218/gitlab-ce-zh:latest
latest: Pulling from twang2218/gitlab-ce-zh
8ee29e426c26: Pull complete
6e83b260b73b: Pull complete
e26b65fd1143: Pull complete
40dca07f8222: Pull complete
b420ae9e10b3: Pull complete
a218309dd589: Pull complete
5c60fd7ba0ce: Pull complete
659c2144b5a3: Pull complete
8289bbac0d0e: Pull complete
31bbd150e8a7: Pull complete
9114e78243fa: Pull complete
e242e5cd1314: Pull complete
0a079dc3f92c: Pull complete
f0e195b09fd2: Pull complete
6e23346e2f58: Pull complete
91f00659be69: Pull complete
a1031bcc5b2c: Pull complete
e3074327c7b1: Pull complete
a917618dbe42: Pull complete
Digest: sha256:62686b74c6fca5ece8ed582d03a126c5988423dd8a19ce70e9a22357ffcaf1c8
Status: Downloaded newer image for twang2218/gitlab-ce-zh:latest
[root@gitlab gitlab]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
twang2218/gitlab-ce-zh latest 18da462b5ff5 4 months ago 1.61GB
4)啟動gitlab的容器
在啟動前,先要修改宿主機的22埠,因為宿主機佔用了22埠,所以啟動容器會失敗,因為對映不過來,修改如下:
vim /etc/ssh/sshd_config
預設在第17行修改:Port 2222
修改後,重啟sshd:systemctl restart sshd
[root@gitlab gitlab]# netstat -tulnp | grep 22
tcp 0 0 0.0.0.0:2222 0.0.0.0: LISTEN 31889/sshd
tcp6 0 0 :::2222 ::: LISTEN 31889/sshd
正式啟動:
[root@gitlab gitlab]# docker-compose up -d
Creating network "gitlab_default" with the default driver
Creating gitlab ... done
[root@gitlab gitlab]# docker-compose ps
Name Command State Ports
gitlab /assets/wrapper Up (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:8443->443/tcp, 0.0.0.0:8181->80/tcp
[root@gitlab gitlab]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
814e559dc728 twang2218/gitlab-ce-zh:latest "/assets/wrapper" 5 minutes ago Up 5 minutes (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:8181->80/tcp, 0.0.0.0:8443->443/tcp gitlab
5)gitlab設定開機啟動
[root@gitlab gitlab]# chmod +x /etc/rc.local
[root@gitlab gitlab]# ls -l /etc/rc.local
lrwxrwxrwx 1 root root 13 Dec 3 14:31 /etc/rc.local -> rc.d/rc.local
[root@gitlab gitlab]# echo "cd /root/gitlab && docker-compose up -d" >> /etc/rc.local
[root@gitlab gitlab]# tail -1 /etc/rc.local
cd /root/gitlab && docker-compose up -d
6)gitlab管理介面
轉載www.jb51.net/article/153399.htm
地址:在瀏覽器輸入yml檔案的第12行ip或者域名
使用者:root
密碼:首次登陸需要手動設定密碼
如下圖所示:
本作品採用《CC 協議》,轉載必須註明作者和本文連結