使用docker-compose来安装harbor v2.5.1,安装过程中有一些问题,下面记录一下:
- 下载离线安装包:
1 |
wget https://github.com/goharbor/harbor/releases/download/v2.5.1/harbor-offline-installer-v2.5.1.tgz |
2. 准备docker-compose.yml和harbor.yml:
docker-compose.yml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
version: '2.3' services: log: image: goharbor/harbor-log:v2.5.1 container_name: harbor-log restart: always cap_drop: - ALL cap_add: - CHOWN - DAC_OVERRIDE - SETGID - SETUID volumes: - /ali-nas/harbor/log/:/var/log/docker/:z - type: bind source: ./common/config/log/logrotate.conf target: /etc/logrotate.d/logrotate.conf - type: bind source: ./common/config/log/rsyslog_docker.conf target: /etc/rsyslog.d/rsyslog_docker.conf ports: - 127.0.0.1:1514:10514 networks: - harbor registry: image: goharbor/registry-photon:v2.5.1 container_name: registry restart: always cap_drop: - ALL cap_add: - CHOWN - SETGID - SETUID volumes: - /ali-nas/harbor/registry:/storage:z - ./common/config/registry/:/etc/registry/:z - type: bind source: /ali-nas/harbor/secret/registry/root.crt target: /etc/registry/root.crt - type: bind source: ./common/config/shared/trust-certificates target: /harbor_cust_cert networks: - harbor depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "registry" registryctl: image: goharbor/harbor-registryctl:v2.5.1 container_name: registryctl env_file: - ./common/config/registryctl/env restart: always cap_drop: - ALL cap_add: - CHOWN - SETGID - SETUID volumes: - /ali-nas/harbor/registry:/storage:z - ./common/config/registry/:/etc/registry/:z - type: bind source: ./common/config/registryctl/config.yml target: /etc/registryctl/config.yml - type: bind source: ./common/config/shared/trust-certificates target: /harbor_cust_cert networks: - harbor depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "registryctl" postgresql: image: goharbor/harbor-db:v2.5.1 container_name: harbor-db restart: always cap_drop: - ALL cap_add: - CHOWN - DAC_OVERRIDE - SETGID - SETUID volumes: - /ali-nas/harbor/database:/var/lib/postgresql/data:z networks: harbor: env_file: - ./common/config/db/env depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "postgresql" shm_size: '1gb' core: image: goharbor/harbor-core:v2.5.1 container_name: harbor-core env_file: - ./common/config/core/env restart: always cap_drop: - ALL cap_add: - SETGID - SETUID volumes: - /ali-nas/harbor/ca_download/:/etc/core/ca/:z - /ali-nas/harbor/:/data/:z - ./common/config/core/certificates/:/etc/core/certificates/:z - type: bind source: ./common/config/core/app.conf target: /etc/core/app.conf - type: bind source: /ali-nas/harbor/secret/core/private_key.pem target: /etc/core/private_key.pem - type: bind source: /ali-nas/harbor/secret/keys/secretkey target: /etc/core/key - type: bind source: ./common/config/shared/trust-certificates target: /harbor_cust_cert networks: harbor: depends_on: - log - registry - redis - postgresql logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "core" portal: image: goharbor/harbor-portal:v2.5.1 container_name: harbor-portal restart: always cap_drop: - ALL cap_add: - CHOWN - SETGID - SETUID - NET_BIND_SERVICE volumes: - type: bind source: ./common/config/portal/nginx.conf target: /etc/nginx/nginx.conf networks: - harbor depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "portal" jobservice: image: goharbor/harbor-jobservice:v2.5.1 container_name: harbor-jobservice env_file: - ./common/config/jobservice/env restart: always cap_drop: - ALL cap_add: - CHOWN - SETGID - SETUID volumes: - /ali-nas/harbor/job_logs:/var/log/jobs:z - type: bind source: ./common/config/jobservice/config.yml target: /etc/jobservice/config.yml - type: bind source: ./common/config/shared/trust-certificates target: /harbor_cust_cert networks: - harbor depends_on: - core logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "jobservice" redis: image: goharbor/redis-photon:v2.5.1 container_name: redis restart: always cap_drop: - ALL cap_add: - CHOWN - SETGID - SETUID volumes: - /ali-nas/harbor/redis:/var/lib/redis networks: harbor: depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "redis" proxy: image: goharbor/nginx-photon:v2.5.1 container_name: nginx restart: always cap_drop: - ALL cap_add: - CHOWN - SETGID - SETUID - NET_BIND_SERVICE volumes: - ./common/config/nginx:/etc/nginx:z - type: bind source: ./common/config/shared/trust-certificates target: /harbor_cust_cert networks: - harbor ports: - 81:8080 depends_on: - registry - core - portal - log logging: driver: "syslog" options: syslog-address: "tcp://localhost:1514" tag: "proxy" networks: harbor: external: false |
harbor.yml文件需要更改hostname, 监听port, 如果不开启ssl, 则注释掉https, 更改harbor_admin_password,和data_volume
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
hostname: 172.20.47.2 http: port: 81 harbor_admin_password: xxxxx database: password: root123 max_idle_conns: 100 max_open_conns: 900 data_volume: /ali-nas/harbor trivy: ignore_unfixed: false skip_update: false insecure: false jobservice: max_job_workers: 10 notification: webhook_job_max_retry: 10 chart: absolute_url: disabled log: level: info local: rotate_count: 50 rotate_size: 200M location: /ali-nas/harbor/log _version: 2.5.0 proxy: http_proxy: https_proxy: no_proxy: components: - core - jobservice - trivy |
执行完docker-compose up -d后, 容器全部启来了, 但是再执行docker-compose down后, 再执行install.sh,或up启动,发现有几个问题:
docker-compose up启动报错:
Creating harbor-log … error
ERROR: for harbor-log Cannot start service log: driver failed programming external connectivity on endpoint harbor-log (cb1338bb88ec65aba9727cb1e7656e6c44b3705095121e27ab9240a66cda1ef1): (iptables failed: iptables –wait -t filter -A DOCKER ! -i br-0f9ec40ce6de -o br-0f9ec40ce6de -p tcp -d 172.19.0.2 –dport 10514 -j ACCEPT: iptables: No chain/target/match by that name.
(exit status 1))
解决:
清空防火墙规则,重启docker
1 2 3 |
iptables -t filter -F iptables -t filter -X systemctl restart docker |
db启不来:
1 2 3 4 5 6 7 8 9 10 11 |
[root@jenkins1-iuap-hb2-ali harbor]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d267f6d99c67 goharbor/harbor-jobservice:v2.5.1 "/harbor/entrypoint.…" 11 seconds ago Up 10 seconds (health: starting) harbor-jobservice 0c4f2765b0e6 goharbor/nginx-photon:v2.5.1 "nginx -g 'daemon of…" 11 seconds ago Up 10 seconds (health: starting) 0.0.0.0:81->8080/tcp nginx 37cc2b8f57a1 goharbor/harbor-core:v2.5.1 "/harbor/entrypoint.…" 12 seconds ago Up 11 seconds (health: starting) harbor-core b2dc0d880539 goharbor/harbor-registryctl:v2.5.1 "/home/harbor/start.…" 14 seconds ago Up 13 seconds (health: starting) registryctl ec3512194643 goharbor/registry-photon:v2.5.1 "/home/harbor/entryp…" 14 seconds ago Up 13 seconds (health: starting) registry a1ef1603f023 goharbor/harbor-portal:v2.5.1 "nginx -g 'daemon of…" 14 seconds ago Up 12 seconds (health: starting) harbor-portal 8fab8be81294 goharbor/harbor-db:v2.5.1 "/docker-entrypoint.…" 14 seconds ago Restarting (1) 2 seconds ago harbor-db 132ff3a7ca1f goharbor/redis-photon:v2.5.1 "redis-server /etc/r…" 14 seconds ago Up 13 seconds (health: starting) redis e522a4651d13 goharbor/harbor-log:v2.5.1 "/bin/sh -c /usr/loc…" 14 seconds ago Up 14 seconds (health: starting) 127.0.0.1:1514->10514/tcp harbor-log |
看日志log/postgresql.log :
1 |
initdb: error: directory "/var/lib/postgresql/data/pg13" exists but is not empty |
参考https://github.com/goharbor/harbor/issues/15464, 方案为在docker-compose.yml的postgresql 里加privileged: true,或升级docker到20版本:
升级docker:
1 2 3 4 5 6 7 8 9 10 11 12 |
#卸载旧版本: yum remove docker-ce-cli yum remove docker-ce docker-compose #添加阿里源 yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #或者可以添加清华源: yum-config-manager \ --add-repo \ https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo #也可以这样安装 curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun |
harbor-db报以下错误:
initdb: error: could not access directory “/var/lib/postgresql/data/pg13”: Permission denied
解决:首先确保harbor.yml的data_volume: 项配置路径正确,然后将harbor目录下的database目录更新权限: chown -R systemd-bus-proxy:ssh_keys database
重启后发现core启不来:
1 2 3 4 5 6 7 8 9 10 11 |
[root@jenkins1-iuap-hb2-ali harbor]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e9ed4d7f3334 goharbor/harbor-jobservice:v2.5.1 "/harbor/entrypoint.…" 6 seconds ago Up 5 seconds (health: starting) harbor-jobservice de1b1456b191 goharbor/nginx-photon:v2.5.1 "nginx -g 'daemon of…" 6 seconds ago Up 5 seconds (health: starting) 0.0.0.0:81->8080/tcp nginx ade1c94566c7 goharbor/harbor-core:v2.5.1 "/harbor/entrypoint.…" 7 seconds ago Restarting (1) Less than a second ago harbor-core ce62153d1f33 goharbor/harbor-db:v2.5.1 "/docker-entrypoint.…" 8 seconds ago Up 7 seconds (health: starting) harbor-db c16f031748da goharbor/registry-photon:v2.5.1 "/home/harbor/entryp…" 8 seconds ago Up 7 seconds (health: starting) registry 6b106044330b goharbor/harbor-portal:v2.5.1 "nginx -g 'daemon of…" 8 seconds ago Up 7 seconds (health: starting) harbor-portal 08a6ddceb094 goharbor/harbor-registryctl:v2.5.1 "/home/harbor/start.…" 8 seconds ago Up 7 seconds (health: starting) registryctl f23a44f58e12 goharbor/redis-photon:v2.5.1 "redis-server /etc/r…" 8 seconds ago Up 7 seconds (health: starting) redis 4e0ddada724b goharbor/harbor-log:v2.5.1 "/bin/sh -c /usr/loc…" 8 seconds ago Up 8 seconds (health: starting) 127.0.0.1:1514->10514/tcp harbor-log |
看日志是failed to connect to host=postgresql user=po stgres database=registry
: server error (FATAL: database “registry” does not exist (SQLSTATE 3)
参考https://github.com/goharbor/harbor-helm/issues/145,手动创建registry表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#Execute into the container docker exec -it harbor-db bash #Execute into the container kubectl exec -it harbor-harbor-database-0 -n harbor /bin/bash #Connect the database psql --username postgres #Run the initial scripts line by line manually postgres=# CREATE DATABASE registry ENCODING 'UTF8'; CREATE DATABASE postgres=# \c registry; You are now connected to database "registry" as user "postgres". registry=# CREATE TABLE schema_migrations(version bigint not null primary key, dirty boolean not null); CREATE TABLE #Now everything is perfect. |
0 Comments