CentOS7 安裝Harbor1.1.2

前言

Harbor是一個用於存儲和分發Docker鏡像的企業級Registry服務器,通過添加一些企業必需的功能特性,例如安全、標識和管理等,擴展了開源Docker Distribution。作爲一個企業級私有Registry服務器,Harbor提供了更好的性能和安全。提升用戶使用Registry構建和運行環境傳輸鏡像的效率[1]。
說白了就是方便自己將項目中使用的公共的Docker 鏡像放到Harbor下進行管理,方便版本更新和維護,減少網絡流量。
目前網絡上關於Harbor的文章時間都比較早了,而且Harbor已經更新到1.1.2版本了,同時Docker今年3月做了版本重命名,基於這個新版本的完整安裝文檔沒有,剛好最近搭建一個Harbor,因此總結了這個文檔,與各位共勉之。


Docker版本變更

Docker在3月份的時候推出了企業版,docker的版本號也發生了翻天覆地的變化。版本也從1.13.x一躍到17.03。
版本變成了社區版(CE,Community Edition)和企業版(EE,Enterprise Edition)。

版本 舉例 說明
月度版本 Edge 版本(17.03, 17.04, 17.05…) 每個月一個版本號
季度版本 Stable 版本(17.03, 17.06, 17.09…) 可以理解爲第三個月的版本號

企業版(EE) 和 Stable 版本號保持一致,每個版本提供一年維護,官方說明圖。
官網的圖片

官方文章《ANNOUNCING DOCKER ENTERPRISE EDITION


版本要求

名稱 版本或者時間
文檔時間 2017/07/08
CentOS 7(1611)
Docker 17.06.0
Docker-Compose 1.14.0
Python 2.7.5(系統自帶)
Harbor 1.1.2

安裝說明

CentOS7自己安裝,這個沒什麼好說明的。我的IP是192.168.0.209。
其他的都會詳細介紹如何安裝,安裝的說明基本來自於官方文檔。

systemctl
這個命令需要了解一下,如果沒用過CentOS7需要看看。
這篇文章《 Centos7下的systemctl命令與service和chkconfig》有詳細的介紹。

接下來會安裝docker,docker-compose,harbor.
python使用的是系統自帶的,達到harbor的要求了。因此就沒有從新安裝。


1:安裝Docker

我的這個安裝方式是按照官網的文檔進行的,因爲採用了新的版本結構,而且是月度更新,因此對於Docker來講升級就變的非常重要。
因此,首先建立一個倉庫,然後在進行安裝。

- 建立倉庫

建立本地倉庫,這個目的就是爲了Docker的版本升級。
安裝需要的包。

# sudo yum install -y yum-utils device-mapper-persistent-data lvm2

安裝yum-utils因爲需要 yum-config-manager工具。
安裝device-mapper-persistent-data 和 lvm2 因爲需要 devicemapper 存儲驅動

# sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

使用上面的命令建立Stable倉庫,Stable這個倉庫總是需要的,即使你想從edge或者testing倉庫安裝更新。

- 可選執行

啓用edge倉庫

# sudo yum-config-manager --enable docker-ce-edge

啓用testing倉庫

# sudo yum-config-manager --enable docker-ce-testing

使用–disable關閉倉庫

Note:

從17.06開始,Stable版本也被push到edge和testing倉庫。

- 安裝Dcoker CE

更新yum的index。

#sudo yum makecache fast

安裝最新版本的Docker CE

#sudo yum install docker-ce

Warning:
如果啓用了多個不同的Docker倉庫,在安裝或者更新時沒有指定一個版本,將會默認安裝最新的版本,最好不要這麼做!

正確的姿勢是每次更新需要指定具體的版本。

#yum list docker-ce.x86_64  --showduplicates | sort -r

列出當前可用的docker版本信息

docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.06.0.ce-1.el7.centos @docker-ce-edge
docker-ce.x86_64 17.05.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.04.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable

列出了所有,第二列是版本的信息,第三列是倉庫的信息。
利用下面的命令安裝特定的版本

# sudo yum install docker-ce-17.06.0.ce-1.el7.centos

啓動Docker

