Harbor
Github地址https://github.com/goharbor/harbor
官方地址:https://github.com/goharbor/harbor/releases
安装
注意在安装之前 需要确保已经安装了docker 和docker-compose
安装docker
# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# systemctl daemon-reload
# service docker restart
# service docker status
可以设置开机自启动
# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
# sudo curl -L https://github.com/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
安装docker-compose
# pip install -U docker-compose
SSL证书创建
官方文档:https://github.com/goharbor/harbor/blob/master/docs/install-config/configure-https.md
创建CA证书
# openssl genrsa -out ca.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
.......................+++++
................+++++
e is 65537 (0x010001)
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/C=CN/ST=BJ/L=BeiJing/O=BTC/OU=MOST/CN=harbor/emailAddress=ca@harbor.com"
选项参数说明:
genrsa 生成私钥
-out filename 标准输出到filename文件
req 生成证书请求
-new 生成新证书签署请求
-x509 专用于CA生成自签证书;不自签的时候不要加该选项
-days num 证书的有效期限
-key file 生成请求时用到的私钥文件
-out filename 标准输出到filename文件
subj内容详解:
C = 国家
ST = 省/州
L = 城市
O = Organization Name
OU = Organizational Unit Name
CN = Common Name
emailAddress = 注册邮箱
如果出现如下错误
Can't load /root/.rnd into RNG
140012552131008:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/root/.rnd
执行如下
# cd /root
# openssl rand -writerand .rnd
创建服务器证书
创建私钥
# openssl genrsa -out httpd.key 1024
生成签发请求
# openssl req -new -key httpd.key -out httpd.csr -subj "/C=CN/ST=BJ/L=BeiJing/O=BTC/OU=OPS/CN=harbor/emailAddress=nlp@harbor.com"
使用CA证书进行签发
# openssl x509 -req -sha256 -in httpd.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 36500 -out httpd.crt
Signature ok
subject=C = CN, ST = BJ, L = BeiJing, O = BTC, OU = OPS, CN = harbor, emailAddress = nlp@harbor.com
Getting CA Private Key
验证签发证书是否有效
# openssl verify -CAfile ca.crt httpd.crt
httpd.crt: OK
其中将httpd.key和httpd.crt,放到/etc/harbor/cert/目录下,后面harbor配置https 需要
一件脚本:https://rancher2.docs.rancher.cn/docs/installation/options/self-signed-ssl/_index/
修改配置
修改配置harbor.yml
hostname 这里设置本机的ip
harbor_admin_password 登录密码
port 端口号
安装
执行 ./prepare
# ./prepare
prepare base dir is set to /root/app/harbor
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registry/root.crt
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
执行./install.sh 安装命令
~/app/harbor# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 19.03.12
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.26.2
如果修改了Harbor的配置文件harbor.yml,因为Harbor是基于docker-compose服务编排的,我们可以使用docker-compose命令重启Harbor。
未修改配置文件,重启Harbor命令:docker-compose start | stop | restart
关于http
在docker.service文件中添加—insecure-registry参数指定仓库地址和端口。
ExecStart=/usr/bin/dockerd --insecure-registry=192.168.1.191:8888
重启docker
systemctl restart docker
镜像推送命令**
docker login 到镜像仓库服务器
docker login --username=testuser --password=xxxx harbor服务器地址
eg
docker login -u baxiang -p BAxiang123456 https://192.168.1.51:443
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
打docker tag docker tag 对本地镜像打tag标签到镜像仓库服务器
docker tag hello-world:latest xxxx/project-test/hello-world:1.0
docker push 镜像到镜像仓库中
docker push xxxx/project-test/hello-world:1.0
docker客户端配置免https
Docker 默认不允许非 HTTPS 方式推送镜像。我们可以通过 Docker 的配置选项来取消这个限制。否则会出现如下错误信息:
Error response from daemon: Get https:// 172.16.1.146:5000/v1/_ping: http: server gave HTTP response to HTTPS client
或者如下
x509: certificate signed by unknown authority
需要添加{ "insecure-registries":["host:port"] }
到/etc/docker/daemon.json
例如直接 vim
{
"insecure-registries": [
"IP:PORT"
]
}
eg:
vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.91.131:5000"]
}
或者
# echo '{ "insecure-registries":["172.16.1.146:8888"] }' > /etc/docker/daemon.json
然后需要重启
systemctl daemon-reload
systemctl restart docker
问题
denied: requested access to the resource is denied
需要登录harbor
参考
http://www.zhangblog.com/2020/05/13/docker06/
https://www.cnblogs.com/haorong/p/11097821.html
http://www.mydlq.club/article/66/
https://juejin.im/post/5d9c2f25f265da5bbb1e3de5
https://juejin.im/post/5e9dbe676fb9a03c5e0cefe9
https://github.com/docker/distribution/issues/948
https://mayanbin.com/post/installing-harbor.html
https://www.cnblogs.com/operationhome/p/10868498.html