docker harbor 域名_一看必会系列:部署docker镜像harbor仓库

2.首先安装docker

yum install -y epel-release lrzsz wget net-tools ntp

时间来来个同步

ntpdate cn.pool.ntp.org

关闭防火墙:

systemctl stop firewalld

systemctl disable firewalld

关闭selinux:

sed -i ‘s/enforcing/disabled/’ /etc/selinux/config

setenforce 0

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum -y install docker-ce-18.06.1.ce-3.el7

systemctl enable docker && systemctl start docker

docker –version

3.安装docker-compose

yum install -y docker-compose

docker-compose –version

1、下载安装包

2、上传并解压安装包

将下载下来的安装包上传到服务器的/home目录,并解压。

[root@test101 home]# tar xf harbor-offline-installer-v1.5.0.tgz

[root@test101 home]# ll

总用量 843504

drwxr-xr-x. 4 root root       229 7月  30 15:48 harbor

-rw-r–r–. 1 root root 863747205 7月  30 15:39 harbor-offline-installer-v1.5.0.tgz

[root@test101 home]#

3、配置harbor和docker

3.1 编辑/home/habor/harbor.cfg,主要修改两个地方:

hostname = 10.0.0.101   #这里直接用的IP

harbor_admin_password = 123456   #登录harbor仓库的密码,默认密码是Harbor12345

5.修改配置文件

配置文件为:/usr/local/harbor/harbor.cfg

配置的内容为:

# vim /usr/local/harbor/harbor.cfg

hostname = rgs.unixfbi.com

#邮箱配置

email_server = smtp.qq.com

email_server_port = 25

email_username = unixfbi@unixfbi.com

email_password =12345678

email_from = UnixFBI

email_ssl = false

#禁止用户注册

self_registration = off

#设置只有管理员可以创建项目

project_creation_restriction = adminonly

6.执行安装脚本

# /usr/local/harbor/install.sh

7.Harbor启动和停止

Harbor 的日常运维管理是通过docker-compose来完成的,Harbor本身有多个服务进程,都放在docker容器之中运行,我们可以通过docker ps命令查看。

或者docker-compose ps 来查看

Harbor的启动和停止

启动Harbor

# docker-compose start

停止Harbor

# docker-comose stop

重启Harbor

# docker-compose restart

改了data路径后,restart报错,但可以先stop,再start进行重启

[root@k8s-registry harbor]# docker-compose restart

Restarting nginx              … done

Restarting harbor-jobservice  … done

Restarting harbor-ui          … error

Restarting registry           … error

Restarting harbor-db          … done

Restarting harbor-adminserver … done

Restarting redis              … done

Restarting harbor-log         … done

[root@k8s-registry harbor]# docker-compose stop

Stopping nginx              … done

Stopping harbor-jobservice  … done

Stopping harbor-db          … done

Stopping harbor-adminserver … done

Stopping redis              … done

Stopping harbor-log         … done

[root@k8s-registry harbor]# docker-compose start

Starting log         … done

Starting mysql       … done

Starting redis       … done

Starting adminserver … done

Starting registry    … done

Starting ui          … done

Starting jobservice  … done

Starting proxy       … done

[root@k8s-registry harbor]#

8.访问测试

在浏览器输入rgs.unixfbi.com,因为我配置的域名为rgs.unixfbi.com。请大家根据自己的配置情况输入访问的域名;

默认账号密码: admin / Harbor12345 登录后修改密码

四、测试上传和下载镜像

在项目中标记镜像:

docker tag SOURCE_IMAGE[:TAG] reg.ccie.wang/k8s/IMAGE[:TAG]

推送镜像到当前项目:

docker push reg.ccie.wang/k8s/IMAGE[:TAG]

1,先登录 docker login ip

2,修改tag 格式,docker tag imagesID 仓库ip/harbor项目名字/imagesname:版本

3,docker push 仓库ip/harbor项目名字/imagesname:版本

[root@k8s-master 1.8+]# docker login reg.ccie.wang

Username: admin

Password:

WARNING! Your password will be stored unencrypted in /root/.docker/config.json.

Configure a credential helper to remove this warning. See

https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

