第一次使用這個的時候是剛進公司處理的第一個任務的時候,發現 Harbor 就是一個用於存儲和分發 Docker 鏡像的企業級Registry 服務器。python
網上找到一個 Harbor 的架構圖:mysql
Harbor 是 VMware 公司開源的企業級 DockerRegistry 項目,項目地址爲 https://github.com/vmware/harbor。其目標是幫助用戶迅速搭建一個企業級的 Docker registry 服務。它以 Docker 公司開源的 registry 爲基礎,提供了管理UI,基於角色的訪問控制(Role Based Access Control),AD/LDAP集成、以及審計日誌(Auditlogging) 等企業用戶需求的功能,同時還原生支持中文。Harbor 的每一個組件都是以 Docker 容器的形式構建的,使用 Docker Compose 來對它進行部署。nginx
一、本身在騰訊雲買的服務器(CentOS7.3)git
二、Docker 版本:17.05.0-cegithub
三、Docker-compose:1.17.1web
四、Harbor:1.1.2sql
由於系統是 CentOS 7.3 ,內核啥的都已是 3.10,因此不用擔憂內核升級的問題,一些操做啥的在 7.x 上操做也很方便。docker
yum update //系統版本更新 vim /etc/yum.repos.d/docker.repo //添加如下內容 [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg //下面安裝 Docker 引擎 yum install docker-engine -y //安裝docker引擎,此步也可做爲更新docker版本的操做:先#systemctl stop docker 中止docker服務,再#yum install docker-engine 更新docker版本 systemctl enable docker.service systemctl start docker //啓動docker守護進程 docker info //查看docker運行狀況 docker -v //查看版本信息
修改 Docker 配置文件 /etc/default/docker 以下:shell
DOCKER_OPTS="--registry-mirror=http://aad0405c.m.daocloud.io" //換成國內的鏡像加速源,否則拉取鏡像簡直龜速,不想在吐槽了
使用 service docker restart
重啓 Docker 服務便可。數據庫
或者用官方提供的方式:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef017c13.m.daocloud.io
若是是想直接命令安裝也行,
下載指定版本的docker-compose sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose 對二進制文件賦可執行權限 chmod +x /usr/local/bin/docker-compose 測試下docker-compose是否安裝成功 docker-compose --version 出現以下 docker-compose version 1.17.1, build 6d101fb
可是,這種方法簡直龜速,幸虧還有種方法,
見這裏:https://docs.docker.com/compo...
這種須要經過 Python 的 pip 安裝
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz tar -vxf setuptools-1.4.2.tar.gz cd setuptools-1.4.2 python2.7 setup.py install //由於服務器自帶 Python 2.7 easy_install-2.7 pip
pip install docker-compose docker-compose --version //測試安裝是否成功
wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-offline-installer-v1.1.2.tgz 離線安裝包,也是龜速,把這個下載連接用迅雷下載,速度卻賊快,嘿嘿,而後再傳到服務器上去,整個過程快不少! tar -zxvf harbor-offline-installer-v1.1.2.tgz
解壓縮以後,進入目錄下會看到 harbor.cfg 文件,該文件就是 Harbor 的配置文件。
## Configuration file of Harbor # hostname設置訪問地址,可使用ip、域名,不能夠設置爲127.0.0.1或localhost hostname = 115.159.227.249 #這裏我先配置個人服務器IP地址 # 訪問協議,默認是http,也能夠設置https,若是設置https,則nginx ssl須要設置on ui_url_protocol = http # mysql數據庫root用戶默認密碼root123,實際使用時修改下 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. # 啓動Harbor後,管理員UI登陸的密碼,默認是Harbor12345 harbor_admin_password = Harbor12345 # 認證方式,這裏支持多種認證方式,如LADP、本次存儲、數據庫認證。默認是db_auth,mysql數據庫認證 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 de pending 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 # 是否開啓自注冊 self_registration = on # Token有效時間,默認30分鐘 token_expiration = 30 # 用戶建立項目權限控制,默認是everyone(全部人),也能夠設置爲adminonly(只能管理員) 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************************
啓動 harbor,修改完配置文件後,在的當前目錄執行./install.sh
,Harbor服務就會根據當期目錄下的docker-compose.yml
開始下載依賴的鏡像,檢測並按照順序依次啓動各個服務。
啓動完成後,咱們訪問剛設置的 hostname 便可,http://115.159.227.249/,默認是80端口,若是端口占用,咱們能夠去修改docker-compose.yml文件中,對應服務的端口映射。
登陸 Web Harbor , 輸入用戶名 admin,默認密碼(或已修改密碼)登陸系統。
咱們能夠看到系統各個模塊以下:
系統管理
其餘設置
注意:非系統管理員用戶登陸,只能看到有權限的項目和日誌,其餘模塊不可見。
咱們要嘗試下能不能把本身 Docker 裏面的鏡像 push 到 Harbor 的 library 裏來(默認這個 library 項目是公開的,全部人均可以有讀的權限,都不須要 docker login 進來,就能夠拉取裏面的鏡像)。
注意:
爲了後面留坑,我這裏先 在本身的 docker.service 中添加倉庫:(這是個坑,建議你先按照我說的作,否則下面可能會一直登陸不上)
vim /usr/lib/systemd/system/docker.service 裏面的這行修改成:(其實就是添加 --insecure-registry 115.159.227.249 ) ExecStart=/usr/bin/dockerd --insecure-registry 115.159.227.249
添加完了後從新啓動 docker:
systemctl daemon-reload && systemctl enable docker && systemctl start docker
啓動 docker 服務:
service docker start
登陸:(爲了測試下可否登陸成功)
admin登陸 $ docker login 115.159.227.249 Username: admin Password: Login Succeeded
打 tag 並 push
docker tag ubuntu:15.10 115.159.227.249/library/ubuntu:15.10 //給個人鏡像打個 tag docker push 115.159.227.249/library/ubuntu The push refers to a repository [115.159.227.249/library/ubuntu] 98d59071f692: Pushed af288f00b8a7: Pushed 4b955941a4d0: Pushed f121afdbbd5d: Pushed 15.10: digest: sha256:ec89c4a90f45f5e103860191890f48d8379e0504a2881ff706aef0768dc0321b size: 1150
上傳完畢後,登陸Web Harbor,選擇項目 library,就能夠看到我剛 push 的鏡像了。
同理,你也能夠測試下從 Harbor pull 鏡像到你的 Docker 中去,這裏就不繼續演示了。
轉載請註明地址爲:http://www.54tianzhisheng.cn/...