Harbor私有仓库搭建【超详细】
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
一.安装docker
设置镜像仓库 阿里云
wget -O /etc/yum.repos.d/docker.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker-ce 社区版
yum install docker-ce docker-ce-cli -y
配置加速器 启动docker并设置开机自启动
mkdir -p /etc/docker
rm -rf /etc/docker/daemon.json
cat >>/etc/docker/daemon.json<<eof
{
"registry-mirrors": ["https://5ke62mgb.mirror.aliyuncs.com"]
}
eof
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
查看docker状态是否启动
[root@hang ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-06-08 10:59:40 CST; 1h 58min ago
Docs: https://docs.docker.com
Main PID: 35098 (dockerd)
Tasks: 17
Memory: 248.7M
CGroup: /system.slice/docker.service
├─35098 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─38040 fuse-overlayfs -o lowerdir=/var/lib/docker/fuse-overlayfs/l/NT5ZIML7X2IWBBJ444YGNCSJ3T:/var/lib/docker/fuse-overlayfs/l/...
├─38137 fuse-overlayfs -o lowerdir=/var/lib/docker/fuse-overlayfs/l/UW7SSJWYTUUVZ5UB5AYMKD7JOV:/var/lib/docker/fuse-overlayfs/l/...
├─38231 fuse-overlayfs -o lowerdir=/var/lib/docker/fuse-overlayfs/l/F7VNQAC2AUZ6WLQ4OHHUZTJKOL:/var/lib/docker/fuse-overlayfs/l/...
├─38328 fuse-overlayfs -o lowerdir=/var/lib/docker/fuse-overlayfs/l/IU5NBHJTUNVDEECENE4L4QXRQP:/var/lib/docker/fuse-overlayfs/l/...
└─38522 fuse-overlayfs -o lowerdir=/var/lib/docker/fuse-overlayfs/l/EAPUSBZTI3KO6OMKXJILC2ZDIE:/var/lib/docker/fuse-overlayfs/l/...
二.安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
#授权
chmod 777 /usr/local/bin/docker-compose
查看docker-compose版本
[root@hang ~]# docker-compose version
docker-compose version 1.24.0, build 0aa59064
docker-py version: 3.7.2
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j 20 Nov 2018
三.修改配置文件
sed -i 's/aliyuncs.com"]/aliyuncs.com"],/g' /etc/docker/daemon.json
sed -i '2a\ "insecure-registries": ["https://hang.com"]' /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
四.安装Harbor
下载 harbor-offline-installer-v1.2.0.tgz 安装包
https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz
#解压harbor压缩包
tar -xzvf harbor-offline-installer-v1.2.0.tgz
mv harbor /usr/local/
cd /usr/local/harbor/
sed -i 's/hostname = reg.mydomain.com/hostname = hang.com/g' harbor.cfg
sed -i 's/ui_url_protocol = http/ui_url_protocol = https/g' harbor.cfg
mkdir -p /data/cert
cd /data/cert
#生成私钥
openssl genrsa -des3 -out server.key 2048
#输入密码 000000
#重新输入密码 000000
#创建证书请求
openssl req -new -key server.key -out server.csr #输入刚刚设置的密码 000000
--------
Country Name (2 letter code) [XX]:CN // 国家
State or Province Name (full name) []:BJ // 州或者省名
Locality Name (eg, city) [Default City]:BJ // 城市名称
Organization Name (eg, company) [Default Company Ltd]:zxjr // 组织名称
Organizational Unit Name (eg, section) []: // 组织单位名称(空)
Common Name (your server's hostname) []: // 你的名称或服务器主机名 这里我填hang.com
Email Address []: // 邮箱
#剩下的空格
cp server.key server.key.org
#转化成证书
openssl rsa -in server.key.org -out server.key
#输入之前设置的密码 000000
#签名
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
#授权
chmod a+x *
cd /usr/local/harbor
#启动
[root@hang harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 20.10.7
Note: docker-compose version: 1.24.0
[Step 1]: loading Harbor images ...
dd60b611baaa: Loading layer [==================================================>] 133.2MB/133.2MB
2e814f7ef645: Loading layer [==================================================>] 2.048kB/2.048kB
bc5742b580db: Loading layer [==================================================>] 2.048kB/2.048kB
5413bcdb81b0: Loading layer [==================================================>] 2.56kB/2.56kB
c4e2be066795: Loading layer [==================================================>] 3.584kB/3.584kB
a4ea62be60b0: Loading layer [==================================================>] 22.8MB/22.8MB
800a351ae5da: Loading layer [==================================================>] 22.8MB/22.8MB
Loaded image: vmware/registry:2.6.2-photon
Loaded image: photon:1.0
a39bd6a7f897: Loading layer [==================================================>] 10.95MB/10.95MB
6f79b8337a1f: Loading layer [==================================================>] 17.3MB/17.3MB
74bbd0e81dd0: Loading layer [==================================================>] 15.87kB/15.87kB
Loaded image: vmware/notary-photon:signer-0.5.0
c192a34d4ff4: Loading layer [==================================================>] 155.2MB/155.2MB
d012a9276a83: Loading layer [==================================================>] 10.75MB/10.75MB
b8befd881cb5: Loading layer [==================================================>] 10.75MB/10.75MB
Loaded image: vmware/clair:v2.0.1-photon
e0b3d6a2361d: Loading layer [==================================================>] 1.536kB/1.536kB
3a527b0785bc: Loading layer [==================================================>] 22.48MB/22.48MB
1efe51df48d0: Loading layer [==================================================>] 7.168kB/7.168kB
c20026b42fab: Loading layer [==================================================>] 5.338MB/5.338MB
615c076c8d0a: Loading layer [==================================================>] 9.728kB/9.728kB
133d7170cbc1: Loading layer [==================================================>] 2.56kB/2.56kB
8e5b68c51d96: Loading layer [==================================================>] 22.48MB/22.48MB
Loaded image: vmware/harbor-ui:v1.2.0
9463fb852970: Loading layer [==================================================>] 75.37MB/75.37MB
e6020d0bad7b: Loading layer [==================================================>] 3.584kB/3.584kB
3fbf59525988: Loading layer [==================================================>] 3.072kB/3.072kB
37bccef91571: Loading layer [==================================================>] 3.072kB/3.072kB
Loaded image: vmware/harbor-log:v1.2.0
5d6cbe0dbcf9: Loading layer [==================================================>] 129.2MB/129.2MB
435f2dfbd884: Loading layer [==================================================>] 344.6kB/344.6kB
814d7b59f0cc: Loading layer [==================================================>] 4.657MB/4.657MB
aae399245bd0: Loading layer [==================================================>] 1.536kB/1.536kB
21e2ae955f72: Loading layer [==================================================>] 33.84MB/33.84MB
a2d0f7b84059: Loading layer [==================================================>] 25.09kB/25.09kB
819fa6af55b8: Loading layer [==================================================>] 3.584kB/3.584kB
78914c99a468: Loading layer [==================================================>] 167.7MB/167.7MB
36e79c658afb: Loading layer [==================================================>] 6.144kB/6.144kB
f73503aca003: Loading layer [==================================================>] 9.216kB/9.216kB
a21b39f6da59: Loading layer [==================================================>] 1.536kB/1.536kB
d7141699e1d4: Loading layer [==================================================>] 8.704kB/8.704kB
af296516d219: Loading layer [==================================================>] 4.608kB/4.608kB
b1ea8c380e6d: Loading layer [==================================================>] 4.608kB/4.608kB
Loaded image: vmware/harbor-db:v1.2.0
7ebf4b23a7e8: Loading layer [==================================================>] 19.6MB/19.6MB
Loaded image: vmware/nginx-photon:1.11.13
bbda1562018e: Loading layer [==================================================>] 101.6MB/101.6MB
1171ab08cc04: Loading layer [==================================================>] 6.656kB/6.656kB
6df81d3a0683: Loading layer [==================================================>] 6.656kB/6.656kB
Loaded image: vmware/postgresql:9.6.4-photon
1576c9b2b2cd: Loading layer [==================================================>] 7.07MB/7.07MB
1812ceac4c95: Loading layer [==================================================>] 7.07MB/7.07MB
Loaded image: vmware/harbor-adminserver:v1.2.0
0050db551e77: Loading layer [==================================================>] 18.31MB/18.31MB
af9394226ea3: Loading layer [==================================================>] 18.31MB/18.31MB
Loaded image: vmware/harbor-jobservice:v1.2.0
4a050fccec52: Loading layer [==================================================>] 12.16MB/12.16MB
d918d73369ec: Loading layer [==================================================>] 17.3MB/17.3MB
22898836924e: Loading layer [==================================================>] 15.87kB/15.87kB
Loaded image: vmware/notary-photon:server-0.5.0
78dbfa5b7cbc: Loading layer [==================================================>] 130.9MB/130.9MB
5f70bf18a086: Loading layer [==================================================>] 1.024kB/1.024kB
8deec01122be: Loading layer [==================================================>] 344.6kB/344.6kB
574ab36807f2: Loading layer [==================================================>] 1.536kB/1.536kB
d8f2cde2eef8: Loading layer [==================================================>] 20.48kB/20.48kB
eaa3924b054e: Loading layer [==================================================>] 5.12kB/5.12kB
8aa2c772121c: Loading layer [==================================================>] 184.3MB/184.3MB
c3014bbccb0b: Loading layer [==================================================>] 8.704kB/8.704kB
978a35efaa8c: Loading layer [==================================================>] 4.608kB/4.608kB
c2385ae7d6e5: Loading layer [==================================================>] 16.6MB/16.6MB
Loaded image: vmware/harbor-notary-db:mariadb-10.1.10
[Step 2]: preparing environment ...
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.
[Step 3]: checking existing instance of Harbor ...
[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry ... done
Creating harbor-adminserver ... done
Creating harbor-db ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at https://hang.com.
For more details, please visit https://github.com/vmware/harbor .
检查服务组件运行状态
[root@hang harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh mysqld Up 3306/tcp
harbor-jobservice /harbor/harbor_jobservice Up
harbor-log /bin/sh -c crond && rm -f ... Up 127.0.0.1:1514->514/tcp
harbor-ui /harbor/harbor_ui Up
nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:4443->4443/tcp,:::4443->4443/tcp,
0.0.0.0:80->80/tcp,:::80->80/tcp
五.配置映射
在windos上找到 C:\Windows\System32\drivers\etc\hosts 这个文件
末尾添加:192.168.100.10 hub.atguigu.com #这里192.168.100.10是你主机的IP地址,可以用ip a查看
浏览器打开:https://hang.com
用户名:admin
密码:Harbor12345
打开网站后发现
点击高级 选择继续访问
成功打开Harbor界面 用户:admin 密码:Harbor12345 密码可以在/usr/local/harbor/harbor.cfg 里进行修改
六.上传镜像到harbor私有仓库
重新开启另一台centos7
关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
添加映射
cat >>/etc/hosts<<eof
192.168.100.10 hang.com
eof
修改docker配置文件
sed -i 's/aliyuncs.com"]/aliyuncs.com"],/g' /etc/docker/daemon.json
sed -i '2a\ "insecure-registries": ["https://hang.com"]' /etc/docker/daemon.json
重启
systemctl daemon-reload
systemctl restart docker
登录 Harbor 用户:admin 密码:Harbor12345
[root@master ~]# docker login https://hang.com
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-store
Login Succeeded
上传镜像,需要将镜像打标签 如图所示
打标签
docker tag nginx:latest hang.com/library/mynginx:v1
推送镜像到Harbor
[root@master ~]# docker push hang.com/library/mynginx:v1
The push refers to repository [hang.com/library/mynginx]
075508cf8f04: Pushed
5c865c78bc96: Pushed
134e19b2fac5: Pushed
83634f76e732: Pushed
766fe2c3fc08: Pushed
02c055ef67f5: Pushed
v1: digest: sha256:61191087790c31e43eb37caa10de1135b002f10c09fdda7fa8a5989db74033aa size: 1570
在harbor仓库中查看是否有这个镜像 可以看到以及推送成功
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献3条内容
所有评论(0)