Nexus 安裝運維手冊

1. Nexus 安裝與配置

1.1 下載Nexus

  登陸https://www.sonatype.com/download-oss-sonatype,下載最新的Nexus版本。 我這裏使用的是nexus-3.16.1-02版本;java

1.2 安裝Nexus

#將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

1.3 啓動Nexus

  啓動用戶是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 --前臺啓動,顯示日誌

1.4 登陸Nexus

  服務啓動完之後,輸入Ip地址+端口訪問(8081),Nexus默認的帳戶名和密碼是是 admin/admin123vim

 

1.5 配置私有庫

  將私有庫添加到http://192.168.209.128:8081/repository/maven-public/中。bash

 

1.6 導入jar包

  通常私服都是存在內網環境,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}/{} ;

1.7 設置登陸用戶權限

  建議將admin註銷,從新定義一個登陸用戶。在Nexus 3.0 這個版本中我直接刪除admin會報錯,可是設置爲不可用沒有問題;curl

 

2. Maven 安裝與配置

2.1 下載Maven

      登陸http://maven.apache.org 下載最新的maven版本,我這裏使用的是apache-maven-3.6.1版本。maven

2.2 安裝Maven

將tar包上傳到服務器/usr/local/目錄下解壓
tar -zxvf apache-maven-3.6.1-bin.tar.gz 

2.3 配置Maven

#配置release、snapshot的用戶信息;
#配置mirror指向私服的nexus-public;
vim /usr/local/maven/apache-maven-3.6.1/conf/setting.xml

 

3. 工做空間配置

3.1 修改本地Maven配置

  配置release、snapshot的用戶信息;ui

  配置mirror指向私服的nexus-public;this

3.2 修改工程中的pom文件

<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>

相關文章
相關標籤/搜索