CentOS安装nexus(Maven仓库管理器)

本文详细介绍如何在CentOS 7环境下部署Nexus仓库管理器,包括安装步骤、配置文件修改、启动服务及开机自启设置等内容。同时,还提供了JDK安装与环境配置的方法,并给出maven配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://blog.csdn.net/typa01_kk/article/details/49228873

[plain]  view plain  copy
  1. Nexus是一个强大的Maven仓库管理器,  
  2. 它极大地简化了自己内部仓库的维护和外部仓库的访问。  
  3. 利用Nexus你可以只在一个地方就能够完全控制访问和部署在你所维护仓库中的每个Artifact。  
  4. Nexus是一套“开箱即用”的系统不需要数据库,它使用文件系统加Lucene来组织数据。  
  5. Nexus使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。  
  6. Nexus支持WebDAV与LDAP安全身份认证。  

官网下载:http://www.sonatype.org/nexus/archived/

我的准备:

[plain]  view plain  copy
  1. CentOS Linux release 7.1.1503 (Core)  
  2. nexus-2.11.1-01-bundle.tar.gz  
  3. jdk-8u60-linux-x64  

注:最终启动,如果远程访问关闭,或者是stoped的nexus的jre版本和本地jre的version不符合(一般1.7就ok)!

1:解压:

[plain]  view plain  copy
  1. [root@CentOS-Slave1 install-files]# tar zxvf nexus-2.11.1-01-bundle.tar.gz   
[plain]  view plain  copy
  1. -rw-r--r--. 1 root root 71817045 Oct 18 15:17 nexus-2.11.1-01-bundle.tar.gz  
  2. drwxr-xr-x. 8 root root     4096 Dec 17  2014 nexus-2.11.1-01  
  3. drwxr-xr-x. 3 root root       35 Dec 17  2014 sonatype-work  
注:安装nexus,本地仓库默认的jar包存储位置是:/sonatype-work/nexus/storage/central。由于Central仓库占用存储较大,所以要注意存储位置。

2:移动合适位置/home/nexus:

[plain]  view plain  copy
  1. [root@CentOS-Slave1 install-files]# mv nexus-2.11.1-01 /home/nexus/  
  2. [root@CentOS-Slave1 install-files]# mv sonatype-work/ /home/nexus  
[plain]  view plain  copy
  1. [root@CentOS-Slave1 install-files]# cd /home/nexus/  
  2. [root@CentOS-Slave1 nexus]# ll  
  3. total 4  
  4. drwxr-xr-x. 8 root root 4096 Dec 17  2014 nexus-2.11.1-01  
  5. drwxr-xr-x. 3 root root   35 Dec 17  2014 sonatype-work  

3:修改配置文件1:/home/nexus/nexus-2.11.1-01/conf/nexus.properties
[plain]  view plain  copy
  1. ………………  
  2. # Sonatype Nexus  
  3. # ==============  
  4. # This is the most basic configuration of Nexus.  
  5.   
  6. # Jetty section  
  7. # 配置端口信息  
  8. application-port=8081  
  9. application-host=0.0.0.0  
  10. nexus-webapp=${bundleBasedir}/nexus  
  11. #配置IP端口访问  
  12. #http://192.168.10.56:8081/nexus/可修改为: /  
  13. nexus-webapp-context-path=/nexus  
  14.   
  15. # Nexus section  
  16. #配置work目录地址,Maven仓库JAR缓存地址,可修改其他地址eg:${bundleBasedir}/nexus-work/nexus   
  17. nexus-work=${bundleBasedir}/../sonatype-work/nexus  
  18. runtime=${bundleBasedir}/nexus/WEB-INF  
4:修改配置文件2:/home/nexus/nexus-2.11.1-01/bin/nexus
[plain]  view plain  copy
  1. ………………  
  2. #NEXUS_HOME=".."  
  3. #如果目录改变配置,如果修改了运行路径  
  4. NEXUS_HOME="/home/nexus/nexus-2.11.1-01"  
  5. ……………………  
  6. #RUN_AS_USER=  
  7. #nexus启动用户  
  8. RUN_AS_USER=root  
注: nexus很依赖于jdk,编写,所以必须安装好jdk并设置环境变量/etc/profile并生效!备注附件!

