【K8S运维知识汇总】第2天5:harbor私有仓库部署

下载harbor版本

# harbor安装1.7.6以上版本	
# 1.9.1不能用,添加dashboard.od.com会无法push

[root@localhost src]# rz	# 上传harbor

[root@hdss7-200 ~]# mkdir /opt/src
[root@hdss7-200 ~]# cd /opt/src/
[root@localhost src]# mv /root/harbor-offline-installer-v1.8.3.tgz .

[root@hdss7-200 src]# ls
harbor-offline-installer-v1.9.1.tgz

[root@hdss7-200 src]# tar zxvf harbor-offline-installer-v1.8.0.tgz -C /opt

把软件包做版本标识,做一个软链接,便于以后升级

[root@hdss7-200 src]# cd ..
[root@hdss7-200 opt]# mv harbor/ harbor-v1.8.0
[root@localhost opt]# ll
总用量 0
drwx--x--x 4 root root  28 625 18:25 containerd
drwxr-xr-x 2 root root 100 625 22:41 harbor-v1.8.0
drwxr-xr-x 2 root root  49 625 22:40 src

[root@hdss7-200 opt]# ln -s /opt/harbor-v1.8.0/ /opt/harbor
[root@hdss7-200 opt]# ll
总用量 0
drwx--x--x 4 root root  28 625 18:25 containerd
lrwxrwxrwx 1 root root  19 625 22:44 harbor -> /opt/harbor-v1.8.0/
drwxr-xr-x 2 root root 100 625 22:41 harbor-v1.8.0
drwxr-xr-x 2 root root  49 625 22:40 src

编辑harbor文件

[root@hdss7-200 opt]# cd harbor
[root@hdss7-200 harbor]# vi harbor.yml
5 hostname: harbor.od.com
# 不占用80端口
10   port: 180
# 在生产环境中,密码要提升复杂度
27 harbor_admin_password: Harbor12345
35 data_volume: /data/harbor
# 更改日志存储路径
82   location: /data/harbor/logs
# 创建日志目录
[root@hdss7-200 harbor]# mkdir -p /data/harbor/logs

安装harbor

安装所需要的单机编排工具:

[root@hdss7-200 harbor]# yum install -y docker-compose
[root@hdss7-200 harbor]# rpm -qa docker-compose
docker-compose-1.18.0-4.el7.noarch

安装

[root@hdss7-200 harbor]# ./install.sh 
[root@hdss7-200 harbor]# docker-compose ps

每次重启docker需要执行

# 通过编排工具来启动yaml配置文件中写明的所有容器
[root@hdss7-200 harbor]# docker-compose up -d  
[root@localhost harbor]# docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                             PORTS                       NAMES
7d50009d4395        goharbor/nginx-photon:v1.8.3                        "nginx -g 'daemon of…"   14 seconds ago      Up 13 seconds (health: starting)   0.0.0.0:180->80/tcp         nginx
4b8b1ea3bc14        goharbor/harbor-portal:v1.8.3                       "nginx -g 'daemon of…"   15 seconds ago      Up 14 seconds (health: starting)   80/tcp                      harbor-portal
2756f67a8d0a        goharbor/harbor-jobservice:v1.8.3                   "/harbor/start.sh"       15 seconds ago      Up 14 seconds                                                  harbor-jobservice
4ba9c81974e4        goharbor/harbor-core:v1.8.3                         "/harbor/start.sh"       16 seconds ago      Up 15 seconds (health: starting)                               harbor-core
7e8f44204a1d        goharbor/redis-photon:v1.8.3                        "docker-entrypoint.s…"   17 seconds ago      Up 16 seconds                      6379/tcp                    redis
1bd68ea6cdab        goharbor/harbor-registryctl:v1.8.3                  "/harbor/start.sh"       17 seconds ago      Up 16 seconds (health: starting)                               registryctl
071a5e1092f6        goharbor/registry-photon:v2.7.1-patch-2819-v1.8.3   "/entrypoint.sh /etc…"   17 seconds ago      Up 16 seconds (health: starting)   5000/tcp                    registry
3c735cecd423        goharbor/harbor-db:v1.8.3                           "/entrypoint.sh post…"   18 seconds ago      Up 16 seconds (health: starting)   5432/tcp                    harbor-db
bf516c7b7e22        goharbor/harbor-log:v1.8.3                          "/bin/sh -c /usr/loc…"   18 seconds ago      Up 17 seconds (health: starting)   127.0.0.1:1514->10514/tcp   harbor-log

安装nginx做反向代理

[root@hdss7-200 harbor]# yum install -y nginx

# 添加nginx配置文件
[root@hdss7-200 harbor]# vi /etc/nginx/conf.d/harbor.od.com.conf
server {
    listen       80;
    server_name  harbor.od.com;

    client_max_body_size 1000m;

    location / {
        proxy_pass http://127.0.0.1:180;
    }
}

检测配置文件

[root@hdss7-11 harbor]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@hdss7-11 harbor]# systemctl start nginx
[root@hdss7-11 harbor]# systemctl enable nginx

配置10.4.7.11上的dns服务器

[root@hdss7-11 named]# vi /var/named/od.com.zone 
$ORIGIN od.com.
$TTL 600        ; 10 minutes
@               IN SOA  dns.od.com. dnsadmin.od.com. (
                                2019120902 ; serial		# 往后滚动一个记录编号02,每次更改配置,必须滚动一个序号
                                10800      ; refresh (3 hours)
                                900        ; retry (15 minutes)
                                604800     ; expire (1 week)
                                86400      ; minimum (1 day)
                                )
                                NS   dns.od.com.
$TTL 60 ; 1 minute
dns                A    10.4.7.11
harbor             A    10.4.7.200

[root@hdss7-11 named]# systemctl restart named 

验证

[root@hdss7-11 named]# dig -t A harbor.od.com +short

浏览器输入:http://harbor.od.com/
【K8S运维知识汇总】第2天5:harbor私有仓库部署_第1张图片

新建一个public项目,公开

【K8S运维知识汇总】第2天5:harbor私有仓库部署_第2张图片
【K8S运维知识汇总】第2天5:harbor私有仓库部署_第3张图片

上传nginx镜像到harbor仓库中

[root@hdss7-200 harbor]# docker pull nginx:1.7.9

[root@hdss7-200 harbor]# docker tag nginx:1.7.9 harbor.od.com/public/nginx:v1.7.9 

[root@localhost harbor]# docker login harbor.od.com
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@localhost harbor]# docker push harbor.od.com/public/nginx:v1.7.9
The push refers to repository [harbor.od.com/public/nginx]
5f70bf18a086: Pushed 
4b26ab29a475: Pushed 
ccb1d68e3fb7: Pushed 
e387107e2065: Pushed 
63bf84221cce: Pushed 
e02dce553481: Pushed 
dea2e4984e29: Pushed 
v1.7.9: digest: sha256:b1f5935eb2e9e2ae89c0b3e2e148c19068d91ca502e857052f14db230443e4c2 size: 3012

你可能感兴趣的:(K8S运维知识汇总)