[root@k8s-master 1.8+]# docker push reg.ccie.wang/k8s/kubernetes-dashboard-amd64:v1.10.1

The push refers to repository [reg.ccie.wang/k8s/kubernetes-dashboard-amd64]

fbdfe08b001c: Pushed

v1.10.1: digest: sha256:0ae6b69432e78069c5ce2bcde0fe409c5c4d6f0f4d9cd50a17974fea38898747 size: 529

[root@k8s-master 1.8+]#

[root@k8s-master 1.8+]# docker tag k8s.gcr.io/metrics-server-amd64:v0.3.1 reg.ccie.wang/k8s/metrics-server-amd64:v0.3.1

[root@k8s-master 1.8+]#

[root@k8s-master 1.8+]#

[root@k8s-master 1.8+]# docker push reg.ccie.wang/k8s/metrics-server-amd64:v0.3.1

The push refers to repository [reg.ccie.wang/k8s/metrics-server-amd64]

14679ed867b8: Pushed

f9d9e4e6e2f0: Pushed

v0.3.1: digest: sha256:78938f933822856f443e6827fe5b37d6cc2f74ae888ac8b33d06fdbe5f8c658b size: 739

[root@k8s-master 1.8+]#

拉镜像

[root@k8s-node1 ~]# docker pull reg.ccie.wang/k8s/metrics-server-amd64:v0.3.1

v0.3.1: Pulling from k8s/metrics-server-amd64

Digest: sha256:78938f933822856f443e6827fe5b37d6cc2f74ae888ac8b33d06fdbe5f8c658b

Status: Downloaded newer image for reg.ccie.wang/k8s/metrics-server-amd64:v0.3.1

1.修改各docker client配置

# vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd –insecure-registry rgs.unixfbi.com

增加 –insecure-registry rgs.unixfbi.com 即可。

重启docker:

# systemctl daemon-reload

# systemctl  restart docker

或者

创建/etc/docker/daemon.json文件,在文件中指定仓库地址

# cat > /etc/docker/daemon.json << EOF

{ "insecure-registries":["rgs.unixfbi.com"] }

EOF

然后重启docker就可以。

# systemctl  restart docker

这样设置完成后,就不会提示我们使用https的错误了。

2.创建Dockerfile

# vim Dockerfile

FROM centos:centos7.1.1503

ENV TZ "Asia/Shanghai"

3.创建镜像

# docker build -t rgs.unixfbi.com/library/centos7.1:0.1 .

4.把镜像push到Harbor

# docker login rgs.unixfbi.com

# docker push rgs.unixfbi.com/library/centos7.1:0.1

如果不是自己创建的镜像,记得先执行 docker tags 给镜像做tag

例如:

# docker pull busybox

# docker tag busybox:latest rgs.unixfbi.com/library/busybox:latest

# docker push rgs.unixfbi.com/library/busybox:latest

5.登录web页面查看镜像

6.pull镜像

从别的机器上拉一下镜像

# docker rmi -f $(docker images -q -a )

# docker pull rgs.unixfbi.com/library/centos7.1:0.1

0.1: Pulling from library/centos7.1

07618ba636d9: Pull complete

Digest: sha256:7f398052ae0e93ddf96ba476185c7f436b15abd27acd848a24b88ede4bb3c322

Status: Downloaded newer image for rgs.unixfbi.com/library/centos7.1:0.1

# docker images

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE

rgs.unixfbi.com/library/centos7.1   0.1                 6c849613a995        5 hours ago         212MB

五、Harbor配置TLS证书

因为我们上面对Harbor的配置都是使用的http协议访问,但是我们工作中一般都是配置https访问。所以我给大家演示一下怎么配置Harbor可以使用https访问,以及配置TLS证书都需要做哪些工作。

1.修改Harbor配置文件

因为Harbor默认使用http协议访问,所以我们这里在配置文件中,开启https配置;

配置harbor.cfg

hostname = rgs.unixfbi.com

ui_url_protocol = https

ssl_cert = /etc/certs/ca.crt

ssl_cert_key = /etc/certs/ca.key

2.创建自签名证书key文件

# mkdir /etc/certs

# openssl genrsa -out /etc/certs/ca.key 2048

Generating RSA private key, 2048 bit long modulus