4.1修改JDK:
[plain]  view plain  copy
  1. /usr/local/nexus/nexus-2.11.1-01/bin/jsw/conf  
  2. # Set the JVM executable  
  3. # (modify this to absolute path if you need a Java that is not on the OS path)  
  4. wrapper.java.command=java  
  5. 修改为jdk路径:  
  6. wrapper.java.command=/usr/local/jdk1.7.0_80/bin/java  

[plain]  view plain  copy
  1. [root@CentOS-Slave1 metrics]# pwd  
  2. /home/nexus/nexus-2.11.1-01/nexus/WEB-INF/classes/org/sonatype/nexus/webapp/metrics  
  3. [root@CentOS-Slave1 metrics]# ls  
  4. DeadlockHealthCheckProvider.class  HealthCheckMediator.class  MetricsModule$1.class  MetricsModule$2.class  MetricsModule.class  
4.2用户和组:
groupadd nexus
useradd nexus -g nexus -d /usr/local/nexus -s /bin/sh
4.3归属:
chown -R nexus: /usr/local/nexus/
5:启动nexus服务:
[plain]  view plain  copy
  1. [root@CentOS-Slave1 bin]# ./nexus start  
  2. ****************************************  
  3. WARNING - NOT RECOMMENDED TO RUN AS ROOT  
  4. ****************************************  
  5. Starting Nexus OSS...  
  6. Started Nexus OSS.  
警告:不推荐作为root用户运行.
6:nexus启动日志:
[plain]  view plain  copy
  1. [root@CentOS-Slave1 logs]# pwd  
  2. /home/nexus/nexus-2.11.1-01/logs  
  3. [root@CentOS-Slave1 logs]# tail -f wrapper.log   
  4. ……………………  
  5. xceptionMapper  
  6. jvm 1    | 2015-10-18 16:38:29,492+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.rest.NexusApplication_UriMatching - Strict URI matching: true  
  7. jvm 1    | 2015-10-18 16:38:29,816+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.configuration.ModelUtils - Loading model /home/nexus/sonatype-work/nexus/conf/ldap.xml  
  8. jvm 1    | 2015-10-18 16:38:29,873+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.configuration.ModelUtils - Loading model /home/nexus/sonatype-work/nexus/conf/lvo-plugin.xml  
  9. jvm 1    | 2015-10-18 16:38:30,994+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.webresources.internal.WebResourceServiceImpl - Discovered 1973 resources  
  10. jvm 1    | 2015-10-18 16:38:30,996+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.webresources.internal.WebResourceServlet - Max-age: 30 days (2592000 seconds)  
  11. jvm 1    | 2015-10-18 16:38:31,132+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.InstrumentedSelectChannelConnector - Metrics enabled  
  12. jvm 1    | 2015-10-18 16:38:31,166+0800 INFO  [jetty-main-1] *SYSTEM org.eclipse.jetty.server.AbstractConnector - Started InstrumentedSelectChannelConnector@0.0.0.0:8081  
  13. jvm 1    | 2015-10-18 16:38:31,166+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Running  
  14. jvm 1    | 2015-10-18 16:38:31,166+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Started  

注:启动日志:*SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Started则,启动成功!
用浏览器访问:http://192.168.10.56:8081/nexus/

7:nexus开机启动:

[plain]  view plain  copy
  1. [root@CentOS-Slave1 bin]# pwd  
  2. /home/nexus/nexus-2.11.1-01/bin  
  3. [root@CentOS-Slave1 bin]# ls  
  4. jsw  nexus  nexus.bat  
  5. [root@CentOS-Slave1 bin]# cp nexus /etc/rc.d/init.d/  
  6. [root@CentOS-Slave1 bin]# cd /etc/rc.d/init.d/  
  7. [root@CentOS-Slave1 init.d]# ls  
  8. functions  jexec  mysql  netconsole  network  nexus  README  
  9. [root@CentOS-Slave1 init.d]# chkconfig --add nexus  
  10. [root@CentOS-Slave1 init.d]# chkconfig --list | grep nexus   
  11.   
  12. Note: This output shows SysV services only and does not include native  
  13.       systemd services. SysV configuration data might be overridden by native  
  14.       systemd configuration.  
  15.   
  16.       If you want to list systemd services use 'systemctl list-unit-files'.  
  17.       To see services enabled on particular target use  
  18.       'systemctl list-dependencies [target]'.  
  19.   
  20. nexus           0:off   1:off   2:off   3:off   4:off   5:off   6:off  
  21. [root@CentOS-Slave1 init.d]# chkconfig nexus on  
  22. [root@CentOS-Slave1 init.d]# chkconfig --list | grep nexus   
  23.   
  24. Note: This output shows SysV services only and does not include native  
  25.       systemd services. SysV configuration data might be overridden by native  
  26.       systemd configuration.  
  27.   
  28.       If you want to list systemd services use 'systemctl list-unit-files'.  
  29.       To see services enabled on particular target use  
  30.       'systemctl list-dependencies [target]'.  
  31.   
  32. nexus           0:off   1:off   2:on    3:on    4:on    5:on    6:off  

