Harbor私仓搭建与使用

配置阿里云yum源、配置docker仓库

参考https://blog.youkuaiyun.com/luhost/article/details/99191469

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
 
[kubernetes]
 
name=Kubernetes
 
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
 
enabled=1
 
gpgcheck=1
 
repo_gpgcheck=1
 
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
 
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
 
EOF

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache

安装docker
yum install -y --setopt=obsoletes=0 docker-ce
运行docker --version,可以看到安装
[root@kuber-master ~]# docker --version
Docker version 19.03.1, build 74b1e89
启动Docker服务并激活开机启动:systemctl start docker & systemctl enable docker

安装python和docker-compose,查看openssl版本

[root@iZuf698fo8d8vjpdy7nlqeZ ~]# python --version
Python 2.7.5

安装pip
yum install python-pip -y
升级pip
pip install --upgrade pip
安装docker-compose
pip install docker-compose
检查更新
pip install --upgrade docker-compose
查看docker-compose版本

[root@iZuf698fo8d8vjpdy7nlqeZ ~]# docker-compose -v
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.3) or chardet (2.2.1) doesn't match a supported version!
  RequestsDependencyWarning)
docker-compose version 1.24.1, build 4667896

查看openssl版本

[root@iZuf698fo8d8vjpdy7nlqeZ ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

使用离线方式,安装harbor

wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.2.tgz
tar -zxf harbor-offline-installer-v1.8.2.tgz
mv harbor /usr/local/

[root@iZuf698fo8d8vjpdy7nlqeZ harbor]# ll
total 60
drwxr-xr-x 3 root root  4096 Aug 18 21:38 common
-rw-r--r-- 1 root root   936 Aug 18 21:27 docker.com.crt
-rw-r--r-- 1 root root   753 Aug 18 21:26 docker.com.csr
-rw-r--r-- 1 root root   887 Aug 18 21:23 docker.com.key
-rw-r--r-- 1 root root  5409 Aug 21 22:30 docker-compose.yml
-rw-r--r-- 1 root root   233 Aug 18 21:30 harbor.cfg
-rw-r--r-- 1 root root  4528 Aug 21 22:30 harbor.yml
-rwxr-xr-x 1 root root  5088 Aug 14 14:51 install.sh
-rw-r--r-- 1 root root 11347 Aug 14 14:51 LICENSE
-rwxr-xr-x 1 root root  1654 Aug 14 14:51 prepare

创建自签名证书

[root@iZuf698fo8d8vjpdy7nlqeZ ~]# openssl genrsa -out docker.com.key 1024
saGenerating RSA private key, 1024 bit long modulus
.............................++++++
.........++++++
e is 65537 (0x10001)

创建证书

[root@iZuf698fo8d8vjpdy7nlqeZ ~]# openssl req -new -key docker.com.key -out docker.com.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:****
State or Province Name (full name) []:********
Locality Name (eg, city) [Default City]:********
Organization Name (eg, company) [Default Company Ltd]:****
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:******
An optional company name []:****

星号部分相应改写

[root@iZuf698fo8d8vjpdy7nlqeZ ~]# openssl x509 -req -days 365 -in docker.com.csr -signkey docker.com.key -out docker.com.crt
Signature ok

配置Harbor的配置文件

vim /Harbor.yaml

[root@iZuf698fo8d8vjpdy7nlqeZ 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: 大网IP地址或者域名

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

# https related config
https:
#   # https port for harbor, default is 443
  port: 443
#   # The path of cert and key files for nginx
  certificate: /usr/local/harbor/docker.com.crt    #填写证书路径
  private_key: /usr/local/harbor/docker.com.key    #填写key路径

# 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: admin登录密码

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: DB密码

# The default data volume
data_volume: /data

# Harbor Storage settings by default is using /data dir on local filesystem
# Uncomment storage_service setting If you want to using external storage
# storage_service:
#   # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
#   # of registry's and chart repository's containers.  This is usually needed when the user hosts a internal storage with self signed certificate.
#   ca_bundle:

#   # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
#   # for more info about this configuration please refer https://docs.docker.com/registry/configuration/
#   filesystem:
#     maxthreads: 100
#   # set disable to true when you want to disable registry redirect
#   redirect:
#     disabled: false

# Clair configuration
clair: 
  # The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
  updaters_interval: 12

  # Config http proxy for Clair, e.g. http://my.proxy.com:3128
  # Clair doesn't need to connect to harbor internal components via http proxy.
  http_proxy:
  https_proxy:
  no_proxy: 127.0.0.1,localhost,core,registry

jobservice:
  # Maximum number of job workers in job service  
  max_job_workers: 10

chart:
  # Change the value of absolute_url to enabled can enable absolute url in chart
  absolute_url: disabled

# Log configurations
log:
  # options are debug, info, warning, error, fatal
  level: info
  # Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
  rotate_count: 50
  # Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes. 
  # If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G 
  # are all valid.
  rotate_size: 200M
  # The directory on your host that store log
  location: /var/log/harbor

#This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
_version: 1.8.0

# Uncomment external_database if using external database.
# external_database:
#   harbor:
#     host: harbor_db_host
#     port: harbor_db_port
#     db_name: harbor_db_name
#     username: harbor_db_username
#     password: harbor_db_password
#     ssl_mode: disable
#   clair:
#     host: clair_db_host
#     port: clair_db_port
#     db_name: clair_db_name
#     username: clair_db_username
#     password: clair_db_password
#     ssl_mode: disable
#   notary_signer:
#     host: notary_signer_db_host
#     port: notary_signer_db_port
#     db_name: notary_signer_db_name
#     username: notary_signer_db_username
#     password: notary_signer_db_password
#     ssl_mode: disable
#   notary_server:
#     host: notary_server_db_host
#     port: notary_server_db_port
#     db_name: notary_server_db_name
#     username: notary_server_db_username
#     password: notary_server_db_password
#     ssl_mode: disable

# Uncomment external_redis if using external Redis server
# external_redis:
#   host: redis
#   port: 6379
#   password:
#   # db_index 0 is for core, it's unchangeable
#   registry_db_index: 1
#   jobservice_db_index: 2
#   chartmuseum_db_index: 3

# Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
# uaa:
#   ca_file: /path/to/ca

中文处相应修改

构建环境

./install.sh
等待安装完成
使用大网IP访问harbor主界面
harbor
harbor

登录私仓推送镜像

配置本地docker配置文件/etc/docker/daemon.json

vim /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ],
  "registry-mirrors": ["https://dnh4r4lu.mirror.aliyuncs.com"],
  "insecure-registries": ["hub.k8s.com"] 
}

重启docker
systemctl restart docker

本地登录到私有仓库

docker login “harbor大网IP”
Username: admin
Password:

Login Succeeded

为golang 打标签并推送镜像

docker tag golang:alpine “harbor大网IP”/library/golang:alpine
docker push “harbor大网IP”/library/golang:alpine
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值