harbor/docs/installation_guide.md
2019-10-21 19:27:28 +02:00

27 KiB
Raw Blame History

Installation and Configuration Guide

There are two possibilities when installing Harbor.

  • Online installer: The online installer downloads the Harbor images from Docker hub. For this reason, the installer is very small in size.

  • Offline installer: Use the offline installer if the host to which are are deploying Harbor does not have a connection to the Internet. The offline installer contains pre-built images so it is larger than the online installer.

You download the installers from the official release page.

This guide describes how to install and configure Harbor by using either the online or offline installer. The installation processes are almost the same.

If you are upgrading from a previous version of Harbor, you might need to update the configuration file and migrate your data to fit the database schema of the later version. For information about upgrading, see the Harbor Upgrade and Migration Guide.

In addition, the Harbor community created instructions describing how to deploy Harbor on Kubernetes. If you want to deploy Harbor to Kubernetes, see Harbor on Kubernetes.

Harbor Components

The table below lists the components that are deployed when you deploy Harbor.

Component Version
Postgresql 9.6.10-1.ph2
Redis 4.0.10-1.ph2
Clair 2.0.8
Beego 1.9.0
Chartmuseum 0.9.0
Docker/distribution 2.7.1
Docker/notary 0.6.1
Helm 2.9.1
Swagger-ui 3.22.1

Deployment Prerequisites for the Target Host

Harbor is deployed as several Docker containers. You can therefore deploy it on any Linux distribution that supports Docker. The target host requires Docker, and Docker Compose to be installed.

Hardware

The following table lists the minimum and recommended hardware configurations for deploying Harbor.

Resource Minimum Recommended
CPU 2 CPU 4 CPU
Mem 4 GB 8 GB
Disk 40 GB 160 GB

Software

The following table lists the software versions that must be installed on the target host.

Software Version Description
Docker engine version 17.06.0-ce+ or higher For installation instructions, see docker engine doc
Docker Compose version 1.18.0 or higher For installation instructions, see docker compose doc
Openssl latest is preferred Used to generate certificate and keys for Harbor

Network ports

Harbor requires that the following ports be open on the target host.

Port Protocol Description
443 HTTPS Harbor portal and core API accept HTTPS requests on this port. You can change this port in the configuration file.
4443 HTTPS Connections to the Docker Content Trust service for Harbor. Only required if Notary is enabled. You can change this port in the configuration file.
80 HTTP Harbor portal and core API accept HTTP requests on this port. You can change this port in the configuration file.

Installation Procedure

The installation procedure involves the following steps:

  1. Download the installer.
  2. Configure the harbor.yml file.
  3. Run the install.sh script with the appropriate options to install and start Harbor.

Download the Installer

  1. Go to the Harbor releases page.
  2. Select either the online or offline installer for the version you want to install.
  3. Use tar to extract the installer package:
  • Online installer:
    bash $ tar xvf harbor-online-installer-version.tgz
  • Offline installer:
    bash $ tar xvf harbor-offline-installer-version.tgz

Configure Harbor

You set system level parameters for Harbor in the harbor.yml file that is contained in the installer package. These parameters take effect when you run the install.sh script to install or reconfigure Harbor.

After the initial deployment and after you have started Harbor, you perform additional configuration in the Harbor Web Portal.

Required Parameters

The table below lists the parameters that must be set when you deploy Harbor. At the very least, you must update the hostname parameter.

IMPORTANT: Harbor does not ship with any certificates, and by default uses HTTP to serve registry requests. This is acceptable only in air-gapped test or development environments. In production environments, always use HTTPS. If you enable Content Trust with Notary, you must use HTTPS.

You can use certificates that are signed by a trusted third-party CA, or you can use self-signed certificates. For information about how to create a CA, and how to use a CA to sign a server certificate and a client certificate, see Configuring Harbor with HTTPS Access.

Required Parameters for Harbor Deployment
Parameter Sub-parameters Description and Additional Parameters
hostname None Specify the IP address or the fully qualified domain name (FQDN) of the target host on which to deploy Harbor. This is the address at which you access the Harbor Portal and the registry service. For example, 192.168.1.10 or reg.yourdomain.com. The registry service must be accessible to external clients, so do not specify localhost, 127.0.0.1, or 0.0.0.0 as the hostname.
https  

