登陸https://www.sonatype.com/download-oss-sonatype,下載最新的Nexus版本。 我這裏使用的是nexus-3.16.1-02版本;java
#將tar包上傳到服務器/usr/local/目錄下解壓,這個時候會出現 nexus-3.16.1-0二、sonatype-work 兩個文件夾 tar -zxvf nexus-3.16.1-02-unix.tar.gz #修改配置文件,eg:端口號 cd /usr/local/nexus-3.16.1-02/etc vim nexus-default.properties
啓動用戶是root的時候會出現下面的警告,能夠經過修改/usr/local/nexus-3.16.1-02/bin/nexus.rc文件解決;apache
#修改啓動用戶run_as_user,建議不要使用root vim /usr/local/nexus-3.16.1-02/bin/nexus.rc # cd /usr/local/nexus-3.16.1-02/bin ./nexus start --後臺啓動 ./nexus run --前臺啓動,顯示日誌
服務啓動完之後,輸入Ip地址+端口訪問(8081),Nexus默認的帳戶名和密碼是是 admin/admin123vim
將私有庫添加到http://192.168.209.128:8081/repository/maven-public/中。bash
通常私服都是存在內網環境,Nexus3.0之後須要經過命令命令將具體的jar包打到私服中;服務器
#將下面的腳本丟到須要上傳jar包的文件目錄下
chmod u+x mavenimport.sh
./mavenimport.sh -u admin -p admin123 -r http://192.168.209.128:8081/repository/lingan/
#!/bin/bash # copy and run this script to the root of the repository directory containing files # this script attempts to exclude uploading itself explicitly so the script name is important # Get command line params while getopts ":r:u:p:" opt; do case $opt in r) REPO_URL="$OPTARG" ;; u) USERNAME="$OPTARG" ;; p) PASSWORD="$OPTARG" ;; esac done find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml'
-not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
建議將admin註銷,從新定義一個登陸用戶。在Nexus 3.0 這個版本中我直接刪除admin會報錯,可是設置爲不可用沒有問題;curl
登陸http://maven.apache.org 下載最新的maven版本,我這裏使用的是apache-maven-3.6.1版本。maven
將tar包上傳到服務器/usr/local/目錄下解壓 tar -zxvf apache-maven-3.6.1-bin.tar.gz
#配置release、snapshot的用戶信息; #配置mirror指向私服的nexus-public; vim /usr/local/maven/apache-maven-3.6.1/conf/setting.xml
配置release、snapshot的用戶信息;ui
配置mirror指向私服的nexus-public;this
<repositories>url
<repository>
<id>nexus-public</id>
<url>http://192.168.11.23:8180/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>release</id>
<url>http://192.168.11.23:8180/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshot</id>
<url>http://192.168.11.23:8180/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>