基于 docker-compose 的 Sonatype Nexus OrientDB 到 H2 迁移
基于官方 Sonatype 迁移说明,但针对 Docker 和我们的 5 分钟 Nexus 配置 进行了调整
虽然我更倾向于使用 PostgreSQL 而不是 H2,但显然使用 PostgreSQL 需要 Nexus Pro 许可证,所以这里我们只能使用 H2。
nexus_orientdb_migration.sh
mkdir -p nexus_logs nexus_sonatype_logs
chmod -R 777 nexus_logs nexus_sonatype_logs更改 docker-compose.yml:
docker-compose.yml
services:
nexus:
image: sonatype/nexus3:3.70.0
# ...
volumes:
- "./nexus_data:/nexus-data"
- "./nexus_sonatype_logs:/opt/sonatype/logs"
- "./nexus_logs:/logs"
# ...重启 Nexus:
restart_nexus.sh
docker-compose up -d执行完整的 Nexus 备份使用备份任务 不要跳过,这是迁移工具运行所必需的!
作为备份位置,使用 /nexus-data(因为它挂载到主机,迁移工具需要访问备份文件)。
将备份任务安排在两分钟后的未来一次运行。
等待它完成
关闭 Nexus:
shutdown_nexus.sh
docker-compose down -v下载迁移工具。你需要专门使用 3.70 迁移工具版本 - 更高版本将无法与 OrientDB 一起工作!
download_migrator.sh
cd nexus_data
wget https://download.sonatype.com/nexus/nxrm3-migrator/nexus-db-migrator-3.70.2-01.jar
cd ..运行迁移工具
run_migrator.sh
docker-compose run -u root nexus /bin/bash -c 'chmod 777 /opt/sonatype && chmod -R 777 /opt/sonatype/logs && cp /nexus-data/*.bak /opt/sonatype && java -Xmx16G -Xms16G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M -jar /nexus-data/nexus-db-migrator-* --migration_type=h2 -y && cp /opt/sonatype/nexus.mv.db /nexus-data/db'现在将数据存储配置添加到 nexus_data/etc/nexus.properties:
nexus.properties
nexus.datastore.enabled=true之后,重启你的 Nexus 并检查它是否工作。
验证迁移成功后,从 docker-compose.yml 中删除额外的卷:
docker-compose.yml
- "./nexus_sonatype_logs:/opt/sonatype/logs" # Remove this line!
- "./nexus_logs:/logs" # Remove this line!删除实际目录:
remove_nexus_log_dirs.sh
rm -rf nexus_sonatype_logs nexus_logs并再次重启 Nexus:
final_restart_nexus.sh
docker-compose down
docker-compose up -d此外,你现在可以通过更改 docker-compose.yml 中的镜像版本升级到 3.72.0 或更高版本(不再支持 OrientDB):
docker-compose.yml
image: sonatype/nexus3:3.72.0If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow