栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

三、安装Harbor与镜像上传存储

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

三、安装Harbor与镜像上传存储

可参考博客:https://blog.csdn.net/moyuanbomo/article/details/123378825

1、下载安装包安装 安装方式一(在线):
wget https://github.com/goharbor/harbor/releases/download/v2.3.1/harbor-offline-installer-v2.3.1.tgz
推荐:安装方式二(离线)包含docker-compose:

链接:https://pan.baidu.com/s/16BaqfQsPPgpgP5BmOKAI0A
提取码:5z1b

2 、前置条件 2.1 配置docker:

多加上:“insecure-registries”: [“47.112.155.50:8081”] 让docker可以访问

[root@node2 harbor]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "insecure-registries": ["47.112.155.50:8081"]
}
2.2 配置:docker-compose
[root@node2 ~]# chmod +x docker-compose-linux-x86_64 
[root@node2 ~]# mv docker-compose-linux-x86_64 /usr/local/sbin/docker-compose
2.3 解压:harbor
[root@zabbix 14:59:20/data/recycle]# tar zxf harbor-offline-installer-v2.4.1.tgz -C ./

2.3 配置harbor配置文件(只配置有中文注释的地方就行)
[root@node2 ~]# cd harbor/
[root@node2 harbor]# ls
common.sh  data  harbor.v2.4.1.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@node2 harbor]# vi harbor.yml  
[root@node2 ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/local/sbin/docker-compose -f /root/harbor/docker-compose.yml up -d
[root@node2 ~]# ^C
[root@node2 ~]# cd harbor/
[root@node2 harbor]# cat harbor.yml
# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
# 配置一下访问地址
hostname: 47.112.155.50

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  # 配置一下访问端口
  port: 8081

# https related config
#https:
  # https port for harbor, default is 443
  # 注释掉就行
 # port: 443
  # The path of cert and key files for nginx
  #certificate: /your/certificate/path
  #private_key: /your/private/key/path

# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
#   # set enabled to true means internal tls is enabled
#   enabled: true
#   # put your cert and key files on dir
#   dir: /etc/harbor/tls/internal

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
# 配置登录密码
harbor_admin_password: 123456

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: root123
  # The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
  max_idle_conns: 100
  # The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
  # Note: the default number of connections is 1024 for postgres of harbor.
  max_open_conns: 900

# The default data volume
#数据挂在目录,再外面创建一下这个文件夹
data_volume: /root/harbor/data
[root@node2 harbor]# mkdir -p /root/harbor/data
2.4 重启docker
[root@zabbix 15:00:50/data/software/harbor]# systemctl daemon-reload && systemctl restart docker
2.5 安装harbor
[root@node2 harbor]# ./install.sh 

[Step 0]: checking if docker is installed ...

Note: docker version: 20.10.16

[Step 1]: checking docker-compose is installed ...

Note: docker-compose version: 2.3.2
.....日志忽略.........

[Step 5]: starting Harbor ...
[+] Running 10/10
 ⠿ Network harbor_harbor        Created                                                                                                                                                                  0.1s
 ⠿ Container harbor-log         Started                                                                                                                                                                  0.8s
 ⠿ Container registry           Started                                                                                                                                                                  1.9s
 ⠿ Container harbor-db          Started                                                                                                                                                                  1.9s
 ⠿ Container harbor-portal      Started                                                                                                                                                                  1.7s
 ⠿ Container registryctl        Started                                                                                                                                                                  2.2s
 ⠿ Container redis              Started                                                                                                                                                                  2.2s
 ⠿ Container harbor-core        Started                                                                                                                                                                  2.9s
 ⠿ Container harbor-jobservice  Started                                                                                                                                                                  4.0s
 ⠿ Container nginx              Started                                                                                                                                                                  4.4s
✔ ----Harbor has been installed and started successfully.----
#到这里便是成功了
2.6 设置开机自启动并给权限

加这行代码在底部:/usr/local/sbin/docker-compose -f /root/harbor/docker-compose.yml up -d

[root@node2 harbor]# vim /etc/rc.local 
  [root@node2 ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/local/sbin/docker-compose -f /root/harbor/docker-compose.yml up -d 
## 赋予执行权限
[root@node2 harbor]# chmod +x /etc/rc.local /etc/rc.d/rc.local
2.7查看
[root@node2 harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                   PORTS                                                                                      NAMES
2ecb64bae488   goharbor/harbor-jobservice:v2.4.1    "/harbor/entrypoint.…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              harbor-jobservice
d0ef9b714365   goharbor/nginx-photon:v2.4.1         "nginx -g 'daemon of…"   2 minutes ago   Up 2 minutes (healthy)   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp                                                  nginx
31025f06fbf5   goharbor/harbor-core:v2.4.1          "/harbor/entrypoint.…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              harbor-core
a8f646f64a19   goharbor/harbor-portal:v2.4.1        "nginx -g 'daemon of…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              harbor-portal
5c9d620af9b7   goharbor/redis-photon:v2.4.1         "redis-server /etc/r…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              redis
09f5556849ee   goharbor/harbor-registryctl:v2.4.1   "/home/harbor/start.…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              registryctl
16ab2c8592dd   goharbor/registry-photon:v2.4.1      "/home/harbor/entryp…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              registry
5c4d3dd12897   goharbor/harbor-db:v2.4.1            "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes (healthy)                                                                                              harbor-db
27dab75f6f96   goharbor/harbor-log:v2.4.1           "/bin/sh -c /usr/loc…"   2 minutes ago   Up 2 minutes (healthy)   127.0.0.1:1514->10514/tcp                                                                  harbor-log
de4bc6ff7d5a   jenkinsci/blueocean                  "/sbin/tini -- /usr/…"   2 days ago      Up 11 minutes            0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp   dreamy_chaum

就此步可以登录了。地址为ip:如:
端口 :http://47.112.155.50:8081/
登录账号:admin
密码文件配置的里的:123456
界面展示如图:

3.使用,比较简单,直接贴代码:
    ## 查看已经好了的镜像:
    [root@node2 harbor]# docker image ls
		REPOSITORY         TAG               IMAGE ID       CREATED         SIZE
		devops-demo-dev    latest            10507ade0641   33 hours ago    560MB
    ## 登录认证
    [root@node2 harbor]# docker login -u admin -p 123456 47.112.155.50:8081
    ## 打上标签  ip:端口/项目名/仓库:版本==>47.112.155.50:8081/devops-demo/devops:v1
    [root@node2 harbor]# docker tag devops-demo-dev 47.112.155.50:8081/devops-demo/devops:v1
    ## 推镜像到harbor仓库
    [root@node2 harbor]# docker push 47.112.155.50:8081/devops-demo/devops:v1
    ## 从harbor仓库拉镜像到本地
    [root@node2 harbor]# docker pull 47.112.155.50:8081/devops-demo/devops:v1

注:这里未配置https使用,待补

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/939468.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号