無需網(wǎng)絡(luò),也能部署Harbor?離線安裝攻略來了!
在當(dāng)今云計算時代,容器化技術(shù)正逐漸成為軟件開發(fā)和部署的主流方式。而Harbor作為一個開源的企業(yè)級Docker Registry管理工具,為用戶提供了安全、可信賴的容器鏡像存儲和管理解決方案。然而,有時候我們面臨的環(huán)境可能并不總是能夠直接連接互聯(lián)網(wǎng),這時如何在離線環(huán)境下部署Harbor成了一個挑戰(zhàn)。不過,別擔(dān)心!本文將為您介紹如何在無網(wǎng)絡(luò)環(huán)境下成功部署Harbor,讓您的容器化之路更加順暢。
離線部署docker
在部署Harbor之前,我們需要提前安裝好docker環(huán)境,由于本環(huán)境模擬的是無法鏈接互聯(lián)網(wǎng),所以,安裝docker的方式也是采用離線部署的方式。
我這里以下載「docker-18.06.3-ce的版本」為例,docker離線包[1]。
解壓文件
把下載的壓縮包解壓到指定的目錄下,解壓出來的文件全部都是二進(jìn)制文件。執(zhí)行如下命令進(jìn)行解壓操作:
tar -zxvf docker-18.06.3-ce.tgz -C /usr/bin
將docker注冊為service
進(jìn)入/etc/systemd/system/目錄,并創(chuàng)建docker.service文件,并把下面的的內(nèi)容復(fù)制到docker.service文件中。
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
給docker.service文件添加執(zhí)行權(quán)限,執(zhí)行如下命令:
chmod +x /etc/systemd/system/docker.service
啟動服務(wù)
每次修改docker.service這個文件時都要重新加載下,執(zhí)行下面命令執(zhí)行:
systemctl daemon-reload
執(zhí)行如下命令啟動docker:
systemctl start docker
配置開啟自啟動,執(zhí)行如下命令:
systemctl enable docker
驗證docker是否啟動成功
執(zhí)行如下命令查看docker狀態(tài),顯示active(running)表示啟動成功。
systemctl status docker
執(zhí)行如下命令,查看版本信息:
[root@harbor ~]# docker -v
Docker version 18.06.3-ce, build d7080c1
安裝docker-compose
docker-compose下載地址[2],下載之后把它移到相應(yīng)的目錄下,并賦予執(zhí)行的權(quán)限:
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
測試安裝結(jié)果
查看docker-compose的對應(yīng)版本:
[root@harbor ~]# docker-compose -v
Docker Compose version v2.9.0
部署Harbor
下載離線安裝包
從這個harbor下載地址[3],下載對應(yīng)的Harbor版本的軟件。
解壓安裝包
把下載好的離線包解壓到指定的目錄下:
tar -zxvf harbor-offline-installer-v2.3.1_2.tgz -C /usr/local/
修改配置文件
拷貝模板文件為 harbor.yml:
cp harbor.yml.tmpl harbor.yml
編輯 harbor.yml 配置文件,hostname 是 harbor 對外暴露的訪問地址,HTTP 服務(wù)對外暴露 8888端口。這里暫時先不配置 HTTPS,將 HTTPS 相關(guān)內(nèi)容注釋。
部署 Harbor
修改完配置文件后,只需要執(zhí)行install.sh 腳本即可安裝 Harbor:
./install.sh
查看 Harbor 組件運行狀況:
登錄頁面
瀏覽器輸入 http://10.91.74.240:8888 訪問 Harbor 頁面,用戶名和密碼為 harbor.yml 配置文件中默認(rèn)設(shè)置的 admin,Harbor12345
推送鏡像
從公網(wǎng)拉取一個pause:3.7 版本的鏡像 ,打包導(dǎo)出并上傳到內(nèi)網(wǎng)機(jī)上:
docker save -o pause:3.7.tar registry.aliyuncs.com/google_containers/pause:3.7
編輯 /etc/docker/daemon.json,設(shè)置允許訪問的 HTTP 倉庫地址。
{
"insecure-registries":["10.91.74.240:8888"]
}
修改鏡像 tag:
docker tag pause:3.7 10.91.74.240:8888/k8s/pause:3.7
登錄 Harbor:
[root@harbor ~]# docker login 10.91.74.240:8888
Username: admin
Password:
Login Succeeded
推送鏡像到 Harbor:
[root@harbor ~]# docker push 10.91.74.240:8888/k8s/pause:3.7
The push refers to repository [10.91.74.240:8888/k8s/pause]
1cb555415fd3: Pushed
3.7: digest: sha256:445a99db22e9add9bfb15ddb1980861a329e5dff5c88d7eec9cbf08b6b2f4eb1 size: 526
查看推送的鏡像:
寫到最后
至此,您已經(jīng)成功在離線環(huán)境下部署了Harbor。無需網(wǎng)絡(luò),也能輕松部署Harbor!通過本文提供的離線安裝攻略,您可以在任何環(huán)境中都能享受到Harbor的便利和安全性。愿本文能對您在容器化之路上的旅程有所幫助!
Reference
- [1]docker離線包:https://download.docker.com/linux/static/stable/x86_64/
- [2]docker-compose下載地址:https://github.com/docker/compose/releases/tag/v2.9.0
- [3]harbor下載地址:https://github.com/goharbor/harbor/releases/download/v2.3.1/harbor-offline-installer-v2.3.1.tgz