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的安裝路徑。html
JAVA_HOME=/usr/java/jdk1.6.0_45 PATH=$JAVA_HOME/bin:$PATH
在nexus/conf/nexus.properties文件中能夠指定nexus的ip和端口
java
application-port=8081 application-host=0.0.0.0
iptables開放8081端口apache
-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中進行配置。
app
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。
maven
在Administration選項中找到Scheduled Tasks,在窗口頁面點擊Add
tcp
對全部的代理倉庫都設置爲Download Remote indexes 爲true.
url
nexus默認有一個開放的倉庫組,在Repositories列表中的第一個。它默認含有遠程代理倉庫central、本地發佈倉庫、第三方鏡像倉庫等四個倉庫。
.net
一張圖說明一切
修改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必須保持一致。
出現上述錯誤的緣由是服務器不能訪問外網網絡,須要檢查網絡設置問題。更新索引須要必定的時間,若是沒有更新完畢是沒法搜索的。