安裝Harbor1.4.0開源docker鏡像倉庫(含letsencrypt認證),dockerletsencrypt
文檔版本號碼:20180216
最近在Ubuntu Linux 14.04上和CentOS Linux 7.4上成功安裝了Harbor,現將過程整理如下,供大家參考:
備忘:使用非root使用者操作Docker,需要建立docker組sudo groupadd docker將目前使用者加入docker組sudo gpasswd -a ${USER} docker重新啟動docker服務(下面是CentOS7的命令)sudo systemctl restart docker目前使用者退出系統重新登陸。一、harbor安裝檔案下載:
1、harbor項目首頁:https://github.com/vmware/harbor/
2、查看README.md,安裝說明在README.md的“Installation & Configuration Guide”中:
https://github.com/vmware/harbor/blob/master/docs/installation_guide.md
3、README.md告知,master屬於開發版,可能不穩定,需下載正式發行版:
https://github.com/vmware/harbor/releases
為了便於安裝,選擇下載二進位版,國內鏡像目前只有二進位離線版,接近800M,下載了最新的1.4.0版:
harbor-offline-installer-v1.4.0.tgz
MD5:6161843c84c9944a087
4、解壓harbor-offline-installer-v1.4.0.tgz後發現,內含一個近800M的全部鏡像的壓縮包harbor.v1.4.0.tar.gz,為了便於上傳到伺服器,將harbor.v1.4.0.tar.gz刪除,重新打包命名為harbor.bytefish.online-installer-v1.4.0.tgz,大小約為32K。
5、上傳harbor.bytefish.online-installer-v1.4.0.tgz到伺服器,並解壓,會在目前的目錄下產生harbor目錄。
$ scp -i .ssh/id_rsa harbor.bytefish.online-installer-v1.4.0.tgz 使用者名稱@docker.MySite.com:/路徑/harbor.bytefish.online-installer-v1.4.0.tgz$ ssh 使用者名稱@docker.MySite.com -i .ssh/id_rsa$ tar -zxf harbor.bytefish.online-installer-v1.4.0.tgz && cd harbor
二、確認伺服器資源:
1、官方對伺服器資源的最小要求和建議:
Hardware:Resource Capacity DescriptionCPU minimal 2 CPU 4 CPU is preferedMem minimal 4GB 8GB is preferedDisk minimal 40GB 160GB is preferedSoftware:Software Version DescriptionPython version 2.7 or higher Note that you may have to install Python on Linux distributions (Gentoo, Arch) that do not come with a Python interpreter installed by defaultDocker engine version 1.10 or higher For installation instructions, please refer to: https://docs.docker.com/engine/installation/Docker Compose version 1.6.0 or higher For installation instructions, please refer to: https://docs.docker.com/compose/install/Openssl latest is prefered Generate certificate and keys for HarborNetwork ports:Port Protocol Description443 HTTPS Harbor UI and API will accept requests on this port for https protocol4443 HTTS Connections to the Docker Content Trust service for Harbor, only needed when Notary is enabled80 HTTP Harbor UI and API will accept requests on this port for http protocol
2、確認伺服器docker版本:
$ docker version
3、確認docker-compose、Python、OpenSSL版本:
$ docker-compose version
4、確認硬體情況:
$ cat /proc/cpuinfo
$ free
5、確認網路連接埠是否被佔用:
$ ss -tna
三、編輯設定檔,並安裝:
1、編輯harbor目錄下harbor.cfg檔案,修改內容如下:
hostname = docker.MySite.com# email服務的相關參數也可在安裝完成後進入網站頁面配置:email_identity =email_server = smtp.mailserver.com# mailserver portemail_server_port = 25email_username = username@mailserver.comemail_password = 郵件服務密碼email_from = adminemail_ssl = trueemail_insecure = falseharbor_admin_password = 設定一個管理員密碼db_password = 設定一個mysql的密碼# self_registration預設為on,是針對資料庫認證方式,訪客可以自己註冊,對於LDAP認證方式無法自註冊:self_registration = off
2、使用root許可權執行install.sh(該指令碼將會在根目錄下建立/data目錄及相關檔案),將自動下載相關docker鏡像檔案,並自動安裝完成:
~/harbor$ sudo ./install.sh
3、容器將自動啟動,此時可用瀏覽器開啟 http://docker.MySite.com,使用管理員帳號admin登陸。
四、配置LDAP:
1、使用管理員帳號admin登陸http://docker.MySite.com,點擊“系統管理”、“組態管理”,將“認證模式”選擇為LDAP,並配置相關參數:
LDAP URL : ldap://MySite.comLDAP搜尋DN : cn=admin,dc=MySite,dc=comLDAP搜尋密碼: 密碼LDAP基礎DN : dc=MySite,dc=comLDAP過濾器 : (|(objectclass=inetOrgPerson))LDAP使用者UID的屬性 : uidLDAP搜尋範圍 : 子樹LDAP 檢查認證 : (測試發現: “LDAP 檢查認證” 選不選都能通過ldap登陸,待再次驗證。)
2、點擊“測試LDAP伺服器”按鈕,如果成功,瀏覽器頂部將顯示“LDAP伺服器的連通正常。”的提示。
3、此時可用LDAP中的帳號登陸web頁面,但無法通過docker login登陸,還需配置網站https認證。
五、配置https認證:
1、安裝說明:
https://github.com/vmware/harbor/blob/master/docs/configure_https.md
2、在/home/ubuntu/harbor目錄執行docker-compose down,停止並刪除容器:
$ docker-compose down
3、本來想通過Let’s Encrypt官方的certbot指令碼(certbot.eff.org)安裝認證,但是指令碼不能成功執行,估計是因為nginx是在容器裡造成的,但是通過這個指令碼自動安裝了一些軟體包。然後嘗試通過git擷取letsencrypt進行安裝:
$ git clone https://github.com/letsencrypt/letsencrypt
4、進入letsencrypt目錄,產生認證
$ cd letsencrypt$ sudo ./letsencrypt-auto certonly --standalone --email username@mailserver.com -d docker.MySite.comSaving debug log to /var/log/letsencrypt/letsencrypt.logPlugins selected: Authenticator standalone, Installer NoneObtaining a new certificatePerforming the following challenges:http-01 challenge for docker.MySite.comWaiting for verification...Cleaning up challengesIMPORTANT NOTES:- Congratulations! Your certificate and chain have been saved at:/etc/letsencrypt/live/docker.MySite.com/fullchain.pemYour key file has been saved at:/etc/letsencrypt/live/docker.MySite.com/privkey.pemYour cert will expire on 2018-05-15. To obtain a new or tweakedversion of this certificate in the future, simply runletsencrypt-auto again. To non-interactively renew *all* of yourcertificates, run "letsencrypt-auto renew"- If you like Certbot, please consider supporting our work by:Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donateDonating to EFF: https://eff.org/donate-le
5、認證到期日期為2018-05-15,產生的認證檔案位於/etc/letsencrypt/live/docker.MySite.com/檔案夾(連結檔案):
$ sudo ls /etc/letsencrypt/live/docker.MySite.com/ -llrwxrwxrwx 1 root root 40 Feb 14 23:30 cert.pem -> ../../archive/docker.MySite.com/cert1.pemlrwxrwxrwx 1 root root 41 Feb 14 23:30 chain.pem -> ../../archive/docker.MySite.com/chain1.pemlrwxrwxrwx 1 root root 45 Feb 14 23:30 fullchain.pem -> ../../archive/docker.MySite.com/fullchain1.pemlrwxrwxrwx 1 root root 43 Feb 14 23:30 privkey.pem -> ../../archive/docker.MySite.com/privkey1.pem-rw-r--r-- 1 root root 543 Feb 14 23:30 README
cert.pem - 服務端認證
chain.pem - 瀏覽器需要的所有認證但不包括服務端認證,比如根憑證和中間認證
fullchain.pem - 包括了cert.pem和chain.pem的內容
privkey.pem - 認證的私密金鑰
6、建立目錄letsencrypt,並將認證檔案拷貝到該目錄:
$ mkdir /home/ubuntu/harbor/letsencrypt/ && cd /home/ubuntu/harbor/letsencrypt/$ sudo cp /etc/letsencrypt/archive/docker.MySite.com/fullchain1.pem docker.MySite.com.crt$ sudo cp /etc/letsencrypt/archive/docker.MySite.com/privkey1.pem docker.MySite.com.key
7、修改/home/ubuntu/harbor/harbor.cfg設定檔:
#設定ui_url_protocol為httpsui_url_protocol = https#設定認證檔案ssl_cert = /home/ubuntu/harbor/letsencrypt/docker.MySite.com.crtssl_cert_key = /home/ubuntu/harbor/letsencrypt/docker.MySite.com.key
8、用root許可權執行一次prepare指令碼,並啟動docker重建容器:
$ sudo /home/ubuntu/harbor/prepare$ docker-compose up -d
六、上傳鏡像:
1、用瀏覽器開啟 http://docker.MySite.com,用普通使用者帳號登入,並建立一個項目“test”:
2、在用戶端登入docker.MySite.com:
$ docker login docker.MySite.comUsername: bytefishPassword: 密碼Login Succeeded
3、將用戶端的鏡像打tag,然後上傳到docker.MySite.com:
格式:
docker tag SOURCE_IMAGE[:TAG] docker.MySite.com/項目名稱/IMAGE[:TAG]docker push docker.MySite.com/項目名稱/IMAGE[:TAG]
樣本:
$ docker tag hello-world:latest docker.MySite.com/test/hello-world:test$ docker push docker.MySite.com/test/hello-world:testThe push refers to a repository [docker.MySite.com/test/hello-world]f999ae22f308: Mounted from library/hello-worldtest: digest: sha256:0b1396cdcea05f91f38fc7f5aecd58ccf19fb5743bbb79cff5eb3c747b36d909 size: 524