CentOS安装Harbor

CentOS版本:7.4

Harbor版本:1.5.0

Docker版本:1.12.6

Docker Compose版本:1.21.2

一、安装Harbor(http方式,80端口)

1、安装Docker

(1)搜索docker

[root@node3 ~]# yum search docker

(2)安装docker

[root@node3 ~]# yum install -y docker

(3)启动命令

[root@node3 ~]# systemctl start docker

(4)查看状态

[root@node3 ~]# systemctl status docker

(5)查看版本

[root@node3 ~]# docker version

(6)查看docker信息

[root@node3 ~]# docker info

(7)开机启动

[root@node3 ~]# systemctl enable docker

2、安装Docker Compose

1)下载文件

curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

2)添加可执行权限

chmod +x /usr/local/bin/docker-compose

3、下载Harbor离线安装文件

wget https://storage.googleapis.com/harbor-releases/release-1.5.0/harbor-offline-installer-v1.5.0.tgz

4、解压Harbor离线安装文件

Harbor安装路径:/root/local/harbor

tar zxf harbor-offline-installer-v1.5.0.tgz -C /root/local

5、修改harbor.cfg

cd /root/local/harbor

vim harbor.cfg

修改hostname为本机IP地址

#The IP address or hostname to access admin UI and registry service.

#DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.

hostname = 10.72.77.176

6、执行准备命令

./prepare

7、执行安装命令

./install.sh

8、访问网址

http://10.72.77.176

二、安装Harbor(https方式,80端口)

1、停止第一步安装好的Harbor容器

docker-compose down -v

2、SSL证书配置

官网配置说明:

https://github.com/vmware/harbor/blob/master/docs/configure_https.md

(1)生成根证书

a. 创建证书存放目录

mkdir -p /data/cert && cd /data/cert

b. 创建自己的CA证书(不使用第三方权威机构的CA来认证,自己充当CA的角色)

openssl genrsa -out ca.key 2048   #生成根证书私钥(无加密)

openssl req -x509 -new -nodes -key ca.key -days 10000 -out ca.crt -subj "/CN=Harbor-sz"

req     产生证书签发申请命令

-x509   签发X.509格式证书命令。X.509是最通用的一种签名证书格式。

-new    生成证书请求-key     指定私钥文件-nodes   表示私钥不加密

-out    输出-subj    指定用户信息 -days    有效期

(2)生成服务器端证书

a. 生成服务器端私钥和CSR签名请求

 openssl req -newkey rsa:4096 -nodes -sha256 -keyout server.key -out server.csr

b. 签发服务器证书

echo subjectAltName = IP:10.72.77.176 > extfile.cnf

openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out server.crt

 x509           签发X.509格式证书命令。  

-req           表示证书输入请求。  

-days          表示有效天数  -extensions    表示按OpenSSL配置文件v3_req项添加扩展。  

-CA            表示CA证书,这里为ca.crt  

-CAkey         表示CA证书密钥,这里为ca.key  

-CAcreateserial表示创建CA证书序列号  

-extfile      指定文件

3、修改harbor.cfg

vim harbor.cfg

#The IP address or hostname to access admin UI and registry service.

#DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.

hostname = 10.72.77.176

#The protocol for accessing the UI and token/notification service, by default it is http.

#It can be set to https if ssl is enabled on nginx.

ui_url_protocol = https

#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

4、设置docker证书

# 如果如下目录不存在,请创建,如果有域名请按此格式依次创建

mkdir -p /etc/docker/certs.d/10.72.77.176

# 如果端口为443,则不需要指定。如果为自定义端口,请指定端口

# /etc/docker/certs.d/yourdomain.com:port

 

# 将ca根证书依次复制到上述创建的目录中

cp /data/cert/ca.crt /etc/docker/certs.d/10.72.77.176/

5、再次执行安装命令

/install.sh

6、访问网址

https://10.72.77.176

三、安装Harbor(https方式,7000端口)

在公网上,一般情况下都不暴露默认端口,避免被攻击!

以下修改harbor的默认80端口为其他端口!

这里示例修改为7000端口!

注意:以下步骤都是在harbor安装目录下操作!!!

cd /root/local/harbor

1、修改docker-compose.yml文件映射为7000端口

vim docker-compose.yml

proxy:

    image: vmware/nginx-photon:1.11.13

    container_name: nginx

    restart: always

    volumes:

      - ./common/config/nginx:/etc/nginx:z

    networks:

      - harbor

    ports:

      - 7000:80

      - 443:443

      - 4443:4443

2、执行准备命令

./prepare

 

3、修改common/templates/registry/config.yml文件

vim common/templates/registry/config.yml

auth:

  token:

    issuer: harbor-token-issuer

    realm: $ui_url/service/token

    rootcertbundle: /etc/registry/root.crt

service: harbor-registry

4、修改common/config/registry/config.yml文件

vim common/config/registry/config.yml

auth:

  token:

    issuer: harbor-token-issuer

    realm: https://10.72.77.176/service/token

    rootcertbundle: /etc/registry/root.crt

    service: harbor-registry

5、修改docker配置文件,设置信任的主机与端口

注意:如果https端口使用的默认443的话,这里只要配置IP地址,不需要带端口号

vim /etc/docker/daemon.json

 {

    "insecure-registries": [

        "10.72.77.176"

    ]

}

6、重新启动docker

systemctl daemon-reload

systemctl restart docker.service

7、停止harbor,重新启动并生成配置文件

docker-compose stop

./install.sh

最后,测试验证:

# docker login 10.72.77.176:7000

Username: admin

Password:

Login Succeeded

ok,完成!

四、常用命令

先进入harbor安装目录 

cd /root/local/harbor

1、常规操作

暂停harbor docker容器stop,并不删除容器

docker-compose stop

恢复harbor 恢复docker容器运行

docker-compose start

停止harbor  停止并删除docker容器

docker-compose down -v

启动harbor 启动所有docker容器

docker-compose up -d

2、修改运行配置

# 停止 harbor

docker-compose down -v

# 修改配置  

vim harbor.cfg

# 执行./prepare已更新配置到docker-compose.yml文件  

./prepare

# 启动 harbor  

docker-compose up -d

3、主要目录

日志目录 /var/log/harbor

数据目录 /data 

其中最主要是 /data/database 和 /data/registry 目录,如果你要彻底重新安装harbor,删除这两个目录即可。

猜你喜欢

转载自www.cnblogs.com/Jasmin/p/9877488.html
今日推荐