一、概述
使用Nexus搭建私服的主要背景是:我们做的是内容管理平台EMC Documentum产品的二次开发有很多平台所特有的第三方jar包需要管理,同时需要用Nexus简化内部仓库的维护和外部仓库的访问。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
二、前期准备
操作系统:CentOS Linux release 7.2.1511 (Core)
Nexus版本:nexus-2.14.0-01-bundle.tar.gz
Nexus下载路径:http://www.sonatype.org/nexus/archived/
JDK版本:jdk-8u101-linux-x64.rpm
三、解压Nexus
[java] view plain copy [root@localhost opt]# tar zxvf nexus-2.14.0-01-bundle.tar.gz注意:安装nexus,本地仓库默认的jar包存储位置是:/sonatype-work/nexus/storage/central。由于Central仓库占用存储较大,所以要注意存储位置。
四、移动到合适的位置:/usr/local
[java] view plain copy [root@localhost opt]# mv nexus-2.14.0-01 /usr/local [java] view plain copy [root@localhost opt]# mv sonatype-work/ /usr/local
五、修改配置文件1:/usr/local/nexus-2.14.0-01/conf/nexus.properties
[java] view plain copy # Sonatype Nexus # ============== # This is the most basic configuration of Nexus. # Jetty section</span> [java] view plain copy #配置端口信息 application-port=8081 application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexus [java] view plain copy <span style="font-size:14px;"><span style="font-size:10px;">#配置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六、修改配置文件2:
/usr/local/nexus-2.14.0-01/bin/nexus
[java] view plain copy # Set this to the root of the Nexus installation [java] view plain copy #建议使用绝对路径 NEXUS_HOME="/usr/local/nexus-2.14.0-01" # If specified, the Wrapper will be run as the specified user. # IMPORTANT - Make sure that the user has the required privileges to write into the Nexus installation directory. # NOTE - This will set the user which is used to run the Wrapper as well as # the JVM and is not useful in situations where a privileged resource or # port needs to be allocated prior to the user being changed. [java] view plain copy #设置为root用户启动,如果需要可设置为其他用户启动,不过需要用户赋予nexus home目录的操作权限 RUN_AS_USER=root
七、启动Nexus
[java] view plain copy [root@localhost bin]# ./nexus start **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS. [root@localhost bin]#
注意,这里不建议使用root用户来运行nexus,使用其他用户我们需要考虑一下文件系统的权限问题,不然程序可能无法启动,报出Permissiondenied错误 ,使用root用户执行如下命令 :
[java] view plain copy chmod -R o+w {nexus-home}/ {nexus-home}表示nexus的根目录 上面的命令将nexus整个文件夹(包括其子文件和子文件夹)向普通用户开放了write权限,于是我们就可以使用普通用户执行nexus脚本了,执行命令./nexusstart
八、查看启动日志:
[java] view plain copy [root@localhost logs]# pwd /usr/local/nexus-2.14.0-01/logs [root@localhost logs]# ls wrapper.log [root@localhost logs]# tail -f wrapper.log jvm 1 | 2016-10-17 06:29:45,193-0400 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.configuration.ModelUtils - Loading model /usr/local/sonatype-work/nexus/conf/lvo-plugin.xml jvm 1 | 2016-10-17 06:29:45,407-0400 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.webresources.internal.WebResourceServiceImpl - Discovered 1971 resources jvm 1 | 2016-10-17 06:29:45,408-0400 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.webresources.internal.WebResourceServlet - Max-age: 30 days (2592000 seconds) jvm 1 | 2016-10-17 06:29:45,430-0400 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.InstrumentedSelectChannelConnector - Metrics enabled jvm 1 | 2016-10-17 06:29:45,441-0400 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.AbstractConnector - Started InstrumentedSelectChannelConnector@0.0.0.0:8081 jvm 1 | 2016-10-17 06:29:45,441-0400 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Running jvm 1 | 2016-10-17 06:29:45,441-0400 INFO [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Started
日志:*SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Started则启动成功
九、配置成服务并开机启动
[java] view plain copy [root@localhost bin]# pwd /usr/local/nexus-2.14.0-01/bin [root@localhost bin]# cp nexus /etc/rc.d/init.d/ [root@localhost bin]# cd /etc/rc.d/init.d/ [root@localhost init.d]# ls functions jexec netconsole network nexus README [root@localhost init.d]# chkconfig --add nexus [root@localhost init.d]# chkconfig --list | grep nexus 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。 nexus 0:关 1:关 2:开 3:开 4:开 5:开 6:关 [root@localhost init.d]# chkconfig nexus on [root@localhost init.d]# chkconfig --list | grep nexus 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。 nexus 0:关 1:关 2:开 3:开 4:开 5:开 6:关 [root@localhost init.d]#
十、访问与启停
访问地址:http://ip:8081/nexus
启动:service nexus start
停止:service nexus stop
重启:service nexus restart
十一、常见问题
1,地址不能访问,可能原因防火墙问题,解决办法如下:
[java] view plain copy /sbin/iptables -I INPUT -p tcp --dport 8081 -j ACCEPT /etc/rc.d/init.d/iptables save /etc/init.d/iptables restart
2,配置成服务启动时遇到的错误,如下:
[java] view plain copy [root@localhost init.d]# service nexus stop Missing platform binary: /etc/rc.d/init.d/../bin/jsw/linux-x86-64/wrapper 解决办法:vi /etc/rc.d/init.d/nexus [java] view plain copy # Set this to the root of the Nexus installation #此处最好设置为绝对路径 NEXUS_HOME="/usr/local/nexus-2.14.0-01"