一、概述
使用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
[root@localhost opt]# tar zxvf nexus-2.14.0-01-bundle.tar.gz
注意:安装nexus,本地仓库默认的jar包存储位置是:/sonatype-work/nexus/storage/central。由于Central仓库占用存储较大,所以要注意存储位置。
四、移动到合适的位置:/usr/local
[root@localhost opt]# mv nexus-2.14.0-01 /usr/local
[root@localhost opt]# mv sonatype-work/ /usr/local
五、修改配置文件1:/usr/local/nexus-2.14.0-01/conf/nexus.properties
# Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.
# Jetty section
#配置端口信息
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
#配置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
# Set this to the root of the Nexus installation
#建议使用绝对路径
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.
#设置为root用户启动,如果需要可设置为其他用户启动,不过需要用户赋予nexus home目录的操作权限
RUN_AS_USER=root
七、启动Nexus
[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用户执行如下命令 :
chmod -R o+w {nexus-home}/
{nexus-home}表示nexus的根目录
[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 [email protected]: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则启动成功
九、配置成服务并开机启动
[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,地址不能访问,可能原因防火墙问题,解决办法如下:
/sbin/iptables -I INPUT -p tcp --dport 8081 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
2,配置成服务启动时遇到的错误,如下:
[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
# Set this to the root of the Nexus installation
#此处最好设置为绝对路径
NEXUS_HOME="/usr/local/nexus-2.14.0-01"