wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.1-01-bundle.tar.gz tar -xzvf nexus-2.11.1-01-bundle.tar.gz mv nexus-2.11.1-01 /usr/local/nexus
export NEXUS_HOME=/usr/local/nexus/ export PATH=$PATH:$NEXUS_HOME/bin export CLASSPATH=$CLASSPATH:$NEXUS_HOME/lib
cp /usr/local/nexus/bin/nexus /etc/init.d chkconfig --add nexus chkconfig --levels 345 nexus on
NEXUS_HOME=/usr/local/nexus RUN_AS_USER=nexus PIDDIR="${NEXUS_HOME}"
nexus 目前版本要求的jdk版本是1.7以上。由于原来的服务器环境是1.6的版本,因此独立指定一个jdk1.7的安装路径。
JAVA_HOME=/usr/java/jdk1.6.0_45 PATH=$JAVA_HOME/bin:$PATH
在nexus/conf/nexus.properties文件中可以指定nexus的ip和端口
application-port=8081 application-host=0.0.0.0iptables开放8081端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
保存,并重启iptables
修改/usr/local/nexus/bin/jsw/conf/wrapper.conf中的日志路径
wrapper.logfile=/home/logs/nexus/wrapper.log
解压nexus安装包后有nexus安装程序和sonatype-work两个目录。允许将sonatype-work放在任意位置,但是需要在nexus.properties中进行配置。
nexus-work=/home/sonatype-work/nexus
useradd nexus #授权nexus安装目录的运行用户为nexus chown nexus nexus nexus
service nexus start
tail -f /home/nexus/wrapper.log
通过http://服务器ip:8081/nexus/可以直接在线操作仓库,默认的用户名密码是admin/admin123。
在Administration选项中找到Scheduled Tasks,在窗口页面点击Add
对所有的代理仓库都设置为Download Remote indexes 为true.
nexus默认有一个开放的仓库组,在Repositories列表中的第一个。它默认含有远程代理仓库central、本地发布仓库、第三方镜像仓库等四个仓库。
一张图说明一切
修改maven的全局配置文件
设置构件磁盘存储位置
<localRepository>F:\Svn\repository\maven</localRepository>设置私有仓库服务器的访问权限
<servers> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers>设置nexus为maven默认查看仓库
<mirror> <id>nexus</id> <name>internal nexus repository</name> <url>http://192.168.8.254:8081/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
<?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.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>F:\SvnCodeManage\repository\maven</localRepository> <offline>false</offline> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> <mirrors> <!--使用nexus代理中央仓库--> <mirror> <id>nexus</id> <name>internal nexus repository</name> <url>http://192.168.8.254:8081/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <!-- <mirror> <id>nexus-osc</id> <mirrorOf>*</mirrorOf> <name>Nexus osc</name> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> --> </mirrors> <profiles> <profile> <id>nexus-profile</id> <repositories> <repository> <id>nexus-central</id> <name>central</name> <url>http://192.168.8.254:8081/nexus/content/groups/public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://192.168.8.254:8081/nexus/content/groups/public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus-profile</activeProfile> </activeProfiles> </settings>
由于从项目中将构件发布到nexus需要登录权限,因此第一步需要设置登录权限。
第一步:在setting.xml设置鉴权
<server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server>第二步:在pom.xml中配置项目发布
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://192.168.8.254:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.8.254:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
上面的setting.xml中的配置id必须与pom.xml的配置id必须保持一致。
出现上述错误的原因是服务器不能访问外网网络,需要检查网络设置问题。更新索引需要一定的时间,如果没有更新完毕是无法搜索的。