博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Harbor Docker 镜像仓库搭建
阅读量:6304 次
发布时间:2019-06-22

本文共 9946 字,大约阅读时间需要 33 分钟。

hot3.png

Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。

环境:Centos 7

1.Docker环境安装 并启动本地Docker环境

#列出版本信息yum list docker-ce --showduplicates | sort -r#安装指定版本yum install docker-ce-17.03.0.ce-1.el7.centos#安装yum install -y docker#启动systemctl start docker#验证环境就绪docker run hello-worldyum remove docker docker-common docker-selinuxyum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm

2.安装Docker-Compose

Docker-Compose下载地址:

#进入指定目录(自由指定)cd /usr/server#下载curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose#可执行赋权chmod +x /usr/local/bin/docker-compose#查看版本验证安装docker-compose --version

3.安装Harbor

Harbor下载地址:

选择需要的版本下载,这里选择1.1.2

#下载tar包wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-online-installer-v1.1.2.tgz#解压tar zxf harbor-online-installer-v1.1.2.tgz#解析后进入harbor目录cd harbor

修改harbor.cfg配置文件,完整配置文件见最后附录

为简单起见我这里只修改两个位置

a.为了让外网可以访问到 修改hostname为机器的公网IP

b.修改UI管理系统的管理员密码 harbor_admin_password = admin123

保存修改后运行当前目录下的安装脚本install.sh

./install.sh

自动安装脚本会下载几个docker镜像并启动,

注意默认web服务nginx镜像绑定80端口,nginx镜像启动失败请先释放80端口。

安装完成后访问IP或者绑定的域名就可以访问到Harbor的管理界面。如下:

4.Harbor的启停

#启动docker-compose start#停止docker-compose stop

5.配置Docker

因为docker默认使用的是https连接,而harbor默认使用http连接,所以需要修改docker配置标志insecure registry不安全仓库的主机!

harbor也可以设置为https。

vim /usr/lib/systemd/system/docker.serviceExecStart=/usr/bin/dockerd --insecure-registry=94.191.16.123#只加上--insecure-registry这个参数即可#重启docker:systemctl daemon-reloadsystemctl restart docker.service

 

6.进阶配置

6.1 修改nginx镜像的端口

nginx镜像默认监听80端口,为安全因素或避免冲突可以改为其他端口,此处我改为8820端口

6.1.1 编辑Harbor目录下的docker-compose.yml文件(完整文件见附录二),找到nginx镜像节点 修改如下:

proxy:    image: nginx:1.11.5    container_name: nginx    restart: always    volumes:      - ./common/config/nginx:/etc/nginx    ports:      - 8820:80      - 1143:443    depends_on:      - mysql      - registry      - ui      - log

6.1.2 修改common/templates/registry/config.yml文件加入8820端口:

#vim common/templates/registry/config.ymlauth:  token:    issuer: registry-token-issuer    realm: $ui_url:8820/service/token    rootcertbundle: /etc/registry/root.crt    service: token-service

6.1.3 停止harbor,重新启动并生成配置文件:

docker-compose stop./install.sh

6.1.4 修改docker启动文件,设置信任的主机与端口(第五步配置docker中修改端口80为8820):

vim /usr/lib/systemd/system/docker.service  修改如下一行ExecStart=/usr/bin/dockerd --insecure-registry=172.16.103.99:1180

6.1.5 重新启动docker并验证:

systemctl daemon-reloadsystemctl restart docker.service

登录验证

docker login 94.191.16.123:8820Username: adminPassword: Login Succeeded

 

遇到的问题:

1.安装执行install.sh报错 File "./prepare", line 60 os.makedirs(folder, mode=0600)

查原因发现在执行python 脚本 prepare时报错,prepare脚本基于python2.7 当前机器默认python环境被我改为python3.7 改回原版安装即可

mv python python3.7.2.bakmv python2.7.bak pythonpython --version

 

 

附录一:harbor.cfg配置文件

## 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 = 94.191.16.123#The protocol for accessing the UI and token/notification service, by default it is http.#It can be set to https if ssl is enabled on nginx.ui_url_protocol = http#The password for the root user of mysql db, change this before any production use.db_password = root123#Maximum number of job workers in job service  max_job_workers = 3 #Determine whether or not to generate certificate for the registry's token.#If the value is on, the prepare script creates new root cert and private key #for generating token to access the registry. If the value is off the default key/cert will be used.#This flag also controls the creation of the notary signer's cert.customize_crt = on#The path of cert and key files for nginx, they are applied only the protocol is set to httpsssl_cert = /data/cert/server.crtssl_cert_key = /data/cert/server.key#The path of secretkey storagesecretkey_path = /data#Admiral's url, comment this attribute, or set its value to NA when Harbor is standaloneadmiral_url = NA#NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES#only take effect in the first boot, the subsequent changes of these properties #should be performed on web ui#************************BEGIN INITIAL PROPERTIES************************#Email account settings for sending out password resetting emails.#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.#Identity left blank to act as username.email_identity = email_server = smtp.mydomain.comemail_server_port = 25email_username = sample_admin@mydomain.comemail_password = abcemail_from = admin 
email_ssl = false##The initial password of Harbor admin, only works for the first time when Harbor starts. #It has no effect after the first launch of Harbor.#Change the admin password from UI after launching Harbor.harbor_admin_password = admin123##By default the auth mode is db_auth, i.e. the credentials are stored in a local database.#Set it to ldap_auth if you want to verify a user's credentials against an LDAP server.auth_mode = db_auth#The url for an ldap endpoint.ldap_url = ldaps://ldap.mydomain.com#A user's DN who has the permission to search the LDAP/AD server. #If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com#the password of the ldap_searchdn#ldap_search_pwd = password#The base DN from which to look up a user in LDAP/ADldap_basedn = ou=people,dc=mydomain,dc=com#Search filter for LDAP/AD, make sure the syntax of the filter is correct.#ldap_filter = (objectClass=person)# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes depending on your LDAP/AD ldap_uid = uid #the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREEldap_scope = 3 #Timeout (in seconds) when connecting to an LDAP Server. The default value (and most reasonable) is 5 seconds.ldap_timeout = 5#Turn on or off the self-registration featureself_registration = on#The expiration time (in minute) of token created by token service, default is 30 minutestoken_expiration = 30#The flag to control what users have permission to create projects#The default value "everyone" allows everyone to creates a project. #Set to "adminonly" so that only admin user can create project.project_creation_restriction = everyone#Determine whether the job service should verify the ssl cert when it connects to a remote registry.#Set this flag to off when the remote registry uses a self-signed or untrusted certificate.verify_remote_cert = on#************************END INITIAL PROPERTIES************************#############

 

