本文从安装完成Centos7.3开始记录,直到Harbor安装完成全过程
配置网络
$ vi /etc/sysconfig/network-scripts/ifcfg-eth0
IPADDR=172.16.22.76
GATEWAY=172.16.22.1
NETMASK=255.255.255.128
DNS1=8.8.8.8
DNS2=8.8.4.4
ONBOOT=YES
BOOTPROTO=static
应用网络配置
$ systemctl restart network
解决yum源无法更新和下载软件,增加163源
http://mirrors.163.com/.help/centos.html
// 备份默认源
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
// 下载 CentOS7-Base-163.repo 并放入 /etc/yum.repos.d/ 目录下
$ yum clean all
$ yum makecache
下载wget
$ yum install -y wget
配置阿里云镜像
$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
$ yum clean all
$ yum makecache
下载安装docker
$ yum install docker
下载安装vim
$ yum install -y vim
下载安装扩展源epel
$ sudo yum -y install epel-release
下载安装python-pip
$ yum install python-pip
下载安装docker-compose
$ pip install docker-compose
离线安装Harbor
官网下载并拷贝harbor-offline-installer-v1.4.0_2.tgz到home目录下并解压
$ tar zxvf harbor-offline-installer-v1.4.0_2.tgz
// 解压完成后进入harbor目录修改配置文件
$ cd /home/harbor/
$ vim docker-compose.yml
version: '2'
services:
log:
image: vmware/harbor-log:v1.4.0
container_name: harbor-log
restart: always
volumes:
- /var/log/harbor/:/var/log/docker/:z - ./common/config/log/:/etc/logrotate.d/:z ports:
- 127.0.0.1:1514:10514 networks:
- harbor registry:
image: vmware/registry-photon:v2.6.2-v1.4.0
container_name: registry
restart: always
volumes:
- /data/registry:/storage:z - ./common/config/registry/:/etc/registry/:z networks:
- harbor ports:
- 5000:5000 // 只增加这一行配置 environment:
- GODEBUG=netdns=cgo command:
["serve","/etc/registry/config.yml"]
depends_on:
- log logging:
driver: "syslog"
$ vim harbor.cfg
## Configuration file of Harbor
## 其他都不修改
hostname = 172.16.22.76
使用官方自带脚本更新参数
$ ./prepare
执行./install.sh 自动进行安装
$ ./install.sh
安装完成后访问172.16.22.76 使用admin Harbor12345 进行登陆管理并创建demo-project公开项目
使用国内docker仓库镜像
$ curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://9e054c8b.m.daocloud.io
重启docker会报错,修改 /etc/docker/daemon.json 为
{
"registry-mirrors": ["http://9e054c8b.m.daocloud.io"],"insecure-registries": [] }
在项目中标记镜像
// 首先拉取一个MysqL镜像作为测试
$ docker pull MysqL:5.7
$ docker tag daocloud.io/MysqL:5.7 172.16.22.76/demo-project/MysqL:5.7
登陆Harbor
$ docker login 172.16.22.76
Username:admin
Password:Harbor12345
Error response from daemon: Get https://172.16.22.76/v1/users/: dial tcp 172.16.22.76:443: getsockopt: connection refused
$ vi /etc/sysconfig/docker
## 追加参数 --insecure-registry 172.16.22.76
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry 172.16.22.76'
推送镜像到harbor仓库
$ docker push 172.16.22.76/demo-project/hnnp-MysqL:5.7