Use HTTPS to access the Harbor Portal and the token/notification service.

  port The port number for HTTPS. The default is 443.
  certificate The path to the SSL certificate.
  private_key The path to the SSL key.
harbor_admin_password None Set an initial password for the Harbor administrator. This password is only used on the first time that Harbor starts. On subsequent logins, this setting is ignored and the administrator's password is set in the Harbor Portal. The default username and password are `admin` and `Harbor12345`.
database   Use a local PostgreSQL database. You can optionally configure an external database, in which case disable this option.
  password Set the root password for the local database. You must change this password for production deployments.
  max_idle_conns The maximum number of connections in the idle connection pool. If set to <=0 no idle connections are retained. The default value is 50. If it is not configured the value is 2.
  max_open_conns The maximum number of open connections to the database. If <= 0 there is no limit on the number of open connections. The default value is 100 for the max connections to the Harbor database. If it is not configured the value is 0.
data_volume None The location on the target host in which to store Harbor's data. You can optionally configure external storage, in which case disable this option and enable `storage_service`.
jobservice   Configure the replication job service.
  max_job_workers The maximum number of replication workers in the job service. For each image replication job, a worker synchronizes all tags of a repository to the remote destination. Increasing this number allows more concurrent replication jobs in the system. However, since each worker consumes a certain amount of network/CPU/IO resources, set the value of this attribute based on the hardware resource of the host.
log   Configure logging.
  level Set the logging level to debug, info, warning, error, or fatal.
  local Optionally disable this option to use external_endpoint to send logs to Syslog. If you use local logging, set the following parameters:
  • rotate_count: Log files are rotated rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
  • rotate_size: Log files are rotated only if they grow bigger than rotate_size bytes. Use k for kilobytes, M for megabytes, and G for gigabytes. 100, 100k, 100M and 100G are all valid values.
  • location: Set the directory in which to store the logs.
  external_endpoint Enable this option to forward logs to a syslog server.
  • protocol: Transport protocol for the syslog server. Default is TCP.
  • host: The URL of the syslog server.
  • port: The port on which the syslog server listens

Optional parameters

Optional Parameters for Harbor
Parameter Sub-Parameters Description and Additional Parameters
http   Do not use HTTP in production environments. Using HTTP is acceptable only in air-gapped test or development environments that do not have a connection to the external internet. Using HTTP in environments that are not air-gapped exposes you to man-in-the-middle attacks.
  port Port number for HTTP
external_url None Enable it if use external proxy, and when it enabled the hostname will no longer used
clair   Clair related configs
  updaters_interval The interval of clair updaters, the unit is hour, set to 0 to disable the updaters
  http_proxy Config http proxy for Clair, e.g. http://my.proxy.com:3128.
  https_proxy Config https proxy for Clair, e.g. http://my.proxy.com:3128.
  no_proxy Config no proxy for Clair, e.g. 127.0.0.1,localhost,core,registry.
chart   chart related configs
  absolute_url if set to enabled chart will use absolute url, otherwise set it to disabled, chart will use relative url.
external_database   external database configs, Currently only support POSTGRES.
  harbor

harbors core database configs

  • host: hostname for harbor core database
  • port: port of harbors core database
  • db_name: database name of harbor core database
  • username: username to connect harbor core database
  • password: password to harbor core database
  • ssl_mode: is enable ssl mode
  • max_idle_conns: The maximum number of connections in the idle connection pool. If <=0 no idle connections are retained. The default value is 2.
  • max_open_conns: The maximum number of open connections to the database. If <= 0 there is no limit on the number of open connections. The default value is 0.
  clair clairs database configs
  • host: hostname for clair database
  • port: port of clair database
  • db_name: database name of clair database
  • username: username to connect clair database
  • password: password to clair database
  • ssl_mode: is enable ssl mode
  notary_signer notarys signer database configs
  • host: hostname for notary signer database
  • port: port of notary signer database
  • db_name: database name of notary signer database
  • username: username to connect notary signer database
  • password: password to notary signer database
  • ssl_mode: is enable ssl mode
  notary_server
  • host: hostname for notary server database
  • port: port of notary server database
  • db_name: database name of notary server database
  • username: username to connect notary server database
  • password: password to notary server database
  • ssl_mode: is enable ssl mode