….+++

…………………………………………..+++

e is 65537 (0x10001)

3.创建自签名证书crt文件

注意命令中/CN=rgs.unixfbi.com字段中rgs.unixfbi.com修改为你自己的仓库域名。

# openssl req -x509 -new -nodes -key /etc/certs/ca.key -subj "/CN=rgs.unixfbi.com" -days 5000 -out /etc/certs/ca.crt

4.开始安装Harbor

# ./install.sh

✔ —-Harbor has been installed and started successfully.—-

Now you should be able to visit the admin portal at https://reg.ccie.wang.

For more details, please visit https://github.com/vmware/harbor .

显示是https了。

5.客户端配置

客户端需要创建证书文件存放的位置,并且把服务端创建的证书拷贝到该目录下,然后重启客户端docker。我们这里创建目录为:/etc/docker/certs.d/rgs.unixfbi.com

# mkdir -p /etc/docker/certs.d/rgs.unixfbi.com

把服务端crt证书文件拷贝到客户端,例如我这的客户端为:192.168.199.183

# scp /etc/certs/ca.crt root@192.168.199.183:/etc/docker/certs.d/rgs.unixfbi.com/

重启客户端docker

# systemctl restart docker

6.测试是否支持https访问

# docker login rgs.unixfbi.com

Username (admin):

Password:

Login Succeeded

六、遇到问题

遇到的问题就是Harbor我配置的是http访问,但是docker客户端默认都是https访问Harbor,所以就会产生错误。下面看看我是怎么解决这个问题的吧。下面我们来访问以下Harbor

# docker pull rgs.unixfbi.com/library/centos7.1:0.1

Error response from daemon: Get https://rgs.unixfbi.com/v1/_ping: dial tcp 192.168.199.233:443: getsockopt: connection refused

问题原因:

因为docker默认访问仓库时都是使用的https协议,而我们的仓库配置的是http

解决方法:

方法一:

在docker启动的配置仓库地址添加如下内容:

–insecure-registry rgs.unixfbi.com

# vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd –insecure-registry rgs.unixfbi.com

然后

# systemctl daemon-reload

# systemctl  restart docker

方法二:

创建/etc/docker/daemon.json文件,在文件中指定仓库地址

# cat > /etc/docker/daemon.json << EOF

{ "insecure-registries":["rgs.unixfbi.com"] }

EOF

然后重启docker就可以了

# systemctl  restart docker

方法三:

就是把你的仓库也配置成https ,设置证书。好吧,这种方法其实我不说,你也知道。

有坑 启动后发现存储只有50G,但/home目录划的400G。肯定是哪配置错误

转移数据目录有两种方式:一种是将默认数据目录软链至其他路径,另外一种是修改相应配置。目前使用的是第一种

Harbor各个组件容器的启动配置在docker-compose.yml文件中,所以可以在这里修改

打开该文件后,搜索所有volumes关键字,可以在每个容器的volumes下面看到,数据在Host机器上的挂载只会在两个地方:/data和./common。将/data修改为所需目录即可,例如/home/harborData

在Harbor的安装配置文件harbor.cfg中也有部分数据路径设置,主要为ssh相关设置,也作出相应修改即可

修改地方有两处

第一处

sed -i "s/\/data\//\/home\/opt\/harbor_data\/data\//g" docker-compose.yml

这里替换会有个错误 第60行需要进行手动修改

原  – /data/:/data/:z

改   – /home/opt/harbor_data/data/:/data/:z

不改的话也能用,但ui会不显示容量大小。而且这个容量df -h  是看不到的

第二处

[root@k8s-registry harbor]# grep data harbor.cfg

secretkey_path =  /home/opt/harbor_data/data

1.修改前使用

docker-compose down -v停止并删除现有容器,

2.修改完成后先执行/home/opt/harbor/prepare使配置生效

3.然后使用docker-compose up -d重新创建容器并启动服务

[root@k8s-registry harbor]# docker-compose down -v

Stopping nginx              … done

Stopping harbor-jobservice  … done

Stopping harbor-ui          … done

Stopping harbor-adminserver …

Stopping redis              … done

Stopping registry           …

Stopping harbor-db          … done

Stopping harbor-log         …

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值