一看必會系列:docker 練習 11 docker部署gitlab及gitlab遷移方法

來源:本站原創 Docker 超過242 views圍觀 0條評論

gitlab docker安裝

前提
關閉selinux:
# sed -i ‘s/enforcing/disabled/’ /etc/selinux/config
# setenforce 0
關閉swap:
# swapoff -a  # 臨時
# vim /etc/fstab  # 永久
同步時間:
# yum install ntpdate -y
# ntpdate  ntp.api.bz

# step 1: 安裝必要的一些系統工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加軟件源信息
sudo yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安裝 Docker-CE
sudo yum makecache fast
yum install docker-ce-17.03.3.ce -y
如果提示container-selinux依賴問題,先安裝ce-17.03匹配版本:
# yum localinstall https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm
# Step 4: 開啟Docker服務
# systemctl enable docker && systemctl start docker

# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.03.3-ce   #版本信息

部署容器
sudo docker run –detach \
  –hostname git03.jdccie.com \
  –publish 4430:443 –publish 803:80 –publish 223:22 \
  –name gitlab03 \
  –restart always \
  –volume /data/service/gitlab/config:/etc/gitlab \
  –volume /data/service/gitlab/logs:/var/log/gitlab \
  –volume /data/service/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest
 
–restart 標志會檢查容器的退出代碼,并據此來決定是否要重啟容器,默認是不會重啟。
–restart的參數說明
always:無論容器的退出代碼是什么,Docker都會自動重啟該容器。
on-failure:只有當容器的退出代碼為非0值的時候才會自動重啟。另外,該參數還接受一個可選的重啟次數參數,
–restart=on-fialure:5`表示當容器退出代碼為非0時,Docker會嘗試自動重啟該容器,最多5次。

 
驗證
[email protected]:~# docker ps
CONTAINER ID        IMAGE                                    COMMAND                                 
PORTS                                                             NAMES
b4a6652f3a4d        gitlab/gitlab-ce:latest                  "/assets/wrapper"         
0.0.0.0:223->22/tcp, 0.0.0.0:803->80/tcp, 0.0.0.0:4430->443/tcp   gitlab03

目錄說明
Local location    Container location    Usage
/srv/gitlab/data    /var/opt/gitlab    For storing application data
/srv/gitlab/logs    /var/log/gitlab    For storing logs
/srv/gitlab/config    /etc/gitlab    For storing the GitLab configuration files

 

#gitlab 遷移及恢復數據
1.容器外復制備份文件到 logs目錄
cp ../15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar logs/
2.
docker exec -it a622702ec855 /bin/bash
[email protected]:/#
3. 容器內
[email protected]:/var/log/gitlab# cp 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar /var/opt/gitlab/backups
4. 修改權限
chmod 666 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar
5  恢復數據
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=15531jdccie.com_2019_03_21_10.7.3
其中有兩處需要 輸入yes,注意一下
Do you want to continue (yes/no)? yes

5 。修改 project的域名信息
修改前http://1.1.1.1/root/git03.git
修改后
http://git03.jdccie.com:803/root/git03.git

修改方法
1.進容器
2.在容器里修改
vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

修改內容
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: git03.jdccie.com:803   #這時取巧了。因為容器對外的端口是803但容器內的端口是80所以改成這樣
    port: 80                     #這個不要動,會啟不動,當然也有另外的方法看最后
    https: false

3.在容器里重啟
gitlab-ctl restart

訪問驗證即可

———-其它信息

如果在selinux環境用以下命令
sudo docker run –detach \
  –hostname gitlab.example.com \
  –publish 443:443 –publish 80:80 –publish 22:22 \
  –name gitlab \
  –restart always \
  –volume /srv/gitlab/config:/etc/gitlab:Z \
  –volume /srv/gitlab/logs:/var/log/gitlab:Z \
  –volume /srv/gitlab/data:/var/opt/gitlab:Z \
  gitlab/gitlab-ce:latest
 
 
sudo docker exec -it gitlab /bin/bash

You can also just edit /etc/gitlab/gitlab.rb:

sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb

Once you open /etc/gitlab/gitlab.rb make sure to set the external_url to point to a valid URL.

To receive e-mails from GitLab you have to configure the SMTP settings because the GitLab Docker image doesn’t have an SMTP server installed.

You may also be interested in Enabling HTTPS.

After you make all the changes you want, you will need to restart the container in order to reconfigure GitLab:

sudo docker restart gitlab

升級新版本

1 sudo docker stop gitlab
2 sudo docker rm gitlab
3 sudo docker pull gitlab/gitlab-ce:latest
4 sudo docker run –detach \
–hostname gitlab.example.com \
–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
 
 
這里可以直接改域名信息
Create a docker-compose.yml file (or download an example):

web:
   image: ‘gitlab/gitlab-ce:latest’
   restart: always
   hostname: ‘gitlab.example.com’
   environment:
     GITLAB_OMNIBUS_CONFIG: |
       external_url ‘https://gitlab.example.com’
       # Add any other gitlab.rb configuration here, each on its own line
   ports:
     – ’80:80′
     – ‘443:443’
     – ’22:22′
   volumes:
     – ‘/srv/gitlab/config:/etc/gitlab’
     – ‘/srv/gitlab/logs:/var/log/gitlab’
     – ‘/srv/gitlab/data:/var/opt/gitlab’
 
 
———-報錯

"couldn’t deduce an advertise address: no private IP found, explicit advertise addr not provided"

#恢復報錯
Unpacking backup … tar: 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar: Cannot open: Permission denied

處理方式 修改權限
[email protected]:/var/opt/gitlab/backups# ll
total 430188
drwx——.  2 git  root      4096 Mar 21 06:03 ./
drwxr-xr-x. 19 root root      4096 Mar 21 04:52 ../
-rw——- #原來的權限.  1 root root 440504320 Mar 21 06:03 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar
[email protected]:/var/opt/gitlab/backups# chmod 666 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar
[email protected]:/var/opt/gitlab/backups# ll
total 430188
drwx——.  2 git  root      4096 Mar 21 06:03 ./
drwxr-xr-x. 19 root root      4096 Mar 21 04:52 ../
-rw-rw-rw-#修改后的.  1 root root 440504320 Mar 21 06:03 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar

[email protected]:/var/opt/gitlab/backups# gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=15531jdccie.com_2019_03_21_10.7.3                                                                              
Unpacking backup … done
GitLab version mismatch:
  Your current GitLab version (11.8.3) differs from the GitLab version in the backup!
  Please switch to the following version and try again:
  version: 10.7.3

[[email protected] logs]# docker pull gitlab/gitlab-ce:10.7.3-ce.0

刪除原容器后,創建新容器報錯
Error response from daemon: service endpoint with name gitlab03 already exists

原因,是容器被刪了。但網絡占用仍在占用
解決
1.確認刪除容器  docker rm -f 容器ID
2.確認容器使用的網絡也被刪除
docker network inspect 網絡模式
3.強制斷開該網絡 docker network disconnect –force 網絡模式 xxx
docker network disconnect –force bridge gitlab03
4.驗證 不出現gitlab03即可
[[email protected] ~]# docker network inspect bridge
5.重建容器即可

這是之前的信息
[[email protected] ~]# docker network inspect bridge
        "Name": "bridge",
                "Name": "gitlab03",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",

https://docs.gitlab.com/omnibus/docker/README.html

#
[[email protected] ops]# docker ps
CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS                         PORTS                                                             NAMES
0ce0e6599588        gitlab/gitlab-ce:10.7.3-ce.0   "/assets/wrapper"   About an hour ago   Up About an hour (unhealthy)   0.0.0.0:223->22/tcp, 0.0.0.0:803->80/tcp, 0.0.0.0:4430->443/tcp   gitlab03
[[email protected] ops]#

docker inspect 0ce0e6599588

                    {
                        "Start": "2019-03-21T09:14:29.322227599Z",
                        "End": "2019-03-21T09:14:59.322409713Z",
                        "ExitCode": -1,
                        "Output": "Health check exceeded timeout (30s)"
                    }

查看日志是nginx配置文件改的有問題

==> /var/log/gitlab/unicorn/unicorn_stderr.log <==
I, [2019-03-21T09:15:22.477559 #945]  INFO — : reaped #<Process::Status: pid 1177 exit 0> worker=0
I, [2019-03-21T09:15:22.477894 #945]  INFO — : reaped #<Process::Status: pid 1180 exit 0> worker=1
I, [2019-03-21T09:15:22.477985 #945]  INFO — : reaped #<Process::Status: pid 1183 exit 0> worker=2
I, [2019-03-21T09:15:22.478067 #945]  INFO — : reaped #<Process::Status: pid 1189 exit 0> worker=4
I, [2019-03-21T09:15:22.478318 #945]  INFO — : reaped #<Process::Status: pid 3199 exit 0> worker=3
I, [2019-03-21T09:15:22.478480 #945]  INFO — : master complete
ok: down: unicorn: 0s, normally up

從容器里把有問題的配置文件搞出來
docker cp 0ce0e6599588:/var/opt/gitlab/nginx/conf/gitlab-http.conf .
[[email protected] ops]# ls
gitlab-http.conf
修改
[[email protected] ops]# vim gitlab-http.conf
再搞回去
[[email protected] ops]# docker cp gitlab-http.conf 0ce0e6599588:/var/opt/gitlab/nginx/conf/gitlab-http.conf
重新啟動服務器

文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4104轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