Nexus部署和使用
1 . 私服简介
私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
我们可以使用专门的 Maven 仓库管理软件来搭建私服,比如:Apache Archiva,Artifactory,Sonatype Nexus。这里我们使用 Sonatype Nexus。
2 . 安装Nexus
2.1 下载Nexus
Nexus 专业版是需要付费的,这里我们下载开源版 Nexus OSS。Nexus 提供两种安装包,一种是包含 Jetty 容器的 bundle 包,另一种是不包含容器的 war 包。下载地址:https://help.sonatype.com/display/NXRM2/Download+Archives+-+Repository+Manager+OSS
2.2 安装nexus
添加用户:
groupadd nexus useradd -d /home/nexus -g nexus nexus |
下载好以后,使用如下命令对nexus-2.14.15-01-bundle.tar.gz进行解压
tar –zxvf nexus-2.14.15-01-bundle.tar.gz
解压完以后会得到两个目录:nexus-2.14.15-01 和 sonatype-work,一个放的是nexus程序,一个放的是仓库类信息。
nexus-2.14.15-01目录下存放着如下目录
|
Bin:可执行文件
Lib:库文件
配置nexus
# Jetty section application-port=8081 application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexus nexus-webapp-context-path=/nexus
# Nexus section nexus-work=${bundleBasedir}/../sonatype-work/nexus runtime=${bundleBasedir}/nexus/WEB-INF
# orientdb buffer size in megabytes storage.diskCache.bufferSize=4096 |
启动nexus,在启动前确保java环境以及安装好了。
|
启动nexus:
到bin目录下:./nexus start
访问nexus
在浏览器进行访问。地址:http://ip:端口/nexus
3配置nexus
Nexus常用功能就是:指定私服的中央地址、将自己的Maven项目指定到私服地址、从私服下载中央库的项目索引、从私服仓库下载依赖组件、将第三方项目jar上传到私服供其他项目组使用。
开启Nexus服务后访问url地址http://localhost:8081/nexus/(推荐使用自己的ip地址),之后登录系统,用户名密码分别是:admin/admin123.
最频繁的就是点击左侧菜单栏的Repositories按钮
一般用到的仓库种类是hosted、proxy。Hosted代表宿主仓库,用来发布一些第三方不允许的组件,比如Oracle驱动、比如商业软件jar包。Proxy代表代理远程的仓库,最典型的就是Maven官方中央仓库、JBoss仓库等等。如果构建的Maven项目本地仓库没有依赖包,那么就会去这个代理站点去下载,那么如果代理站点也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。代理站点下载成功后再下载至本机。笔者认为,其实Maven这个自带的默认仓库一般情况下已经够大多数项目使用了。特殊情况时在配置新的仓库,指定url即可,一般熟悉ExtJS的人操作这个Nexus都没什么问题,单词不是很难,不明白的查查单词基本差不多。就是如果Sonatype公司对其做了国际化的处理就更好了。
(1)hosted 类型的仓库,内部项目的发布仓库
(2)releases内部的模块中release模块的发布仓库
(3)snapshots发布内部的SNAPSHOT模块的仓库
(4)3rd party第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
(5)proxy 类型的仓库,从远程中央仓库中寻找数据的仓库
(6)group 类型的仓库,组仓库用来方便我们开发人员进行设置的仓库
maven项目索引
下载Maven项目索引,项目索引是为了使用者能够在私服站点查找依赖使用的功能
保存后后台会运行一个任务,点击菜单栏的Scheduled Tasks选项即可看到有个任务在RUNNING。 下载完成后,Maven索引就可以使用了,在搜索栏输入要搜索的项,就可以查到相关的信息。例如spring-core
就可以检索出它的相关信息,包括怎么配置依赖信息。我们要想使用这个私服仓库,先在项目pom中配置相关私服信息指定仓库。
<repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://192.168.0.166:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> |
指定插件仓库:
<pluginRepositories> <pluginRepository> <id>nexus</id> <name>nexus</name> <url>http://192.168.0.166:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> |
这样只有本项目才在私服下载组件
这样这个Maven项目构建的时候会从私服下载相关依赖。当然这个配置仅仅是在此项目中生效,对于其他项目还是不起作用。如果相对Maven的其他项目也生效的话。需要修改全局的settings.xml文件。
<profile> <id>nexusProfile</id> <repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://192.168.0.166:8081/nexus/content/groups/public/</url> <layout>default</layout> <releases> <enabled>true</enabled> </releases> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> |
追加激活profile:
<activeProfiles> <activeProfile>central</activeProfile> </activeProfiles> |
之后所有本机的Maven项目就在私服下载组件。(这样比较好)
项目的发布,在项目的pom文件中添加如下配置:
<distributionManagement> <repository> <id>user-release</id> <name>User Project Release</name> <url>http://192.168.0.166:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>user-snapshots</id> <name>User Project SNAPSHOTS</name> <url>http://192.168.0.166:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> |
注意配置了还是发布项目到私服失败,原因为没有权限
配置权限在settings.xml
<server> <id>user-snapshots</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>user-release</id> <username>deployment</username> <password>deployment123</password> </server> |
然后运行发布
clean deploy
在控制台发布成功
然后进入到私服上的仓库中,看一下确实存在刚刚发布的项目
宿主库——3rd party
假如我们下载了Oracle的驱动程序jar包想给其他项目组使用,就需要上传该jar包。选中宿主库——3rd party,之后选择Artifact Upload上传至宿主空间。
最后点击上传
3.1索引更新
(1) 在线更新索引
安装配置完成Nexus后,电脑联网状态下,Nexus会自动下载索引文件。下载好的索引文件存放在目录:sonatype-work\nexus\indexer
(2) 手动更新索引
网络环境不佳,或者在线更新有问题时,可以选择手动添加索引方式。
到http://repo.maven.apache.org/maven2/.index/上下载:
到http://search.maven.org下载特定解压文indexer-cli-5.1.1.jar
把这几个文件放在同一个文件路径下面,从cmd进入到这个路径里,输入命令:
nohup java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.613.gz -d indexer & |
执行完之后,把indexer文件夹下的所有内容都复制到%nexus-home%\sonatype-work\nexus\indexer\central-ctx下面。
重新启动nexus,进入管理界面,选择central->Browse Index,就看到更新的索引了。
注意:nexus是需要重新启动的,我是在做上面的所有步骤之前,先停掉nexus,等上面四个步骤完成之后,再启动nexus的。
仓库迁移
Nexus的构件仓库都保存在sonatype-work目录中,该目录的位置由nexus/conf/nexus.properties配置文件指定。
仓库迁移需要两个过程:备份和还原
备份仓库:将sonatype-work文件夹整体备份即可,也可以选择只备份最重要的两个文件夹索引(indexer)和仓库(storage)
还原仓库:将备份好的sonatype-work文件拷贝到新的服务器中。然后修改nexus/conf/nexus.properties配置文件,重新指定仓库的目录。
@@@部署和使用
安装nexus
https://www.cnblogs.com/karmapeng/p/11968511.html
[root@mcw15 ~]# mv nexus-3.71.0-06-unix.tar.gz /opt/ [root@mcw15 ~]# cd /opt/ [root@mcw15 opt]# [root@mcw15 opt]# groupadd nexus [root@mcw15 opt]# useradd -d /home/nexus -g nexus nexus [root@mcw15 opt]# ls nexus-3.71.0-06-unix.tar.gz rakudo-pkg [root@mcw15 opt]# tar xf nexus-3.71.0-06-unix.tar.gz [root@mcw15 opt]# ls nexus-3.71.0-06 nexus-3.71.0-06-unix.tar.gz rakudo-pkg sonatype-work [root@mcw15 opt]# ls nexus-3.71.0-06 bin deploy etc lib NOTICE.txt OSS-LICENSE.txt PRO-LICENSE.txt public replicator system [root@mcw15 opt]# ls sonatype-work/ nexus3 [root@mcw15 opt]# ls sonatype-work/nexus3/ clean_cache log tmp [root@mcw15 opt]#
没改
[root@mcw15 etc]# pwd /opt/nexus-3.71.0-06/etc [root@mcw15 etc]# ls fabric jetty karaf logback nexus-default.properties ssl [root@mcw15 etc]# cat nexus-default.properties ## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties ## # Jetty section application-port=8081 application-host=0.0.0.0 nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml nexus-context-path=/ # Nexus section nexus-edition=nexus-pro-edition nexus-features=\ nexus-pro-feature [root@mcw15 etc]#
启动提示用的是root,程序好像没起来
[root@mcw15 etc]# pwd /opt/nexus-3.71.0-06/etc [root@mcw15 etc]# ls fabric jetty karaf logback nexus-default.properties ssl [root@mcw15 etc]# cat nexus-default.properties ## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties ## # Jetty section application-port=8081 application-host=0.0.0.0 nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml nexus-context-path=/ # Nexus section nexus-edition=nexus-pro-edition nexus-features=\ nexus-pro-feature [root@mcw15 etc]#
我们修改一些端口为9081
[root@mcw15 etc]# pwd /opt/nexus-3.71.0-06/etc [root@mcw15 etc]# ls fabric jetty karaf logback nexus-default.properties ssl [root@mcw15 etc]# cat nexus-default.properties ## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties ## # Jetty section application-port=9081 application-host=0.0.0.0 nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml nexus-context-path=/ # Nexus section nexus-edition=nexus-pro-edition nexus-features=\ nexus-pro-feature [root@mcw15 etc]#
切换用户并启动服务
[root@mcw15 etc]# su - nexus [nexus@mcw15 ~]$ cd /opt/ nexus-3.71.0-06/ rakudo-pkg/ sonatype-work/ [nexus@mcw15 ~]$ cd /opt/nexus-3.71.0-06/bin/ [nexus@mcw15 bin]$ ./nexus start Starting nexus [nexus@mcw15 bin]$ exit
[root@mcw15 etc]# netstat -lntup|grep 9081 tcp6 0 0 :::9081 :::* LISTEN 19808/java [root@mcw15 etc]#
访问内存溢出了
可以看到默认的内存大于机器剩余内存
[root@mcw15 etc]# ls fabric jetty karaf logback nexus-default.properties nexus.properties ssl [root@mcw15 etc]# cd .. [root@mcw15 nexus-3.71.0-06]# ls bin deploy etc lib NOTICE.txt OSS-LICENSE.txt PRO-LICENSE.txt public replicator system [root@mcw15 nexus-3.71.0-06]# ls bin/ contrib nexus nexus.rc nexus.vmoptions [root@mcw15 nexus-3.71.0-06]# pwd /opt/nexus-3.71.0-06 [root@mcw15 nexus-3.71.0-06]# vim bin/nexus.vmoptions [root@mcw15 nexus-3.71.0-06]# free -mh total used free shared buff/cache available Mem: 3.7G 2.1G 112M 16M 1.5G 1.2G Swap: 4.0M 2.0M 2.0M [root@mcw15 nexus-3.71.0-06]# vim bin/nexus.vmoptions [root@mcw15 nexus-3.71.0-06]# head bin/nexus.vmoptions -Xms2703m -Xmx2703m -XX:MaxDirectMemorySize=2703m -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=../sonatype-work/nexus3/log/jvm.log -XX:-OmitStackTraceInFastThrow -Dkaraf.home=. -Dkaraf.base=. [root@mcw15 nexus-3.71.0-06]#
降低内存,并重启服务
[root@mcw15 nexus-3.71.0-06]# ls bin deploy etc lib NOTICE.txt OSS-LICENSE.txt PRO-LICENSE.txt public replicator system [root@mcw15 nexus-3.71.0-06]# [root@mcw15 nexus-3.71.0-06]# [root@mcw15 nexus-3.71.0-06]# vim bin/nexus.vmoptions [root@mcw15 nexus-3.71.0-06]# head bin/nexus.vmoptions -Xms1024m -Xmx1024m -XX:MaxDirectMemorySize=1024m -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=../sonatype-work/nexus3/log/jvm.log -XX:-OmitStackTraceInFastThrow -Dkaraf.home=. -Dkaraf.base=. [root@mcw15 nexus-3.71.0-06]# su - nexus Last login: Fri Aug 16 01:02:18 CST 2024 on pts/0 [nexus@mcw15 ~]$ cd /opt/nexus-3.71.0-06/bin/ [nexus@mcw15 bin]$ ./nexus restart Shutting down nexus Could not stop daemon. Restarting nexus [nexus@mcw15 bin]$
然后访问,可以正常进入了http://10.0.0.25:9081/
这里还没登陆
[nexus@mcw15 bin]$ cat /opt/sonatype-work/nexus3/admin.password
8c8d16fc-3eba-41e5-b57d-dcb2fa277555[nexus@mcw15 bin]$
登录之后让修改密码
修改密码为123456,开启匿名访问
maven项目中使用nexus
正常打包
[root@mcw12 demo1]# ls HELP.md mvnw mvnw.cmd pom.xml src target [root@mcw12 demo1]# rm -rf target/ [root@mcw12 demo1]# ls HELP.md mvnw mvnw.cmd pom.xml src [root@mcw12 demo1]# mvn clean package [INFO] Scanning for projects... [INFO] [INFO] -------------------------< org.example:demo1 >-------------------------- [INFO] Building demo1 0.0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:3.3.2:clean (default-clean) @ demo1 --- [INFO] [INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ demo1 --- [INFO] Copying 1 resource from src/main/resources to target/classes [INFO] Copying 1 resource from src/main/resources to target/classes [INFO] [INFO] --- maven-compiler-plugin:3.13.0:compile (default-compile) @ demo1 --- [INFO] Recompiling the module because of changed source code. [INFO] Compiling 3 source files with javac [debug parameters release 17] to target/classes [INFO] [INFO] --- maven-resources-plugin:3.3.1:testResources (default-testResources) @ demo1 --- [INFO] skip non existing resourceDirectory /root/demo1/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.13.0:testCompile (default-testCompile) @ demo1 --- [INFO] Recompiling the module because of changed dependency. [INFO] Compiling 1 source file with javac [debug parameters release 17] to target/test-classes [INFO] [INFO] --- maven-surefire-plugin:3.2.5:test (default-test) @ demo1 --- [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.example.demo.Demo1ApplicationTests 01:46:43.907 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.Demo1ApplicationTests]: Demo1ApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 01:46:44.132 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.Demo1Application for test class com.example.demo.Demo1ApplicationTests . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.3.1) 2024-08-16T01:46:46.149+08:00 INFO 55096 --- [demo1] [ main] com.example.demo.Demo1ApplicationTests : Starting Demo1ApplicationTests using Java 17.0.11 with PID 55096 (started by root in /root/demo1) 2024-08-16T01:46:46.155+08:00 INFO 55096 --- [demo1] [ main] com.example.demo.Demo1ApplicationTests : No active profile set, falling back to 1 default profile: "default" 2024-08-16T01:46:51.264+08:00 INFO 55096 --- [demo1] [ main] com.example.demo.Demo1ApplicationTests : Started Demo1ApplicationTests in 6.356 seconds (process running for 9.809) Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.31 s -- in com.example.demo.Demo1ApplicationTests [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- maven-war-plugin:3.4.0:war (default-war) @ demo1 --- [INFO] Packaging webapp [INFO] Assembling webapp [demo1] in [/root/demo1/target/demo1-0.0.1-SNAPSHOT] [INFO] Processing war project [INFO] Building war: /root/demo1/target/demo1-0.0.1-SNAPSHOT.war [INFO] [INFO] --- spring-boot-maven-plugin:3.3.1:repackage (repackage) @ demo1 --- [INFO] Replacing main artifact /root/demo1/target/demo1-0.0.1-SNAPSHOT.war with repackaged archive, adding nested dependencies in BOOT-INF/. [INFO] The original artifact has been renamed to /root/demo1/target/demo1-0.0.1-SNAPSHOT.war.original [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 26.442 s [INFO] Finished at: 2024-08-16T01:46:59+08:00 [INFO] ------------------------------------------------------------------------ [root@mcw12 demo1]# ls HELP.md mvnw mvnw.cmd pom.xml src target [root@mcw12 demo1]#
删除本地仓库
[root@mcw12 demo1]# ls /root/.m2/repository/ antlr backport-util-concurrent ch com commons-cli commons-collections commons-lang io javax junit net oro xmlpull aopalliance biz classworlds commons-beanutils commons-codec commons-io commons-logging jakarta joda-time log4j org regexp xpp3 [root@mcw12 demo1]# rm -rf /root/.m2/repository/* [root@mcw12 demo1]# ls /root/.m2/repository/
copy地址
生成配置
<repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://10.0.0.25:9081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
加到项目的pom.xml里面
此时本地仓库没有东西
私有服也没有包
不过貌似这里看,这个仓库是不可用的,不如直接换成中央的那个试试
直接修改maven全局仓库配置
<mirror> <id>nexus-mirror</id> <mirrorOf>*</mirrorOf> <url>http://10.0.0.25:9081/repository/maven-public/</url> </mirror>
[root@mcw12 demo1]# which mvn /opt/apache-maven-3.8.8/bin/mvn [root@mcw12 demo1]# ls /opt/apache-maven-3.8.8/conf/settings.xml /opt/apache-maven-3.8.8/conf/settings.xml [root@mcw12 demo1]#
删除本地仓库后,开始打包,可以看到开始从新部署的私服里面去下载。不过私服里面还没任何包。私服应该去官方仓库那里要下载到私服里面,才能提供mcw12下载包到本服务器。
一开始是空的,可以看到已经有了,不过很慢
查看下载速度,很慢
刷新页面,可以看到私服里面有很多了
可以看到,本地仓库也已经有了。下次本地仓库需要包,直接去私服里面下载
已经打包完成
查看中央仓库,里面也有了。之前没有
maven项目发布到nexus私服,然后下载并启动项目
项目的pom.xml文件里添加如下配置
<distributionManagement> <repository> <id>user-release</id> <name>User Project Release</name> <url>http://10.0.0.25:9081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>user-snapshots</id> <name>User Project SNAPSHOTS</name> <url>http://10.0.0.25:9081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
查看这两个
都是空的
发布,报错未认证
[root@mcw12 demo1]# vim pom.xml [root@mcw12 demo1]# [root@mcw12 demo1]# ls HELP.md mvnw mvnw.cmd pom.xml src target [root@mcw12 demo1]# mvn clean deploy [INFO] Scanning for projects... [INFO] [INFO] -------------------------< org.example:demo1 >-------------------------- [INFO] Building demo1 0.0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ war ]--------------------------------- Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-install-plugin/3.1.2/maven-install-plugin-3.1.2.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-install-plugin/3.1.2/maven-install-plugin-3.1.2.pom (8.5 kB at 6.3 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-plugins/42/maven-plugins-42.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-plugins/42/maven-plugins-42.pom (7.7 kB at 15 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/maven-parent/42/maven-parent-42.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/maven-parent/42/maven-parent-42.pom (50 kB at 66 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/apache/32/apache-32.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/apache/32/apache-32.pom (24 kB at 38 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-install-plugin/3.1.2/maven-install-plugin-3.1.2.jar Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-install-plugin/3.1.2/maven-install-plugin-3.1.2.jar (32 kB at 54 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-deploy-plugin/3.1.2/maven-deploy-plugin-3.1.2.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-deploy-plugin/3.1.2/maven-deploy-plugin-3.1.2.pom (9.6 kB at 13 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-deploy-plugin/3.1.2/maven-deploy-plugin-3.1.2.jar Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/plugins/maven-deploy-plugin/3.1.2/maven-deploy-plugin-3.1.2.jar (40 kB at 57 kB/s) [INFO] [INFO] --- maven-clean-plugin:3.3.2:clean (default-clean) @ demo1 --- [INFO] Deleting /root/demo1/target [INFO] [INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ demo1 --- [INFO] Copying 1 resource from src/main/resources to target/classes [INFO] Copying 1 resource from src/main/resources to target/classes [INFO] [INFO] --- maven-compiler-plugin:3.13.0:compile (default-compile) @ demo1 --- [INFO] Recompiling the module because of changed source code. [INFO] Compiling 3 source files with javac [debug parameters release 17] to target/classes [INFO] [INFO] --- maven-resources-plugin:3.3.1:testResources (default-testResources) @ demo1 --- [INFO] skip non existing resourceDirectory /root/demo1/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.13.0:testCompile (default-testCompile) @ demo1 --- [INFO] Recompiling the module because of changed dependency. [INFO] Compiling 1 source file with javac [debug parameters release 17] to target/test-classes [INFO] [INFO] --- maven-surefire-plugin:3.2.5:test (default-test) @ demo1 --- [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.example.demo.Demo1ApplicationTests 23:01:39.842 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.Demo1ApplicationTests]: Demo1ApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 23:01:40.013 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.Demo1Application for test class com.example.demo.Demo1ApplicationTests . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.3.1) 2024-08-16T23:01:40.728+08:00 INFO 127549 --- [demo1] [ main] com.example.demo.Demo1ApplicationTests : Starting Demo1ApplicationTests using Java 17.0.11 with PID 127549 (started by root in /root/demo1) 2024-08-16T23:01:40.729+08:00 INFO 127549 --- [demo1] [ main] com.example.demo.Demo1ApplicationTests : No active profile set, falling back to 1 default profile: "default" 2024-08-16T23:01:44.475+08:00 INFO 127549 --- [demo1] [ main] com.example.demo.Demo1ApplicationTests : Started Demo1ApplicationTests in 4.122 seconds (process running for 6.185) Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.388 s -- in com.example.demo.Demo1ApplicationTests [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- maven-war-plugin:3.4.0:war (default-war) @ demo1 --- [INFO] Packaging webapp [INFO] Assembling webapp [demo1] in [/root/demo1/target/demo1-0.0.1-SNAPSHOT] [INFO] Processing war project [INFO] Building war: /root/demo1/target/demo1-0.0.1-SNAPSHOT.war [INFO] [INFO] --- spring-boot-maven-plugin:3.3.1:repackage (repackage) @ demo1 --- [INFO] Replacing main artifact /root/demo1/target/demo1-0.0.1-SNAPSHOT.war with repackaged archive, adding nested dependencies in BOOT-INF/. [INFO] The original artifact has been renamed to /root/demo1/target/demo1-0.0.1-SNAPSHOT.war.original [INFO] [INFO] --- maven-install-plugin:3.1.2:install (default-install) @ demo1 --- Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-util/1.9.18/maven-resolver-util-1.9.18.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-util/1.9.18/maven-resolver-util-1.9.18.pom (2.9 kB at 5.7 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver/1.9.18/maven-resolver-1.9.18.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver/1.9.18/maven-resolver-1.9.18.pom (22 kB at 38 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-api/1.9.18/maven-resolver-api-1.9.18.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-api/1.9.18/maven-resolver-api-1.9.18.pom (2.7 kB at 4.8 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/codehaus/plexus/plexus-utils/4.0.1/plexus-utils-4.0.1.pom Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/codehaus/plexus/plexus-utils/4.0.1/plexus-utils-4.0.1.pom (7.8 kB at 14 kB/s) Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-util/1.9.18/maven-resolver-util-1.9.18.jar Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-api/1.9.18/maven-resolver-api-1.9.18.jar Downloading from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/codehaus/plexus/plexus-utils/4.0.1/plexus-utils-4.0.1.jar Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-util/1.9.18/maven-resolver-util-1.9.18.jar (196 kB at 153 kB/s) Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/codehaus/plexus/plexus-utils/4.0.1/plexus-utils-4.0.1.jar (193 kB at 100 kB/s) Downloaded from nexus-mirror: http://10.0.0.25:9081/repository/maven-public/org/apache/maven/resolver/maven-resolver-api/1.9.18/maven-resolver-api-1.9.18.jar (157 kB at 48 kB/s) [INFO] Installing /root/demo1/pom.xml to /root/.m2/repository/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-SNAPSHOT.pom [INFO] Installing /root/demo1/target/demo1-0.0.1-SNAPSHOT.war to /root/.m2/repository/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-SNAPSHOT.war [INFO] [INFO] --- maven-deploy-plugin:3.1.2:deploy (default-deploy) @ demo1 --- Downloading from user-snapshots: http://10.0.0.25:9081/repository/maven-snapshots/org/example/demo1/0.0.1-SNAPSHOT/maven-metadata.xml Uploading to user-snapshots: http://10.0.0.25:9081/repository/maven-snapshots/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-20240816.150127-1.pom Uploading to user-snapshots: http://10.0.0.25:9081/repository/maven-snapshots/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-20240816.150127-1.war [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 28.917 s [INFO] Finished at: 2024-08-16T23:01:56+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.1.2:deploy (default-deploy) on project demo1: Failed to deploy artifacts: Could not transfer artifact org.example:demo1:pom:0.0.1-20240816.150127-1 from/to user-snapshots (http://10.0.0.25:9081/repository/maven-snapshots/): authentication failed for http://10.0.0.25:9081/repository/maven-snapshots/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-20240816.150127-1.pom, status: 401 Unauthorized -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException [root@mcw12 demo1]#
之前上面的pom.xml里面配置了id,但是在maven的setting里面没有配置这个id,需要配置一下,指定nexus的用户和密码
<server> <id>user-snapshots</id> <username>admin</username> <password>123456</password> </server> <server> <id>user-release</id> <username>admin</username> <password>123456</password> </server>
然后再次执行部署,可以看的已经在往nexus私服上传
私服上可以看到我们的war包
点击查看信息
release里面还没有
复制上面的地址看看是否能下载,不可以,下载的是个index.html文件
要想下载,可以用仓库地址,拼接上path
我上传的这个仓库地址是:http://10.0.0.25:9081/repository/maven-snapshots/,配置文件,或者页面中可以copy出来
如下,成功下载
[root@mcw12 mcw]# ls consul consul_1.18.1_linux_amd64.zip index.html test [root@mcw12 mcw]# wget http://10.0.0.25:9081/repository/maven-snapshots/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-20240816.151037-1.war --2024-08-16 23:23:14-- http://10.0.0.25:9081/repository/maven-snapshots/org/example/demo1/0.0.1-SNAPSHOT/demo1-0.0.1-20240816.151037-1.war Connecting to 10.0.0.25:9081... connected. HTTP request sent, awaiting response... 200 OK Length: 20274638 (19M) [application/java-archive] Saving to: ‘demo1-0.0.1-20240816.151037-1.war’ 100%[===========================================================================================================================================>] 20,274,638 109MB/s in 0.2s 2024-08-16 23:23:15 (109 MB/s) - ‘demo1-0.0.1-20240816.151037-1.war’ saved [20274638/20274638] [root@mcw12 mcw]# ls consul consul_1.18.1_linux_amd64.zip demo1-0.0.1-20240816.151037-1.war index.html test [root@mcw12 mcw]#
运行这个包,然后访问这个机器的8080端口
可以看到,部署到私服,然后从私服下载下来的这个包,成功运行,并提供web服务
nexus错误
nexus无法启动
普通用户无法start启动,并且没有任何日志输出。然后使用run命令,可以看到终端报错。报错都是权限问题。
[nexus@mcw15 nexus-3.71.0-06]$ ./bin/nexus run Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to Permission denied Warning: Cannot open log file: ../sonatype-work/nexus3/log/jvm.log Warning: Forcing option -XX:LogFile=/tmp/jvm.log java.io.FileNotFoundException: ../sonatype-work/nexus3/tmp/i4j_ofnh2eIHEKc2icDbgZmlfnxUUHg=.lock (Permission denied) at java.base/java.io.RandomAccessFile.open0(Native Method) at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:344) at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:259) at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:213) at com.install4j.runtime.launcher.util.SingleInstance.check(SingleInstance.java:72) at com.install4j.runtime.launcher.util.SingleInstance.checkForCurrentLauncher(SingleInstance.java:31) at com.install4j.runtime.launcher.UnixLauncher.checkSingleInstance(UnixLauncher.java:88) at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:67) Unable to delete file: /opt/sonatype-work/nexus3/cache/bundle387/version0.0/revision.location Unable to update instance pid: /opt/sonatype-work/nexus3/instances/instance.properties (Permission denied) [nexus@mcw15 nexus-3.71.0-06]$ [nexus@mcw15 nexus-3.71.0-06]$ ls -lh ../sonatype-work/nexus3/log/jvm.log -rw-r--r-- 1 root root 0 Aug 18 21:15 ../sonatype-work/nexus3/log/jvm.log [nexus@mcw15 nexus-3.71.0-06]$ ls -lh ../sonatype-work/nexus3/ total 20K drwxr-xr-x 3 root root 21 Aug 16 01:06 blobs
因为很多文件是root用户的,nexus用户没有权限操作
所以用root启动,用root启动之后,端口没有开启,然后就用nexus再次执行了一次start启动,然后端口就开启了,不过端口开启应该跟这个普通用户的操作没有关系,可能只是端口开启慢了罢了。有时间再验证
[root@mcw15 bin]# ./nexus start WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ Starting nexus [root@mcw15 bin]# ps -ef|grep nexus root 9308 2462 0 21:12 pts/0 00:00:00 su - nexus nexus 9310 9308 0 21:12 pts/0 00:00:00 -bash root 16544 1 78 21:41 pts/1 00:00:16 /usr/lib/jvm/jdk-17.0.12-oracle-x64/bin/java -server -Dinstall4j.jvmDir=/usr/lib/jvm/jdk-17.0.12-oracle-x64 -Dexe4j.moduleName=/opt/nexus-3.71.0-06/bin/nexus -XX:+UnlockDiagnosticVMOptions -Dinstall4j.launcherId=246 -Dinstall4j.swt=false -Di4jv=0 -Di4jv=0 -Di4jv=0 -Di4jv=0 -Di4jv=0 -Xms1024m -Xmx1024m -XX:MaxDirectMemorySize=1024m -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=../sonatype-work/nexus3/log/jvm.log -XX:-OmitStackTraceInFastThrow -Dkaraf.home=. -Dkaraf.base=. -Dkaraf.etc=etc/karaf -Djava.util.logging.config.file=etc/karaf/java.util.logging.properties -Dkaraf.data=../sonatype-work/nexus3 -Dkaraf.log=../sonatype-work/nexus3/log -Djava.io.tmpdir=../sonatype-work/nexus3/tmp -Dkaraf.startLocalConsole=false -Djdk.tls.ephemeralDHKeySize=2048 --add-reads=java.xml=java.logging --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED --patch-module java.base=./lib/endorsed/org.apache.karaf.specs.locator-4.3.9.jar --patch-module java.xml=./lib/endorsed/org.apache.karaf.specs.java.xml-4.3.9.jar --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.naming/javax.naming.spi=ALL-UNNAMED --add-opens java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED --add-exports=java.security.sasl/com.sun.security.sasl=ALL-UNNAMED -Di4j.vpt=true -classpath /opt/nexus-3.71.0-06/.install4j/i4jruntime.jar:/opt/nexus-3.71.0-06/lib/boot/nexus-main.jar:/opt/nexus-3.71.0-06/lib/boot/activation-1.1.jar:/opt/nexus-3.71.0-06/lib/boot/jakarta.xml.bind-api-2.3.3.jar:/opt/nexus-3.71.0-06/lib/boot/jaxb-runtime-2.3.3.jar:/opt/nexus-3.71.0-06/lib/boot/txw2-2.3.3.jar:/opt/nexus-3.71.0-06/lib/boot/istack-commons-runtime-3.0.10.jar:/opt/nexus-3.71.0-06/lib/boot/org.apache.karaf.main-4.3.9.jar:/opt/nexus-3.71.0-06/lib/boot/osgi.core-7.0.0.jar:/opt/nexus-3.71.0-06/lib/boot/org.apache.karaf.specs.activator-4.3.9.jar:/opt/nexus-3.71.0-06/lib/boot/org.apache.karaf.diagnostic.boot-4.3.9.jar:/opt/nexus-3.71.0-06/lib/boot/org.apache.karaf.jaas.boot-4.3.9.jar com.install4j.runtime.launcher.UnixLauncher start 9d17dc87 0 0 org.sonatype.nexus.karaf.NexusMain root 16672 10460 0 21:41 pts/1 00:00:00 grep --color=auto nexus [root@mcw15 bin]#
原文档:https://www.cnblogs.com/karmapeng/p/11968511.html