#sudo systemctl start docker

驗證docker是否正確安裝

#sudo docker run hello-world

- 更新Docker
這個操作的過程和安裝的過程是一樣的。
首先運行

#sudo yum makecache fast

安裝指定版本的Docker

# sudo yum install docker-ce-17.06.0.ce-1.el7.centos

2:安裝Docker-Compose

執行下面的命令安裝compose
首先進入這個頁面查看當前的版本。
https://github.com/docker/compose/releases/

下載

#curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

實際下載了一個文件
修改文件的可執行權限

#sudo chmod +x /usr/local/bin/docker-compose

Test the installation.

#docker-compose --version

docker-compose version 1.14.0, build 1719ceb

3:安裝Harbor

下載Harbor
選擇目前最新版本1.1.2
https://github.com/vmware/harbor/releases

我選擇的是online版本,兩種版本基本上差不多。
https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-online-installer-v1.1.2.tgz

解壓

#tar xvf harbor-online-installer-v1.1.2.tgz

配置
在解壓後的路徑下,找到harbor.cfg進行修改

harbor.cfg中的參數包含兩個類型,一個是必須設置,一個是可選設置。
必須設置的參數是必須在cfg文件中進行參數設置的,可以使用默認值,但是必須被設置,否則會無法啓動。
可選設置的參數,在cfg文件中可以設置,也可以刪除或者註釋,不進行設置,不影響啓動。

必須設置的參數

參數 描述
hostname 服務器的名稱,如果訪問UI和註冊服務,需要通過這個。可以是IP地址(192.168.0.209),或者是完整的域名(reg.youdomain.com)。不要使用localhost或者127.0.0.1,因爲服務需要被其他的機器訪問。
db_password: mysql數據的密碼。
customize_crt on或者off。默認是on。當這個屬性是on的時候,prepare腳本爲registry’s token 創建私有key和根證書。如果屬性是off的時候,是有key和根證書將有外部資源提供。瞭解更多請看《Customize Key and Certificate of Harbor Token Service
ssl_cert SSL證書的位置,只有當協議設置成https的時候,這個屬性生效
ssl_cert_key SSL祕鑰的位置,只有當協議設置成https的時候這個屬性生效。
secretkey_path 加密解密的密碼文件路徑

還有一些可選的設置
具體描述參考官方文檔,這裏不進行贅述了。

安裝
官方文檔內容

#sudo ./install.sh

直接執行會提示

[root@192 harbor]# sudo ./install.sh [Step 0]: checking installation
environment … Note: docker version: 17.06.0 ✖ Need to install
docker-compose(1.7.1+) by yourself first and run this script again.

需要換成另外一種安裝方法。

#sudo ./prepare

[root@192 harbor]# ./prepare
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.

然後在執行

#docker-compose up -d

啓動這個後,我們是online版本,提示下載很多東西。時間有點長,慢慢等待。
● harbor-log
● harbor-adminserver
● harbor-ui
● registry
● harbor-db
● harbor-jobservice
● nginx
到這裏,我們應該看清楚了,實際上harbor就是利用docker-compose進行管理Dokcer的一個UI系統。
最後輸出
Creating harbor-log …
Creating harbor-log … done
Creating registry …
Creating harbor-db …
Creating harbor-adminserver …
Creating harbor-db
Creating registry
Creating registry … done
Creating harbor-ui …
Creating harbor-ui … done
Creating harbor-jobservice …
Creating nginx …
Creating harbor-jobservice
Creating harbor-jobservice … done

完成後

http://192.168.0.209/
正常訪問
用戶名:admin
密碼:Harbor12345
可以執行如下的命令進行停止和啓動

停止

#docker-compose stop

啓動

#docker-compose start

結尾

到目前位置Harbor已經安裝完成。
目前這個安裝是沒有包含Notary
如果需要包含Notary請看《官方文檔

後續有時間回寫一個Harbor的簡單使用教程。

參考文章

[1]https://vmware.github.io/harbor/cn/
[2]https://github.com/vmware/harbor/blob/master/docs/installation_guide.md
[3]http://blog.csdn.net/felix_yujing/article/details/54694294

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章