Linux安装Nexus

当我们尝试从官网下载最新的Nexus 3.x的时候,哦吼,死活下载不下来

https://www.sonatype.com/products/repository-oss-download

https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.30.1-01-unix.tar.gz

https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3

于是,只得用docker安装Nexus

1.  安装Docker

首先找到Docker官方文档  https://docs.docker.com/get-docker/

按照文档一步步操作即可

https://docs.docker.com/engine/install/centos/ 

依次执行以下命令即可:

 yum install -y yum-utils
 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 yum install docker-ce docker-ce-cli containerd.io

其它命令

 # Start Docker
 systemctl start docker
 systemctl stop docker
 systemctl status docker
 
 # Verify that Docker Engine is installed correctly
 docker run hello-world
 
 # Uninstall Docker Engine
 yum remove docker-ce docker-ce-cli containerd.io
 rm -rf /var/lib/docker
 rm -rf /var/lib/containerd

2.  安装nexus3

在docker hub上搜索nexus

https://hub.docker.com/

https://hub.docker.com/search?image_filter=official&type=image

 docker run -d -p 8081:8081 --name nexus sonatype/nexus3

手动指定nexus数据持久化目录

 docker volume create --name nexus-data
 docker run -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3

浏览器访问 http://ip:8081/

登录以后,我们修改admin的密码为admin123

接下来,我们创建两个仓库,一个代理阿里云的maven仓库,一个本地仓库

3.  配置maven仓库

首先,更改maven的settings.xml 

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <settings
 3     xmlns="http://maven.apache.org/SETTINGS/1.2.0"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
 6     <!-- localRepository
 7    | The path to the local repository maven will use to store artifacts.
 8    |
 9    | Default: ${user.home}/.m2/repository
10   <localRepository>/path/to/local/repo</localRepository>
11   -->
12     <servers>
13         <server>
14             <id>releases</id>
15             <username>admin</username>
16             <password>admin123</password>
17         </server>
18         <server>
19             <id>snapshots</id>
20             <username>admin</username>
21             <password>admin123</password>
22         </server>
23     </servers>
24     <mirrors>
25         <mirror>
26             <id>nexus</id>
27             <name>nexus repository</name>
28             <url>http://192.168.28.31:8081/repository/maven-public/</url>
29             <mirrorOf>*</mirrorOf>
30         </mirror>
31     </mirrors>
32     <profiles>
33         <profile>
34             <id>jdk-1.8</id>
35             <activation>
36                 <activeByDefault>true</activeByDefault>
37                 <jdk>1.8</jdk>
38             </activation>
39             <properties>
40                 <maven.compiler.source>1.8</maven.compiler.source>
41                 <maven.compiler.target>1.8</maven.compiler.target>
42                 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
43             </properties>
44         </profile>
45         <profile>
46             <id>dev</id>
47             <repositories>
48                 <repository>
49                     <id>local-nexus</id>
50                     <url>http://192.168.28.31:8081/repository/maven-public/</url>
51                     <releases>
52                         <enabled>true</enabled>
53                     </releases>
54                     <snapshots>
55                         <enabled>true</enabled>
56                     </snapshots>
57                 </repository>
58             </repositories>
59             <pluginRepositories>
60                 <pluginRepository>
61                     <id>local-nexus</id>
62                     <url>http://192.168.28.31:8081/repository/maven-public/</url>
63                     <releases>
64                         <enabled>true</enabled>
65                     </releases>
66                     <snapshots>
67                         <enabled>true</enabled>
68                     </snapshots>
69                 </pluginRepository>
70             </pluginRepositories>
71         </profile>
72     </profiles>
73     <activeProfiles>
74         <activeProfile>dev</activeProfile>
75         <activeProfile>jdk-1.8</activeProfile>
76     </activeProfiles>
77 </settings>

项目的pom.xml文件中加上以下配置

 1 <distributionManagement>
 2     <repository>
 3         <id>releases</id>
 4         <url>http://192.168.28.31:8081/repository/maven-releases/</url>
 5     </repository>
 6     <snapshotRepository>
 7         <id>snapshots</id>
 8         <url>http://192.168.28.31:8081/repository/maven-snapshots/</url>
 9     </snapshotRepository>
10 </distributionManagement>

然后就大功告成了

原文地址:https://www.cnblogs.com/cjsblog/p/14866335.html