附录二:docker-compose.yml

version: '2'services:  log:    image: vmware/harbor-log:v1.1.2    container_name: harbor-log     restart: always    volumes:      - /var/log/harbor/:/var/log/docker/:z    ports:      - 127.0.0.1:1514:514    networks:      - harbor  registry:    image: vmware/registry:2.6.1-photon    container_name: registry    restart: always    volumes:      - /data/registry:/storage:z      - ./common/config/registry/:/etc/registry/:z    networks:      - harbor    environment:      - GODEBUG=netdns=cgo    command:      ["serve", "/etc/registry/config.yml"]    depends_on:      - log    logging:      driver: "syslog"      options:          syslog-address: "tcp://127.0.0.1:1514"        tag: "registry"  mysql:    image: vmware/harbor-db:v1.1.2    container_name: harbor-db    restart: always    volumes:      - /data/database:/var/lib/mysql:z    networks:      - harbor    env_file:      - ./common/config/db/env    depends_on:      - log    logging:      driver: "syslog"      options:          syslog-address: "tcp://127.0.0.1:1514"        tag: "mysql"  adminserver:    image: vmware/harbor-adminserver:v1.1.2    container_name: harbor-adminserver    env_file:      - ./common/config/adminserver/env    restart: always    volumes:      - /data/config/:/etc/adminserver/config/:z      - /data/secretkey:/etc/adminserver/key:z      - /data/:/data/:z    networks:      - harbor    depends_on:      - log    logging:      driver: "syslog"      options:          syslog-address: "tcp://127.0.0.1:1514"        tag: "adminserver"  ui:    image: vmware/harbor-ui:v1.1.2    container_name: harbor-ui    env_file:      - ./common/config/ui/env    restart: always    volumes:      - ./common/config/ui/app.conf:/etc/ui/app.conf:z      - ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z      - /data/secretkey:/etc/ui/key:z      - /data/ca_download/:/etc/ui/ca/:z    networks:      - harbor    depends_on:      - log      - adminserver      - registry    logging:      driver: "syslog"      options:          syslog-address: "tcp://127.0.0.1:1514"        tag: "ui"  jobservice:    image: vmware/harbor-jobservice:v1.1.2    container_name: harbor-jobservice    env_file:      - ./common/config/jobservice/env    restart: always    volumes:      - /data/job_logs:/var/log/jobs:z      - ./common/config/jobservice/app.conf:/etc/jobservice/app.conf:z      - /data/secretkey:/etc/jobservice/key:z    networks:      - harbor    depends_on:      - ui      - adminserver    logging:      driver: "syslog"      options:          syslog-address: "tcp://127.0.0.1:1514"        tag: "jobservice"  proxy:    image: vmware/nginx:1.11.5-patched    container_name: nginx    restart: always    volumes:      - ./common/config/nginx:/etc/nginx:z    networks:      - harbor    ports:      - 80:80      - 443:443      - 4443:4443    depends_on:      - mysql      - registry      - ui      - log    logging:      driver: "syslog"      options:          syslog-address: "tcp://127.0.0.1:1514"        tag: "proxy"networks:  harbor:    external: false

 

转载于:https://my.oschina.net/mrpei123/blog/2989929

你可能感兴趣的文章
使用OVS
查看>>
键盘回收的几种方法
查看>>
Python(条件判断和循环)
查看>>
day4 linux安装python
查看>>
LeetCode Container With Most Water (Two Pointers)
查看>>
vue (v-if show 问题)
查看>>
https基础
查看>>
css3 canvas之刮刮卡效果
查看>>
并查集模板
查看>>
RESTful Mongodb
查看>>
BZOJ3237:[AHOI2013]连通图(线段树分治,并查集)
查看>>
如何提高Ajax性能
查看>>
Android--自定义加载框
查看>>
LINUX下 lamp安装及配置
查看>>
BZOJ3105 [cqoi2013]新Nim游戏
查看>>
困惑的前置操作与后置操作
查看>>
SDNU 1269.整数序列(水题)
查看>>
BZOJ 2118 Dijkstra
查看>>
Go语言基础之结构体
查看>>
SpringCloud:Eureka Client项目搭建(Gradle项目)
查看>>