linux怎么查看本机内存大小
265
2022-10-17
Harbor----使用 Harbor 安装包安装部署 Harbor
@toc
一、Harbor安装准备条件
这里以 harbor 2.5.3 版本为例
1.1 硬件要求
Harbor 安装对硬件资源CPU、内存和硬盘的要求如下表:
资源 | 最小要求 | 推荐配置 |
---|---|---|
CPU | 2 CPU | 4 CPU |
Mem | 4 GB | 8 GB |
Disk | 40 GB | 160 GB |
使用如下命令分别查看服务器的物理CPU和逻辑CPU个数
# 查看物理CPU个数 cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l # 查看逻辑CPU个数 cat /proc/cpuinfo |grep "processor"|wc -l # 查看内存 free -h # 查看地盘 df -h
1.2 软件要求
harbor 2.5.3 版本对docker、docker-compose等软件的要求
软件 | 版本号 |
---|---|
docker | 17.06.0 及以上 |
docker-compose | 1.18.0 及以上 |
openssl |
1.3 网络端口要求
harbor 2.5.3 版本对网络端口的要求如下表
端口 | 协议 | 描述 |
---|---|---|
443 | https | https端口,可以从配置文件中修改 |
4443 | https | 当notary打开时使用,否则不需要使用,可以通过配置文件修改 |
80 | http | http端口,可以从配置文件中修改 |
二、下载 Harbor 的安装包文件
2.1 Harbor 安装包分类
Harbor 的安装文件分为在线安装包和离线安装包
在线安装包:在线安装包从 docker Hub 下载镜像,因此安装包文件比较小,适用于安装服务器能联网的场景下 离线安装包:离线安装包包含了预先编译好的镜像文件,因此安装文件较大,适用于安装服务器未联网的场景下
2.2 下载并解压安装包
(3) 如服务器能联网,则到服务器直接使用wget 下载,命令如下:
# 下载在线安装版 wget https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-online-installer-v2.5.3.tgz # 下载离线安装版 wget 解压
# 解压在线安装版 tar -zxvf harbor-online-installer-v2.5.3.tgz # 解压离线安装版 tar -zxvf harbor-offline-installer-v2.5.3.tgz
三、配置安装 Harbor
3.1 安装基于 协议访问的默认的 Harbor
默认安装命令没有启用 Notary, Trivy 和 Chart Repository Service。
Notary:镜像签名认证 Trivy: 容器漏洞扫描 Chart Repository Service: Helm chart 仓库服务
一般在内网的情况下,可以直接使用 的方式访问,这种方式安装部署方式相对比较简单,在 harbor 压缩包解压后有一个 harbor 文件夹,进入
[root@redrose2100 online]# ls harbor harbor-online-installer-v2.5.3.tgz [root@redrose2100 online]# cd harbor [root@redrose2100 harbor]# ls common.sh harbor.yml.tmpl install.sh LICENSE prepare [root@redrose2100 harbor]#
可以发现 harbor 文件夹中有一个 harbor.yml。tmpl文件,将其文件名修改为 harbor.yml
[root@redrose2100 harbor]# mv harbor.yml.tmpl harbor.yml [root@redrose2100 harbor]# ls common.sh harbor.yml install.sh LICENSE prepare [root@redrose2100 harbor]#
然后编辑通过 vi harbor.yml 编辑 harbor.yml 文件
3.1.1 配置域名
配置 harbor 的域名,如果内部的不用域名,可以直接设置主机名或者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: harbor.redrose2100.com
3.1.2 配置 的端口
默认是 80,这里修改为 10001
# related config http: # port for default is 80. If enabled, this port will redirect to port port: 10001
3.1.3 注释 配置
暂时可以先将 配置注释
# related config #https: # port for harbor, default is 443 #port: 443 # The path of cert and key files for nginx #certificate: /your/certificate/path #private_key: /your/private/key/path
3.1.4 配置 admin 用户的密码
默认密码是Harbor12345,这里可以修改自己的密码
# The initial password of Harbor admin # It only works in first time to install harbor # Remember Change the admin password from UI after launching Harbor. harbor_admin_password: Harbor12345
3.1.5 执行安装 harbor 的脚本
其他配置暂时保持默认配置,执行瑞安脚本即可
./install.sh
3.1.6 修改 docker 配置文件
安装完成 harbor 后,因为此时使用的是 协议,此时需要在 docker 的配置文件 /etc/docker/daemon.json 中增加如下内容:
"insecure-registries":["harbor.redrose2100.com"],
完整的内容如下所示:
[root@redrose2100 harbor]# cat /etc/docker/daemon.json { "exec-opts":["native.cgroupdriver=systemd"], "registry-mirrors":[ "https://ooe7wn09.mirror.aliyuncs.com", "https://registry.docker-cn.com", "http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn" ], "insecure-registries":["harbor.redrose2100.com"], "dns": ["114.114.114.114", "8.8.8.8"] }
然后重启 docker
systemctl restart docker
再重启 harbor , 在 harbor 文件夹中执行如下两条命令
# 停止 harbor docker-compose down -v # 启动 harbor docker-compose up -d
3.1.7 验证 harbor
# 修改 hello-world 镜像的 tag 值 docker tag hello-world:latest harbor.redrose2100.com/redrose2100/hello-world:latest # 登录 harbor docker login harbor.redrose2100.com -u admin -p xxxx(harbor的密码) # 推送镜像 docker push harbor.redrose2100.com/redrose2100/hello-world:latest
至此,最简单的基于配置 访问 Harbor
在生产环境,需要从CA获取证书,在测试环境,可以通过openssl生成CA证书以及通过CA生成服务端证书和客户端证书
如下假设harbor的域名为: harbor.redrose2100.com
3.2.1 配置生成CA证书
(1) 首先创建一个目录,用于存放生成的证书等文件
mkdir ssl cd ssl
(2) 生成 CA 证书 私钥
openssl genrsa -out ca.key 4096
(3) 生成 CA 证书,注意修改域名
openssl req -x509 -new -nodes -sha512 -days 3650 \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.redrose2100.com" \ -key ca.key \ -out ca.crt
3.2.2 生成服务端证书
(1) 生成服务端证书私钥,注意替换自己的域名
openssl genrsa -out harbor.redrose2100.com.key 4096
(2) 生成证书签名
openssl req -sha512 -new \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.redrose2100.com" \ -key harbor.redrose2100.com.key \ -out harbor.redrose2100.com.csr
(3) 生成 v3 扩展文件,注意替换为自己的域名
cat > v3.ext <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] DNS.1=harbor.redrose2100.com EOF
(4) 为 harbor 主机生成证书
openssl x509 -req -sha512 -days 3650 \ -extfile v3.ext \ -CA ca.crt -CAkey ca.key -CAcreateserial \ -in harbor.redrose2100.com.csr \ -out harbor.redrose2100.com.crt
3.2.3 为 harbor 和 docker 颁发证书
(1) 将服务端证书拷贝至 /data/cert/目录下
mkdir -p /data/cert/ cp harbor.redrose2100.com.crt /data/cert/ cp harbor.redrose2100.com.key /data/cert/
(2) 将 crt文件转换为cert文件,为docker使用
openssl x509 -inform PEM -in harbor.redrose2100.com.crt -out harbor.redrose2100.com.cert
(3) 将 harbor.redrose2100.com.cert harbor.redrose2100.com.key ca.crt 文件拷贝到docker的证书目录下,注意替换为自己的域名
mkdir -p /etc/docker/certs.d/harbor.redrose2100.com/ cp harbor.redrose2100.com.cert /etc/docker/certs.d/harbor.redrose2100.com/ cp harbor.redrose2100.com.key /etc/docker/certs.d/harbor.redrose2100.com/ cp ca.crt /etc/docker/certs.d/harbor.redrose2100.com/
这里需要注意的是,如果nginx中对或者 /etc/docker/certs.d/harbor_IP:port
(4) 重启docker
systemctl restart docker
3.2.4 修改 harbor.yml 配置文件
修改配置,开启 配置,如下前面部署 模式的时候将的配置放开注释,而且修改证书的文件路径,如下所示
# related config https: # port for harbor, default is 443 port: 8443 # The path of cert and key files for nginx certificate: /data/cert/harbor.redrose2100.com.crt private_key: /data/cert/harbor.redrose2100.com.key
然后执行如下命令更新 harbor
./install.sh
3.2.5 Nginx 配置 nginx.conf 配置,增加监听 443 端口的,跳转到harbor的8443端口,此外在这里需要指定证书文件的路径
server { listen 443 ssl; server_name harbor.redrose2100.com; ssl_certificate /data/cert/harbor.redrose2100.com.crt; ssl_certificate_key /data/cert/harbor.redrose2100.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; location / { client_max_body_size 1024M; client_body_buffer_size 1024M; proxy_redirect off; proxy_pass https://172.22.27.162:8443; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
然后将 的跳转到 { listen 80; server_name harbor.redrose2100.com; return 301 https://harbor.redrose2100.com$request_uri; }
然后重新加载配置文件
nginx -s reload
此时在浏览器就可以 通过 和 访问,当使用 时会发现自动跳转到 Nginx 配置可能遇到额问题
注意,如果出现类似如下错误:
nginx: [emerg] unknown directive "ssl_certificate" in /usr/local/nginx/conf/nginx.conf
或者类似如下错误;
error: SSL modules require the OpenSSL library.
说明 nginx 没有安装ssl,此时进入nginx的源码目录,执行如下命令
./configure --prefix=/usr/local/nginx --with---with---with-openssl=/usr/local/src/openssl-1.1.1o
其中:
/usr/local/src/openssl-1.1.1o 目录 为openssl 源码包的解压目录
然后使用 make 编译,注意,不要使用 make install,否则会覆盖
make
然后备份原有的nginx 命令,并将新编译的nginx拷贝的nginx命令所在的目录
# 将原有的命令重命名备份 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bark # 将新编译的nginx命令拷贝到nginx命令的目录下 cp objs/nginx /usr/local/nginx/sbin/
然后执行 nginx -V ,如下,出现 --with-表示安装成功
[root@redrose2100 nginx-1.21.4]# nginx -V nginx version: nginx/1.21.4 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.1.1o 3 May 2022 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with---with---with-openssl=/usr/local/src/openssl-1.1.1o [root@redrose2100 nginx-1.21.4]#
然后再次执行如下命令重新加载nginx配置
nginx -s reload
3.3 安装镜像签名
安装签名时,只需要在执行 ./install.sh 的命令的时候带上 --with-notary 参数即可
./install.sh --with-notary
3.4 安装扫描器
安装扫描器时,只需要在执行 ./install.sh 的命令的时候带上 --with-trivy 参数即可
./install.sh --with-trivy
3.5 安装 Chart Repository 服务
安装 Chart Repository 服务时,只需要在执行 ./install.sh 的命令的时候带上 --with-chartmuseum 参数即可
./install.sh --with-chartmuseum
3.6 同时安装签名、扫描器、Chart Repository 服务
同时安装签名、扫描器、Chart Repository 服务时只需要将三个参数都带上即可
./install.sh --with-notary --with-trivy --with-chartmuseum
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~