问题1:

[root@CentOS-Slave1 bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.

解决1:上:4:修改配置文件2:/home/nexus/nexus-2.11.1-01/bin/nexus ---> RUN_AS_USER=root

备注附件:

安装jdk:

[plain]  view plain  copy
  1. [root@CentOS-Slave1 install-files]# rpm -ivh jdk-8u60-linux-x64.rpm   
  2. Preparing...                          ################################# [100%]  
  3. Updating / installing...  
  4.    1:jdk1.8.0_60-2000:1.8.0_60-fcs    ################################# [100%]  
  5. Unpacking JAR files...  
  6.     tools.jar...  
  7.     plugin.jar...  
  8.     javaws.jar...  
  9.     deploy.jar...  
  10.     rt.jar...  
  11.     jsse.jar...  
  12.     charsets.jar...  
  13.     localedata.jar...  
  14.     jfxrt.jar...  
  15. [root@CentOS-Slave1 install-files]# vim /etc/profile  
  16. ……………………  
  17. #jdk  
  18. export JAVA_HOME=/usr/java/jdk1.8.0_60  
  19. export PATH=$JAVA_HOME/bin:$PATH  
  20. export CLASSPATH=$JAVA_HOME/lib:.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar  
  21. [root@CentOS-Slave1 install-files]# source /etc/profile  

参数说明:

[plain]  view plain  copy
  1. nexus的仓库类型分为以下四种:group: 仓库组,hosted:宿主 ,proxy:代理,virtual:虚拟  
  2. 仓库组和多个仓库:  
  3. Public Repositories:  仓库组  
  4. 3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库  
  5. Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库  
  6. Central: 用来代理maven中央仓库中发布版本构件的仓库  
  7. Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库  
  8. Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库  
  9. Releases: 用来部署管理内部的发布版本构件的宿主类型仓库  
  10. Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库  
maven的pom.xml设置:

[plain]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <settings>  
  3.     <mirrors>  
  4.         <mirror>  
  5.             <!--This sends everything else to /public -->  
  6.             <id>nexus</id>  
  7.             <mirrorOf>*</mirrorOf>  
  8.              <!-- <url>http://repo1.maven.org/maven2/</url> -->  
  9.             <url>http://192.168.10.56:8081/nexus/content/groups/public</url>  
  10.         </mirror>  
  11.     </mirrors>  
  12.     <profiles>  
  13.         <profile>  
  14.             <id>nexus</id>  
  15.             <!--Enable snapshots for the built in central repo to direct -->  
  16.             <!--all requests to nexus via the mirror -->  
  17.             <repositories>  
  18.                 <repository>  
  19.             <id>central</id>  
  20.             <url>http://repo1.maven.org/maven2/</url>  
  21.                     <releases>  
  22.                         <enabled>true</enabled>  
  23.                     </releases>  
  24.                     <snapshots>  
  25.                         <enabled>true</enabled>  
  26.                     </snapshots>  
  27.                 </repository>  
  28.             </repositories>  
  29.             <pluginRepositories>  
  30.                 <pluginRepository>  
  31.                     <id>central</id>  
  32.                     <url>http://central</url>  
  33.                     <releases>  
  34.                         <enabled>true</enabled>  
  35.                     </releases>  
  36.                     <snapshots>  
  37.                         <enabled>true</enabled>  
  38.                     </snapshots>  
  39.                 </pluginRepository>  
  40.             </pluginRepositories>  
  41.         </profile>  
  42.     </profiles>  
  43.       
  44.     <activeProfiles>  
  45.         <!--make the profile active all the time -->  
  46.         <activeProfile>nexus</activeProfile>  
  47.     </activeProfiles>  
  48. </settings>  

### CentOS 安装 Maven 并配置私有仓库 #### 一、Maven安装CentOS 系统上安装 Maven 可通过手动下载二进制包的方式完成。 1. **下载 Maven 压缩包** 使用 `wget` 下载官方发布的 Maven 版本压缩包。 ```bash wget https://apache.osuosl.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz ``` 2. **解压文件** 将下载的压缩包解压至指定位置。 ```bash sudo tar xzf apache-maven-3.8.8-bin.tar.gz -C /opt/ ``` 此操作会将 Maven 文件夹放置于 `/opt/` 路径下[^1]。 3. **设置环境变量** 编辑系统的全局环境变量文件,使 Maven 生效。 ```bash echo 'export M2_HOME=/opt/apache-maven-3.8.8' | sudo tee -a /etc/profile.d/maven.sh echo 'export PATH=${M2_HOME}/bin:${PATH}' | sudo tee -a /etc/profile.d/maven.sh source /etc/profile.d/maven.sh ``` 这些命令定义了 `M2_HOME` 和 `PATH` 环境变量,并重新加载配置使其生效。 4. **验证安装** 执行以下命令确认 Maven 是否成功安装。 ```bash mvn -v ``` 输出应显示当前使用的 Maven 版本以及 JDK 配置信息[^3]。 --- #### 二、创建本地仓库 为了管理依赖项,默认情况下 Maven 会在用户家目录下的 `.m2/repository` 中存储缓存数据。如果希望自定义路径,则需修改配置文件: 1. **新建仓库目录** ```bash mkdir -p ~/repository ``` 2. **编辑 settings.xml** 修改 Maven 默认配置文件以指向新仓库地址。 ```xml <settings> <localRepository>/path/to/custom/repo</localRepository> </settings> ``` 替换 `/path/to/custom/repo` 为实际的仓库路径[^1]。 --- #### 三、搭建私有 Maven 仓库(Nexus) 对于团队协作或内部项目需求,可以部署 Nexus 来作为私有的 Maven 仓库服务器。 1. **安装 Docker** 如果尚未安装 Docker,请先执行如下步骤: ```bash yum install docker -y systemctl start docker && systemctl enable docker ``` 2. **拉取 Nexus 镜像** 利用 Docker 提供的服务快速启动 Nexus 实例。 ```bash docker pull sonatype/nexus3 docker run -d --name nexus -p 8081:8081 sonatype/nexus3 ``` 3. **访问 Web 控制台** 浏览器打开 http://<server-ip>:8081/nexus ,登录初始账户 admin/admin123 后更改密码[^2]。 4. **配置仓库类型** 在 Nexus 中新增三种主要类型的仓库: - Central Proxy Repository (代理远程中央库) - Hosted Release Repository (托管正式版库) - Hosted Snapshot Repository (托管快照版库) 5. **放行防火墙端口** 若启用了防火墙规则,允许外部设备连接到该服务端口。 ```bash firewall-cmd --zone=public --add-port=8081/tcp --permanent firewall-cmd --reload ``` 6. **客户端配置** 更新项目的 pom.xml 或者 global settings.xml 添加私有仓库 URL 地址。 ```xml <repositories> <repository> <id>private-nexus</id> <url>http://<your-server-ip>:8081/repository/maven-public/</url> </repository> </repositories> ``` --- #### 四、注意事项 - 确保 JDK 已正确定义好环境变量,因为 Maven 是基于 Java 构建工具[^4]。 - 对于生产环境中建议采用 HTTPS 加密传输方式保护通信安全[^5]。 --- ### 示例脚本总结 以下是完整的自动化脚本模板供参考: ```bash #!/bin/bash # Step 1: Install dependencies and download Maven binary package. yum update -y && yum groupinstall "Development Tools" -y wget https://apache.osuosl.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz # Step 2: Extract the archive into a specific directory. tar xzf apache-maven-3.8.8-bin.tar.gz -C /opt/ # Step 3: Configure system-wide environment variables for Maven. cat <<EOF >> /etc/profile.d/maven.sh export M2_HOME=/opt/apache-maven-3.8.8 export PATH=\${M2_HOME}/bin:\${PATH} EOF source /etc/profile.d/maven.sh # Optional step to set up private repository path. mkdir -p ~/.m2/repository sed -i '/<localRepository>/c\<localRepository>~/.m2/repository<\/localRepository>' $M2_HOME/conf/settings.xml echo "Installation completed successfully!" ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值