Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,经过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。python
环境:Centos 7mysql
#列出版本信息 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-world yum remove docker docker-common docker-selinux yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
Docker-Compose下载地址:https://github.com/docker/compose/releases/linux
#进入指定目录(自由指定) 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
Harbor下载地址:https://github.com/vmware/harbor/releasesnginx
选择须要的版本下载,这里选择1.1.2git
#下载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配置文件,完整配置文件见最后附录github
为简单起见我这里只修改两个位置web
a.为了让外网能够访问到 修改hostname为机器的公网IPsql
b.修改UI管理系统的管理员密码 harbor_admin_password = admin123docker
保存修改后运行当前目录下的安装脚本install.shvim
./install.sh
自动安装脚本会下载几个docker镜像并启动,
注意默认web服务nginx镜像绑定80端口,nginx镜像启动失败请先释放80端口。
安装完成后访问IP或者绑定的域名就能够访问到Harbor的管理界面。以下:
#启动 docker-compose start #中止 docker-compose stop
由于docker默认使用的是https链接,而harbor默认使用http链接,因此须要修改docker配置标志insecure registry不安全仓库的主机!
harbor也能够设置为https。
vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd --insecure-registry=94.191.16.123 #只加上--insecure-registry这个参数便可 #重启docker: systemctl daemon-reload systemctl restart docker.service
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.yml auth: 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-reload systemctl restart docker.service
登陆验证
docker login 94.191.16.123:8820 Username: admin Password: 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.bak mv python2.7.bak python python --version
## 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 https ssl_cert = /data/cert/server.crt ssl_cert_key = /data/cert/server.key #The path of secretkey storage secretkey_path = /data #Admiral's url, comment this attribute, or set its value to NA when Harbor is standalone admiral_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.com email_server_port = 25 email_username = sample_admin@mydomain.com email_password = abc email_from = admin <sample_admin@mydomain.com> 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/AD ldap_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_SUBTREE ldap_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 feature self_registration = on #The expiration time (in minute) of token created by token service, default is 30 minutes token_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************************ #############
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