harbor2.1安装及管理

环境

部署测试时系统: centos7.8

硬件

资源 容量 描述
中央处理器 最小2 CPU 4 CPU是首选
内存 最小4GB 8GB是首选
磁盘 最小40GB 160GB是首选

2.1安装步骤

配置自签证书

cd /etc/ssl/certs/
mkdir domain.com
cd domain.com/
openssl genrsa -des3 -out server.key 2048  # 生产带密码的证书
openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=Guangdong/L=Shenzhen/O=mw/OU=mw/CN=domain.com"
openssl rsa -in server.key -out server.key  # 取消密码
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
openssl dhparam -out dhparam.pem 2048

安装harbor

wget https://github.com/goharbor/harbor/releases/download/v2.1.0/harbor-offline-installer-v2.1.0.tgz.asc
tar -xf harbor-offline-installer-v2.1.0.tgz -C /opt/
cp /opt/harbor/harbor.yml.tmpl /opt/harbor/harbor.yml
修改/opt/harbor/harbor.yml中的hostname字段为实际ip地址或者域名,域名ssl证书
bash /opt/harbor/install.sh --with-clair --with-chartmuseum

说明:

  • --with-notary 启用harbor.yml中的https配置,加载证书。
  • --with-clair 启动helm的clair格式
  • --with-chartmuseum 启动镜像漏洞扫描
harbor.yml配置文件
只启用http,前面有Nignx代理
5  hostname: domain.com  #nginx 的主机名
10 port: 80  #改http端口
29 external_url: https://domain.com:443   #默认没启用,指定nginx代理上的访问地址,必须写端口号,
34 harbor_admin_password: Harbor12345   #默认admin登陆密码
39 password: root123  #数据库密码,密码不要带?等特殊字符,否则导致clair组件连接不上数据库

注释掉13,15,17,18行

 13 #https:
 15 #  port: 443
 17 #  certificate: /your/certificate/path
 18 #  private_key: /your/private/key/path
项目配置文件修改

修改common/config/nginx/nginx.conf

sed -i 's/proxy_set_header\ X-Forwarded-Proto\ $scheme/#proxy_set_header X-Forwarded-Proto $scheme/' common/config/nginx/nginx.conf
前端nginx代理服务配置
server {
  listen 443 ssl;
  server_name hostname;
  access_log /var/log/nginx/domain.com_nginx.log main;
  include testsslset.conf;
    location / {
       client_max_body_size 1G;
       proxy_pass http://10.10.2.14:81;
       proxy_set_header X-Forwarded-Proto $scheme;   #必须要的参数,否则报401错误
       include proxy.conf;
    }
    location = /50x.html {
      root   html;
    }
}
server {
  listen 80;
  server_name hostname;
  return 301 https://$server_name$request_uri;
}
启用https时

在http的基础上,开启https选项,提供ssl证书

17,18c   # https证书路径
>   certificate: /your/certificate/path
>   private_key: /your/private/key/path

harbor服务管理

cd /opt/harbor/
启动harbor: `docker-compose up -d`
停止harbor:  `docker-compose stop`
重启harbor: `docker-compose restart`
查看harbor状态: `docker-compose ps`

查看harbor日志

harbor通过rsyslog收集日志,日志默认在物理机的/var/log/harbor文件夹中

更新harbor.yml配置

  1. 编写harbor.yml
  2. docker-compose down
  3. 把harbor.yml转化为容器配置文件: bash /opt/harbor/prepare --with-clair --with-chartmuseum
  4. 如果是http+nginx代理模式: sed -i 's/proxy_set_header\ X-Forwarded-Proto\ $scheme/#proxy_set_header X-Forwarded-Proto $scheme/' common/config/nginx/nginx.conf
  5. docker-compose up -d
    注意:数据库密码在第一次初始化后,后面再修改配置的密码,通过prepare更新配置后,会导致容器连接不上数据库,可通过install.sh重新安装处理,记得执行前备份数据

你可能感兴趣的:(harbor2.1安装及管理)