external_redis   configs for use the external redis
  host host for external redis
  port port for external redis
  password password to connect external host
  registry_db_index db index for registry use
  jobservice_db_index db index for jobservice
  chartmuseum_db_index db index for chartmuseum
storage_service   By default, Harbor stores images and chart on your local filesystem. In a production environment, you may consider use other storage backend instead of the local filesystem, like S3, OpenStack Swift, Ceph, etc. These parameters are configurations for registry.
  ca_bundle The path to the custom root ca certificate, which will be injected into the trust store of registry's and chart repository's containers. This is usually needed when the user hosts a internal storage with self signed certificate.
  provider_name Storage configs for registry, default is filesystem. for more info about this configuration please refer https://docs.docker.com/registry/configuration/
  redirect disable: set disable to true when you want to disable registry redirect

Configuring storage backend (optional)

For example, if you use Openstack Swift as your storage backend, the parameters may look like this:

storage_service:
  ca_bundle:
  swift:
    username: admin
    password: ADMIN_PASS
    authurl: http://keystone_addr:35357/v3/auth
    tenant: admin
    domain: default
    region: regionOne
    container: docker_images"
  redirect:
    disable: false

NOTE: For detailed information on storage backend of a registry, refer to Registry Configuration Reference .

Finishing installation and starting Harbor

Once harbor.yml and storage backend (optional) are configured, install and start Harbor using the install.sh script. Note that it may take some time for the online installer to download Harbor images from Docker hub.

Default installation (without Notary/Clair)

Harbor has integrated with Notary and Clair (for vulnerability scanning). However, the default installation does not include Notary or Clair service.

    $ sudo ./install.sh

If everything worked properly, you should be able to open a browser to visit the admin portal at http://reg.yourdomain.com (change reg.yourdomain.com to the hostname configured in your harbor.yml). Note that the default administrator username/password are admin/Harbor12345.

Log in to the admin portal and create a new project, e.g. myproject. You can then use docker commands to login and push images (By default, the registry server listens on port 80):

$ docker login reg.yourdomain.com
$ docker push reg.yourdomain.com/myproject/myrepo:mytag

IMPORTANT: The default installation of Harbor uses HTTP - as such, you will need to add the option --insecure-registry to your client's Docker daemon and restart the Docker service.

Installation with Notary

To install Harbor with Notary service, add a parameter when you run install.sh:

    $ sudo ./install.sh --with-notary

Note: For installation with Notary the parameter ui_url_protocol must be set to "https". For configuring HTTPS please refer to the following sections.

More information about Notary and Docker Content Trust, please refer to Docker's documentation.

Installation with Clair

To install Harbor with Clair service, add a parameter when you run install.sh:

    $ sudo ./install.sh --with-clair

For more information about Clair, please refer to Clair's documentation: https://coreos.com/clair/docs/2.0.1/

Installation with chart repository service

To install Harbor with chart repository service, add a parameter when you run install.sh:

    $ sudo ./install.sh --with-chartmuseum

Note: If you want to install Notary, Clair and chart repository service, you must specify all the parameters in the same command:

    $ sudo ./install.sh --with-notary --with-clair --with-chartmuseum

For information on how to use Harbor, please refer to User Guide of Harbor .

Configuring Harbor with HTTPS access

Harbor does not ship with any certificates, and, by default, uses HTTP to serve requests. While this makes it relatively simple to set up and run - especially for a development or testing environment - it is not recommended for a production environment. To enable HTTPS, please refer to Configuring Harbor with HTTPS Access.

Managing Harbor's lifecycle

You can use docker-compose to manage the lifecycle of Harbor. Some useful commands are listed as follows (must run in the same directory as docker-compose.yml).

Stopping Harbor:

