# Harbor 简单部署(For Ubuntu_20.04) ###### tags: `Harbor `Ubuntu_20.04` `docker` ## 官方最小配置 ``` 2个cpu 4g内存 40g硬盘,因为是存储镜像的所以推荐硬盘大点 ``` --- ## 安装前配置 在真正安装之前,我们还要安装下面这几个组件: ``` docker docker-compose python openssl ``` --- ## 安装docker 更新apt源,并添加https支持 > $ sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release --- ## 使用utc源添加GPG Key > $ `curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add ` --- ## 添加Docker-ce稳定版源地址 > $ `sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"` --- ## 安装 [docker-ce](https://docs.docker.com/engine/install/ubuntu/) 目前最新版本是 20.10.5 (2021-03-02) 要安裝特定版本的Docker Engine,請在存儲庫中列出可用版本,然後選擇並安裝: #### a. 列出您的倉庫中可用的版本: > $ apt-cache madison docker-ce ``` docker-ce | 5:20.10.5~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.5~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.4~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.4~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages ``` </br> #### b. 使用第二列中的版本字符串安裝特定版本,例如 `5:20.10.5~3-0~ubuntu-focal` > $ sudo apt-get update > $ `sudo apt install -y docker-ce=5:20.10.5~3-0~ubuntu-focal` ``` ... Configuration file '/etc/forticlient/config.db' ==> File on system created by you or by a script. ==> File also in package provided by package maintainer. What would you like to do about it ? Your options are: Y or I : install the package maintainer's version N or O : keep your currently-installed version D : show the differences between the versions Z : start a shell to examine the situation The default action is to keep your current version. *** config.db (Y/I/N/O/D/Z) [default=N] ? ___ ... ``` ## 安装 [docker-compose](https://docs.docker.com/compose/install/) 运行此命令下载docker compose的当前稳定版本: > $ `sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose` ``` % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 633 0 633 0 0 1889 0 --:--:-- --:--:-- --:--:-- 1883 100 11.6M 100 11.6M 0 0 3483k 0 0:00:03 0:00:03 --:--:-- 4788k ``` > $ docker-compose --version ``` docker-compose version 1.28.5, build c4eb3a1f ``` 对二进制文件应用可执行权限 > $ sudo chmod +x /usr/local/bin/docker-compose > $ dpkg -l |grep openssl ``` ii libxmlsec1-openssl:amd64 1.2.28-2 amd64 Openssl engine for the XML security library ii openssl 1.1.1f-1ubuntu2.2 amd64 Secure Sockets Layer toolkit - cryptographic utility ii perl-openssl-defaults:amd64 4 amd64 version compatibility baseline for Perl OpenSSL packages ii python3-openssl 19.0.0-1build1 all Python 3 wrapper around the OpenSSL library ``` --- ## 下载 [Harbor离线包](https://github.com/vmware/harbor/releases) 安装有两种方式,一种是off-line ,一种是on-line,即离线和在线安装,离线安装需要下载的安装包较大,在线安装下载的安装包很小,课题根据自己的情况选择,我选择的是1.8.1版本 - 下载在线安装包 > `$ wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-online-installer-v1.8.1.tgz` ``` --2021-03-16 16:14:09-- https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-online-installer-v1.8.1.tgz Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.160.112, 172.217.160.80, 2404:6800:4008:801::2010, ... Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.160.112|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 7953 (7.8K) [application/x-tar] Saving to: ‘harbor-online-installer-v1.8.1.tgz’ harbor-online-installer-v1.8.1.t 100%[=========================================================>] 7.77K --.-KB/s in 0s 2021-03-16 16:14:09 (133 MB/s) - ‘harbor-online-installer-v1.8.1.tgz’ saved [7953/7953] ``` --- ## 安装 Harbor 解压安装包 > $ sudo tar zxvf harbor-online-installer-v1.8.1.tgz -C /usr/src/ ``` harbor/prepare harbor/LICENSE harbor/install.sh harbor/harbor.yml ``` - 编辑配置文件 > $ sudo vim harbor.yml - 修改hostname为本机ip地址 > hostname: 192.168.1.195 > $ sudo su ``` root@ub20042s:/usr/src/harbor# ``` > `# cat harbor.yml |grep -v "^#"|grep -v " #"|grep -v "^$"` ``` hostname: 192.168.1.195 http: port: 80 harbor_admin_password: Harbor12345 database: password: root123 data_volume: /data clair: updaters_interval: 12 http_proxy: https_proxy: no_proxy: 127.0.0.1,localhost,core,registry jobservice: max_job_workers: 10 chart: absolute_url: disabled log: level: info rotate_count: 50 rotate_size: 200M location: /var/log/harbor _version: 1.8.0 ``` > `# ./install.sh` ``` [Step 0]: checking installation environment ... Note: docker version: 20.10.5 Note: docker-compose version: 1.28.5 [Step 1]: preparing environment ... prepare base dir is set to /usr/src/harbor Unable to find image 'goharbor/prepare:v1.8.1' locally v1.8.1: Pulling from goharbor/prepare .. Creating harbor-log ... done Creating registry ... done Creating redis ... done Creating registryctl ... done Creating harbor-db ... done Creating harbor-core ... done Creating harbor-jobservice ... done Creating harbor-portal ... done Creating nginx ... done ✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at http://192.168.1.195. For more details, please visit https://github.com/goharbor/harbor . ``` ***之后如果想修改某一个配置比如要把域名修改一下,可以先修改上面 `harbor.cfg` 这个文件,之后重新执行 `install.sh` 这个文件就可以了。*** --- ## 访问页面 > http://192.168.1.195 ``` 使用默认的账号:admin 密码:Harbor12345 ``` ![](https://i.imgur.com/bWGjNIS.png) 登录验证 登录成功之后,效果如下: ![](https://i.imgur.com/VBidTZO.png) --- ## 测试推送镜像 登录到另外一台服务器,确保docker已经安装好了。 本地配置仓库地址 由于默认的harbor,已经创建了一个公开项目 libary。 > $ vim /etc/docker/daemon.json 内容如下: ``` {"insecure-registries": ["192.168.1.195"]} ``` 接着重启服务 > $ systemctl restart docker --- ## 基本步驟 - ### 在 root 環境下執行: ``` # 登入: # docker login 192.168.1.195 ## docker login [ip_address] # 查看光碟片: # docker images # 推送光碟片: # docker pull alpine ## docker pull [images]# docker tag centos 192.168.1.195/[projet_name]/[images] # 在项目中标记镜像: ## docker tag alpine 192.168.1.195/library/alpine ## docker tag [images] [ip_address]/[projet_name]/[images] # 推送镜像到当前项目: # docker push 192.168.1.195/library/alpine ## docker push [ip_address]/[projet_name]/[images] ``` --- - ### 建立 Dockeerfile: ``` # 建立專案資料夾 # sudo mkdir nginx_docker # 進入到專案資料夾 # cd nginx_docker # 建立文件 Dockerfile # sudo nano Dockerfile FROM centos:7 RUN yum -y install epel-release RUN yum -y update RUN yum -y install nginx ADD index.html /usr/share/nginx/html/index.html EXPOSE 80/tcp CMD ["nginx", "-g daemon off;"] # 建立文件 index.html # nano index.html <header> <h1>Docker ADD is neat</h1> </header> # 製作光碟片 # docker build -t dopensource/nginx . ``` ``` # 檢查光碟片 # docker images REPOSITORY TAG IMAGE ID CREATED SIZE dopensource/nginx latest e56cefff8926 About an hour ago 765MB nginx latest 6084105296a9 4 days ago 133MB 192.168.1.195/library/alpine latest 28f6e2705743 3 weeks ago 5.61MB alpine latest 28f6e2705743 3 weeks ago 5.61MB 192.168.1.195/centos/centos latest 300e315adb2f 3 months ago 209MB ``` --- ## 參考網址: - https://codertw.com/%E4%BC%BA%E6%9C%8D%E5%99%A8/376868/ - http://www.dark-hamster.com/server/how-to-build-centos-docker-image-and-install-nginx-using-dockerfile/ - https://dopensource.com/2016/05/01/creating-a-docker-file/ - https://docs.microsoft.com/zh-tw/dotnet/core/install/linux-centos - https://docs.microsoft.com/en-us/dotnet/core/install/linux-centos - https://dotnet.microsoft.com/download/dotnet/