部署
运行 nexus3 容器,其默认使用 8081 端口,可以将其转发到其他端口,例如 443
~/go/src/etcd-io/etcd/tools/etcd-dump-db (main ✔) docker run -d -p 443:8081 --name nexus sonatype/nexus3
af9b0952e35105bcd7a2e7080f5e15f0451f71b69e4df123096039f0e9d7ae83
nexus 服务的初始化大概需要 2-3 分钟,可以通过 docker logs 查看进度
docker logs -f nexus
查询 nexus 状态
~/go/src/etcd-io/etcd/tools/etcd-dump-db (main ✔) curl http://localhost:443/ [78/90285]
<!DOCTYPE html>
<html lang="en">
<head>
<title>Nexus Repository Manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="description" content="Nexus Repository Manager"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<!--[if lt IE 9]>
<script>(new Image).src="./static/rapture/resources/favicon.ico?_v=3.37.3-02&_e=OSS"</script>
<![endif]-->
<link rel="icon" type="image/png" href="./static/rapture/resources/favicon-32x32.png?_v=3.37.3-02&_e=OSS" sizes="32x32">
<link rel="mask-icon" href="./static/rapture/resources/safari-pinned-tab.svg?_v=3.37.3-02&_e=OSS" color="#5bbad5">
<link rel="icon" type="image/png" href="./static/rapture/resources/favicon-16x16.png?_v=3.37.3-02&_e=OSS" sizes="16x16">
<link rel="shortcut icon" href="./static/rapture/resources/favicon.ico?_v=3.37.3-02&_e=OSS">
<meta name="msapplication-TileImage" content="./static/rapture/resources/mstile-144x144.png?_v=3.37.3-02&_e=OSS">
<meta name="msapplication-TileColor" content="#00a300">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/loading-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/baseapp-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/nexus-rapture-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/nexus-proximanova-plugin-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/nexus-coreui-plugin-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/nexus-proui-plugin-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/rapture/resources/nexus-onboarding-plugin-prod.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/nexus-rapture-bundle.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/nexus-coreui-bundle.css?_v=3.37.3-02&_e=OSS">
<link rel="stylesheet" type="text/css" href="./static/nexus-proui-bundle.css?_v=3.37.3-02&_e=OSS">
.....
查询 nexus 初始密码,默认用户名为 admin
~/go/src/etcd-io/etcd/tools/etcd-dump-db (main ✔) docker container exec nexus cat nexus-data/admin.password
518bb908-5f68-4cb0-a17d-6496d8febc73
登录界面后需要修改密码。
使用
可以使用 docker exec 进入 nexus 容器里查看相关信息,如下所示。如果要从容器里退出,可以使用快捷键:ctrl+p ctrl+q
~/go/src/etcd-io/etcd/tools/etcd-dump-db (main ✔) docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
af9b0952e351 sonatype/nexus3 "sh -c ${SONATYPE_DI…" 29 minutes ago Up 29 minutes 0.0.0.0:443->8081/tcp, :::443->8081/tcp
nexus
~/go/src/etcd-io/etcd/tools/etcd-dump-db (main ✔) docker exec -ti af9b0952e351 bash
bash-4.4$ ls -al /opt/sonatype/sonatype-work/
total 0
drwxr-xr-x 2 root root 20 Dec 29 2021 .
drwxr-xr-x 1 root root 19 Dec 29 2021 ..
lrwxrwxrwx 1 root root 11 Dec 29 2021 nexus3 -> /nexus-data
bash-4.4$ ls -al /opt/sonatype/sonatype-work/nexus3/
total 24
drwxr-xr-x 15 nexus nexus 254 Aug 18 07:46 .
drwxr-xr-x 1 root root 28 Aug 18 07:42 ..
drwxr-xr-x 3 nexus nexus 21 Aug 18 07:43 blobs
drwxr-xr-x 336 nexus nexus 8192 Aug 18 07:42 cache
drwxr-xr-x 6 nexus nexus 113 Aug 18 07:43 db
drwxr-xr-x 3 nexus nexus 19 Aug 18 07:43 elasticsearch
drwxr-xr-x 3 nexus nexus 45 Aug 18 07:42 etc
drwxr-xr-x 2 nexus nexus 6 Aug 18 07:42 generated-bundles
drwxr-xr-x 2 nexus nexus 33 Aug 18 07:42 instances
drwxr-xr-x 3 nexus nexus 19 Aug 18 07:42 javaprefs
-rw-r--r-- 1 nexus nexus 1 Aug 18 07:42 karaf.pid
drwxr-xr-x 3 nexus nexus 18 Aug 18 07:42 keystores
-rw-r--r-- 1 nexus nexus 14 Aug 18 07:42 lock
drwxr-xr-x 3 nexus nexus 112 Aug 18 07:43 log
drwxr-xr-x 2 nexus nexus 6 Aug 18 07:42 orient
-rw-r--r-- 1 nexus nexus 5 Aug 18 07:42 port
drwxr-xr-x 2 nexus nexus 6 Aug 18 07:42 restore-from-backup
drwxr-xr-x 7 nexus nexus 242 Aug 18 07:43 tmp
Nexus Repository 存储多种类型的数据,其中主要包含两种存储需求:
Embedded data (H2, OrientDB, Elastic Search) requires very responsive, fast storage, ideally local disk
Blob storage (component binaries), which requires moderately responsive, high-capacity storage
可以通过界面操作创建 File/S3 blob storage
通过界面创建 apt repository
注意,创建 hosted apt repository 时需要设置 PGP signing key 和 Passphrase,可以通过如下命令,设置的过程中会要求输入密码。Blob storage 可以使用上面创建的 s3 storage。
gpg --gen-key
gpg --list-keys
gpg --export-secret-key --armor
上传 deb 包
- curl 命令行上传
curl -u "admin:admin" -H "Content-Type: multipart/form-data" --data-binary "@./test.deb" "http://10.9.8.72:443/repository/apt-hosted/"
- 界面上传
2023-08-21 06:24:59,260+0000 INFO [qtp887932152-643] admin org.sonatype.nexus.repository.upload.internal.OrientUploadManagerImpl - Uploading component with parameters: repository="apt-hosted" format="apt"
2023-08-21 06:24:59,260+0000 INFO [qtp887932152-643] admin org.sonatype.nexus.repository.upload.internal.OrientUploadManagerImpl - Asset with parameters: file="hello-world_0.0.1-1_amd64.deb"
如果 pgp 设置不正确,上传 deb 包时会出现java.lang.RuntimeException: org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
错误:
2023-08-18 11:18:40,679+0000 ERROR [qtp887932152-648] admin org.sonatype.nexus.coreui.UploadResource - Unable to perform upload to repository apt-hosted java.lang.RuntimeException: org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
at org.sonatype.nexus.repository.security.GpgUtils.signInline(GpgUtils.java:195) at org.sonatype.nexus.repository.apt.internal.gpg.AptSigningFacet.signInline(AptSigningFacet.java:96)
at org.sonatype.nexus.repository.apt.orient.internal.hosted.OrientAptHostedFacet.rebuildIndexes(OrientAptHostedFacet.java:183) at org.sonatype.nexus.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:49)
at org.sonatype.nexus.repository.apt.orient.internal.hosted.OrientAptHostedFacet.ingestAsset(OrientAptHostedFacet.java:139) at org.sonatype.nexus.transaction.TransactionalWrapper.proceedWithTransaction(TransactionalWrapper.java:58) at org.sonatype.nexus.transaction.TransactionInterceptor.proceedWithTransaction(TransactionInterceptor.java:66)
at org.sonatype.nexus.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:55) at org.sonatype.nexus.repository.apt.orient.internal.hosted.OrientAptHostedFacet.ingestAsset(OrientAptHostedFacet.java:107)
at org.sonatype.nexus.repository.apt.orient.OrientAptUploadHandler.handle(OrientAptUploadHandler.java:69) at org.sonatype.nexus.repository.upload.internal.OrientUploadManagerImpl.handle(OrientUploadManagerImpl.java:109)
at org.sonatype.nexus.coreui.internal.UploadService.upload(UploadService.java:78)
at org.sonatype.nexus.coreui.UploadResource.postComponent(UploadResource.java:86)
at com.palominolabs.metrics.guice.ExceptionMeteredInterceptor.invoke(ExceptionMeteredInterceptor.java:23)
at com.palominolabs.metrics.guice.TimedInterceptor.invoke(TimedInterceptor.java:26)
at org.sonatype.nexus.validation.internal.ValidationInterceptor.invoke(ValidationInterceptor.java:53)
at org.apache.shiro.guice.aop.AopAllianceMethodInvocationAdapter.proceed(AopAllianceMethodInvocationAdapter.java:49)
at org.apache.shiro.authz.aop.AuthorizingAnnotationMethodInterceptor.invoke(AuthorizingAnnotationMethodInterceptor.java:68)
at org.apache.shiro.guice.aop.AopAllianceMethodInterceptorAdapter.invoke(AopAllianceMethodInterceptorAdapter.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
参考链接
https://github.com/sonatype/docker-nexus3
Sonatype Nexus Repository System Requirements
Apt Repositories
https://ahgh.medium.com/how-to-setup-sonatype-nexus-3-repository-manager-using-docker-7ff89bc311ce
https://gist.github.com/marcelmaatkamp/123e8793e07a72a382d8d0e8d66bbd8f
https://www.digitalocean.com/community/tutorials/install-maven-linux-ubuntu