環(huán)境:
? ? ? ? 操作系統(tǒng):CentOS Linux 7 (Core)
? ? ? ? 內(nèi)核:?Linux 3.10.0-1160.el7.x86_64
目錄
安裝搭建harbor
(1)安裝docker編排工具docker compose
(2)下載Harbor 安裝包
(3)修改配置文件
(4)添加主機(jī)映射
安裝啟動(dòng)harbor
安裝后驗(yàn)證
使用Harbor
①訪問瀏覽器
②登錄
③新建一個(gè)項(xiàng)目
上傳下載鏡像到harbor倉庫
(1)修改docker配置,添加harbor倉庫為信任地址
(2)把要上傳的鏡像打上合適的標(biāo)簽
(3)登錄harbor倉庫
(4)上傳鏡像
(5)在harbor上驗(yàn)證上傳成功
控制harbor服務(wù)
(1)暫停/取消暫停harbor服務(wù)
(2)關(guān)閉/開啟harbor服務(wù)
安裝搭建harbor
(1)安裝docker編排工具docker compose
[root@node1 ~]# yum -y install epel-release??#安裝pip需要先安裝epel-release包
[root@node1 ~]# yum install -y python-pip? ? ? ? #安裝pip
[root@node1 ~]# pip install --upgrade pip? ? ? ? ?#升級(jí)pip
[root@node1 ~]# pip install docker-compose? ? ? ? #安裝docker-compose
[root@node1 ~]# docker-compose -v
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
? from cryptography.hazmat.backends import default_backend
docker-compose version 1.29.2, build unknown若升級(jí)報(bào)錯(cuò):
原因:
yum install python-pip
時(shí),CentOS7默認(rèn)的python版本是2.7。它不支持更新到最新版本。解決:
[root@node1 bin]# yum install -y python3-pip? ? #安裝python3的pip
[root@node1 bin]# pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple? ? ? ? #升級(jí)pip(需要使用pip3指令),-i 添加鏡像源地址,提高下載速度
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
[root@node1 bin]# pip3 install docker-compose -i https://pypi.tuna.tsinghua.edu.cn/simple
(2)下載Harbor 安裝包
添加一塊新硬盤格式化后掛載在/harbordata:
①添加sdb1磁盤
首先把虛擬機(jī)系統(tǒng)關(guān)機(jī),在彈出的界面中單擊
添加
按鈕,新增一塊硬件設(shè)備,如下圖所示:
在虛擬機(jī)中模擬添加了硬盤設(shè)備后就應(yīng)該能看到
抽象成的硬盤設(shè)備文件
了。按照udev 服務(wù)命名規(guī)則
,第二個(gè)被識(shí)別的SCSI 設(shè)備
應(yīng)該會(huì)被保存為/dev/sdb
,這個(gè)就是硬盤設(shè)備文件了。但在開始使用該硬盤之前還需要進(jìn)行分區(qū)操作,例如從中取出一個(gè)10GB
?的分區(qū)設(shè)備以供后面的操作使用。用
fdisk 命令
來嘗試管理/dev/sdb
?硬盤設(shè)備:[root@node1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x67bd3d87.Command (m for help): n
Partition type:
? ?p ? primary (0 primary, 0 extended, 4 free)
? ?e ? extended
Select (default p):?
Using default response p
Partition number (1-4, default 1):?
First sector (2048-41943039, default 2048):?
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is setCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.在上述步驟執(zhí)行完畢之后,Linux 系統(tǒng)會(huì)自動(dòng)把這個(gè)硬盤主分區(qū)抽象成/dev/sdb1 設(shè)備文件??梢允褂胒ile 命令查看該文件的屬性,但有些時(shí)候系統(tǒng)并沒有自動(dòng)把分區(qū)信息同步給Linux 內(nèi)核,而且這種情況似乎還比較常見(但不能算作是嚴(yán)重的bug)。可以輸入partprobe 命令手動(dòng)將分區(qū)信息同步到內(nèi)核,而且一般推薦連續(xù)兩次執(zhí)行該命令,效果會(huì)更好。如果使用這個(gè)命令都無法解決問題,那么就重啟計(jì)算機(jī)。
[root@node1 ~]# file /dev/sdb1
/dev/sdb1: block special
[root@node1 ~]# partprobe?
Warning: Unable to open /dev/sr0 read-write (Read-only file system). ?/dev/sr0 has been opened read-only.
[root@node1 ~]# partprobe?
Warning: Unable to open /dev/sr0 read-write (Read-only file system). ?/dev/sr0 has been opened read-only.[root@node1 ~]# file /dev/sdb1
/dev/sdb1: block special
②格式化和掛載[root@node1 ~]# mkfs.ext4 /dev/sdb1
[root@node1 ~]# mkdir /harbordata
[root@node1 ~]# mount /dev/sdb1 /harbordata/
[root@node1 ~]# df -h
(3)修改配置文件
[root@node1 ~]#?/harbordata/harbor
[root@node1 harbor]# cp harbor.yml.tmpl harbor.yml
[root@node1 harbor]# vim harbor.yml
修改hostname值和注釋https為443的信息,如下
(4)添加主機(jī)映射
[root@node1 harbor]# tail -1 /etc/hosts
192.168.19.133 node1
安裝啟動(dòng)harbor
[root@node1 harbor]# ./install.sh?
安裝后驗(yàn)證
①打開了一些端口
[root@node1 harbor]# ss -lntup | grep docker
tcp ? ?LISTEN ? ? 0 ? ? ?128 ? ?127.0.0.1:1514 ? ? ? ? ? ? ? ? ?*:* ? ? ? ? ? ? ? ? ? users:(("docker-proxy",pid=26691,fd=4))
tcp ? ?LISTEN ? ? 0 ? ? ?128 ? ? ? *:80 ? ? ? ? ? ? ? ? ? ?*:* ? ? ? ? ? ? ? ? ? users:(("docker-proxy",pid=27275,fd=4))
tcp ? ?LISTEN ? ? 0 ? ? ?128 ? ?[::]:80 ? ? ? ? ? ? ? ? [::]:* ? ? ? ? ? ? ? ? ? users:(("docker-proxy",pid=27279,fd=4))
②harbor實(shí)際就是啟動(dòng)了一些docker服務(wù)[root@node1 harbor]# docker ps
CONTAINER ID ? IMAGE ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?COMMAND ? ? ? ? ? ? ? ? ?CREATED ? ? ? ? ? ? ?STATUS ? ? ? ? ? ? ? ? ? ? ? ?PORTS ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NAMES
be75291d7f54 ? goharbor/nginx-photon:v2.8.4 ? ? ? ? "nginx -g 'daemon of…" ? About a minute ago ? Up About a minute (healthy) ? 0.0.0.0:80->8080/tcp, :::80->8080/tcp ? nginx
8391933a9bd0 ? goharbor/harbor-jobservice:v2.8.4 ? ?"/harbor/entrypoint.…" ? About a minute ago ? Up 58 seconds (healthy) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? harbor-jobservice
d4be8400acb4 ? goharbor/harbor-core:v2.8.4 ? ? ? ? ?"/harbor/entrypoint.…" ? About a minute ago ? Up About a minute (healthy) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? harbor-core
使用Harbor
①訪問瀏覽器
②登錄
初始密碼在harbor.cfg 文件有記錄
③新建一個(gè)項(xiàng)目
上傳下載鏡像到harbor倉庫
(1)修改docker配置,添加harbor倉庫為信任地址,重啟docker
[root@node1 harbor]# cat /etc/docker/daemon.json?
{
"registry-mirrors": ["http://registry.docker-cn.com"],
"insecure-registries": ["192.168.169.133:8081"],
"insecure-registries": ["node1:8081"]
}
(2)把要上傳的鏡像打上合適的標(biāo)簽
[root@node1 harbor]# docker tag goharbor/harbor-db:v2.8.4 node1:80/test/harbor-db:v2.8.4
[root@node1 harbor]# docker image ls | grep test
node1:80/test/harbor-db ? ? ? ? v2.8.4 ? ?5b8af16d7420 ? 6 days ago ? 174MB
(3)登錄harbor倉庫
[root@node1 harbor]# docker login node1:8081
Username: admin
Password:?
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
(4)上傳鏡像
[root@node1 harbor]# docker push node1:8081/test/harbor-db:v2.8.4
The push refers to repository [node1:80/test/harbor-db]
b91c1501abe9: Pushed?
e30935897ec8: Pushed?
7600d3f327f6: Pushed?
04498149158d: Pushed?
8dd9b9af7425: Pushed?
6f34146f1977: Pushed?
98c144348806: Pushed?
22c2b4c49c70: Pushed?
b4faf8a74f36: Pushed?
627fc8f29b12: Pushed?
a074a02dfff1: Pushed?
v2.8.4: digest: sha256:f887f9197510e86e3c8a82235c1d170f7a3bc93b4823028077e2565ca27e17c3 size: 2612
(5)在harbor上驗(yàn)證上傳成功
(6)拉取harbor中的鏡像
#刪除原本鏡像
[root@node1 harbor]# docker rmi node1:8081/test/harbor-db:v2.8.4
Untagged: node1:8081/test/harbor-db:v2.8.4
Untagged: node1:8081/test/harbor-db@sha256:f887f9197510e86e3c8a82235c1d170f7a3bc93b4823028077e2565ca27e17c3#驗(yàn)證是否刪除
[root@node1 harbor]# docker image ls node1:8081/test/harbor-db:v2.8.4
REPOSITORY ? TAG ? ? ? IMAGE ID ? CREATED ? SIZE#拉取鏡像
[root@node1 harbor]# docker pull node1:8081/test/harbor-db:v2.8.4
v2.8.4: Pulling from test/harbor-db
Digest: sha256:f887f9197510e86e3c8a82235c1d170f7a3bc93b4823028077e2565ca27e17c3
Status: Downloaded newer image for node1:8081/test/harbor-db:v2.8.4
node1:80/test/harbor-db:v2.8.4#驗(yàn)證是否拉取成功
[root@node1 harbor]# docker image ls node1:8081/test/harbor-db:v2.8.4
REPOSITORY ? ? ? ? ? ? ? ?TAG ? ? ? IMAGE ID ? ? ? CREATED ? ? ?SIZE
node1:8081/test/harbor-db ? v2.8.4 ? ?5b8af16d7420 ? 6 days ago ? 174MB
控制harbor服務(wù)
在harbor安裝路徑下,使用docker-compose命令對(duì)harbor進(jìn)行控制
(1)暫停/取消暫停harbor服務(wù)
docker-compose pause
docker-compose unpause
(2)關(guān)閉/開啟harbor服務(wù)
docker-compose stop文章來源:http://www.zghlxwxcb.cn/news/detail-665669.html
docker-compose start文章來源地址http://www.zghlxwxcb.cn/news/detail-665669.html
到了這里,關(guān)于基于CentOS搭建私有倉庫harbor的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!