$ sudo docker-compose stop
Stopping nginx              ... done
Stopping harbor-portal      ... done
Stopping harbor-jobservice  ... done
Stopping harbor-core        ... done
Stopping registry           ... done
Stopping redis              ... done
Stopping registryctl        ... done
Stopping harbor-db          ... done
Stopping harbor-log         ... done

Restarting Harbor after stopping:

$ sudo docker-compose start
Starting log         ... done
Starting registry    ... done
Starting registryctl ... done
Starting postgresql  ... done
Starting core        ... done
Starting portal      ... done
Starting redis       ... done
Starting jobservice  ... done
Starting proxy       ... done

To change Harbor's configuration, first stop existing Harbor instance and update harbor.yml. Then run prepare script to populate the configuration. Finally re-create and start Harbor's instance:

$ sudo docker-compose down -v
$ vim harbor.yml
$ sudo prepare
$ sudo docker-compose up -d

Removing Harbor's containers while keeping the image data and Harbor's database files on the file system:

$ sudo docker-compose down -v

Removing Harbor's database and image data (for a clean re-installation):

$ rm -r /data/database
$ rm -r /data/registry

Managing lifecycle of Harbor when it's installed with Notary, Clair and chart repository service

If you want to install Notary, Clair and chart repository service together, you should include all the components in the prepare commands:

$ sudo docker-compose down -v
$ vim harbor.yml
$ sudo prepare --with-notary --with-clair --with-chartmuseum
$ sudo docker-compose up -d

Please check the Docker Compose command-line reference for more on docker-compose.

Persistent data and log files

By default, registry data is persisted in the host's /data/ directory. This data remains unchanged even when Harbor's containers are removed and/or recreated, you can edit the data_volume in harbor.yml file to change this directory.

In addition, Harbor uses rsyslog to collect the logs of each container. By default, these log files are stored in the directory /var/log/harbor/ on the target host for troubleshooting, also you can change the log directory in harbor.yml.

Configuring Harbor listening on a customized port

By default, Harbor listens on port 80(HTTP) and 443(HTTPS, if configured) for both admin portal and docker commands, these default ports can configured in harbor.yml

Configuring Harbor using the external database

Currently, only PostgreSQL database is supported by Harbor. To user an external database, just uncomment the external_database section in harbor.yml and fill the necessary information. Four databases are needed to be create first by users for Harbor core, Clair, Notary server and Notary signer. And the tables will be generated automatically when Harbor starting up.

Manage user settings

User settings are handled separately system settings. All user settings are configured in the web console or by HTTP requests at the command line. For information about using HTTP requests to configure user settings, see Configure User Settings at the Command Line to config user settings.

Performance tuning

By default, Harbor limits the CPU usage of Clair container to 150000 and avoids its using up all the CPU resources. This is defined in the docker-compose.clair.yml file. You can modify it based on your hardware configuration.

Troubleshooting

  1. When Harbor does not work properly, run the below commands to find out if all containers of Harbor are in UP status:
    $ sudo docker-compose ps
        Name                     Command               State                    Ports
  -----------------------------------------------------------------------------------------------------------------------------
  harbor-core         /harbor/start.sh                 Up
  harbor-db           /entrypoint.sh postgres          Up      5432/tcp
  harbor-jobservice   /harbor/start.sh                 Up
  harbor-log          /bin/sh -c /usr/local/bin/ ...   Up      127.0.0.1:1514->10514/tcp
  harbor-portal       nginx -g daemon off;             Up      80/tcp
  nginx               nginx -g daemon off;             Up      0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp
  redis               docker-entrypoint.sh redis ...   Up      6379/tcp
  registry            /entrypoint.sh /etc/regist ...   Up      5000/tcp
  registryctl         /harbor/start.sh                 Up

If a container is not in UP state, check the log file of that container in directory /var/log/harbor. For example, if the container harbor-core is not running, you should look at the log file core.log.

2.When setting up Harbor behind an nginx proxy or elastic load balancing, look for the line below, in common/config/nginx/nginx.conf and remove it from the sections if the proxy already has similar settings: location /, location /v2/ and location /service/.

proxy_set_header X-Forwarded-Proto $scheme;

and re-deploy Harbor refer to the previous section "Managing Harbor's lifecycle".