【www.lexiangwang.net--管理咨询】
Nexus的主要作用: 减少从远方仓库下载的次数,节省带宽、提高maven build的效率 减少对远方仓库的依赖,确保maven build的稳定性 方便内部人员发布artifact 方便存放官方仓库中没有的第三方依赖包 QQ截图20180105101208.png 下面开始介绍nexus的安装步骤: 1、安装SDK debian apt-get安装jdk的方法 sudo sh -c 'echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" >> /etc/apt/sources.list sudo sh -c 'echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" >> /etc/apt/sources.list sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 sudo apt-get update sudo apt-get install oracle-java8-installer 2、下载 https://www.sonatype.com/download-oss-sonatype?hsCtaTracking=920dd7b5-7ef3-47fe-9600-10fecad8aa32%7Cf59d5f10-099f-4c66-a622-0254373f4a92 nexus-3.6.2-01-unix.tar.gz 使用root用户安装 解压到/opt 3、修改/opt/nexus/bin/nexus.rc run_as_user="nexus" 4、测试运行 nexus@debian:/opt/nexus/bin$ ./nexus run 5、使用update-rc.d工具添加服务 使用update-rc.d工具创建systemd cd /etc/init.d sudo update-rc.d nexus defaults sudo service nexus start /lib/systemd/systemd-sysv-install enable nexus 6、手动添加systemd 在/etc/systemd/system/目录中 创建nexus.service文件: [Unit] Description=nexus service After=network.target [Service] Type=forking ExecStart=/opt/nexus/bin/nexus start ExecStop=/opt/nexus/bin/nexus stop User=root Restart=on-abort [Install] WantedBy=multi-user.target Activate the service with the following commands: sudo systemctl daemon-reload sudo systemctl enable nexus.service sudo systemctl start nexus.service 7、打开文件限制 编辑/etc/security/limits.conf file 在文件末尾添加: * hard nofile 65536 * soft nofile 65536 编辑 /etc/pam.d/common-session,注释掉下面的代码 # session required pam_limits.so 如果使用systemd启动服务器失败,可以在配置文件中添加LimitNOFILE配置 [Unit] Description=nexus service After=network.target [Service] Type=forking *LimitNOFILE=65536* ExecStart=/opt/nexus/bin/nexus start ExecStop=/opt/nexus/bin/nexus stop User=nexus Restart=on-abort [Install] WantedBy=multi-user.target 8、验证服务器的可用 在客户机上安装maven 配置maven的setting.xml文件,指定使用自己的nexue服务器 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> <localRepository>C:\Users\lew\.m2\repository</localRepository> --> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <!-- * 表示让所有仓库使用该镜像--> <name>nexus-mirror</name> <url>*http://repo.test.com:8088/repository/maven-public/*</url> </mirror> </mirrors> <profiles> </profiles> </settings> 进入maven项目pom.xml目录,执行mvn package,如果一切正常,可以看到从repo.test.com开始下载了 Image.png 全部下载完成 Image.png 本地仓库也可以看到相关的下载 Image.png 9、上传第三方jar包 以 ojdbc14.jar为例 先去nexus创建hosted类型仓库 Image.png 并创建用户,如fred Image.png 使用maven客户端上传: mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=E:\Applications\Java\Workspaces\Git\qywxtxltb\weixin\lib\ojdbc14.jar -Durl=http://fred:[email protected]:8088/repository/maven-3rd/ -DrepositoryId=nexus-releases mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=E:\Applications\Java\Workspaces\Git\qywxtxltb\weixin\lib\ojdbc14.jar -Durl=http://fred:[email protected]:8088/repository/maven-3rd/ -DrepositoryId=nexus-releases [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- Uploading to nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.jar Uploaded to nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.jar (1.5 MB at 155 kB/s) Uploading to nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.pom Uploaded to nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.pom (395 B at 41 B/s) Downloading from nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/maven-metadata.xml Uploading to nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/maven-metadata.xml Uploaded to nexus-releases: http://fred:[email protected]:8088/repository/maven-3rd/com/oracle/ojdbc14/maven-metadata.xml (307 B at 33 B/s) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 29.664 s [INFO] Finished at: 2017-12-14T17:08:03+08:00 [INFO] Final Memory: 8M/104M [INFO] ------------------------------------------------------------------------ 开发工具中,maven可以下载oracle的包了。 Image.png <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId> <version>10.2.0.4.0</version> </dependency> setting.xml 也需要更新,使用自己的第三方仓库 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd">; <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> <localRepository>C:\Users\lew\.m2\repository</localRepository> --> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <!-- * 表示让所有仓库使用该镜像--> <name>nexus-mirror</name> <url>http://repo.test.com:8088/repository/maven-public/</url> </mirror> <mirror> <id>nexus3rd</id> <mirrorOf>*</mirrorOf> <!-- * 表示让所有仓库使用该镜像--> <name>nexus-3rd/</name> <url>http://repo.test.com:8088/repository/maven-3rd/</url> </mirror> </mirrors> <profiles> </profiles> </settings>http://www.lazyedu.com/opensource-server/nexus-maven.html