Nexus概念
nexus适用场景: nexus适用于maven用户特别多的情况下
注:安装nexus前必须先安装jdk环境,因为nexus也是基于java开发的
[root@localhost ~]# ls #准备jdk软件包
jdk-8u201-linux-x64.tar.gz
[root@localhost ~]# java -version
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
[root@localhost ~]# rm -rf /usr/bin/java #删除原本主机上的Java程序
[root@localhost ~]# java -version
-bash: /usr/bin/java: 没有那个文件或目录
[root@localhost ~]# tar -zxf jdk-8u201-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.8.0_201/ /usr/local/java
添加环境变量
[root@localhost bin]# vim /etc/profile
#末尾添加
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
#释义:
#export:声明一个变量
#jre java runtime environment : java的运行环境
#class java 依赖库文件
#path 环境变量
[root@localhost bin]# source /etc/profile
[root@localhost bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin:/usr/local/java/jre/bin
[root@localhost bin]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
安装nexus
[root@localhost ~]# ls #所需的软件包
aliyun-sdk-oss-2.6.1.jar nexus-3.14.0-04-unix.tar.gz
[root@localhost ~]# mkdir /usr/local/nexus
[root@localhost ~]# tar -zxf nexus-3.14.0-04-unix.tar.gz -C /usr/local/nexus/
[root@localhost ~]# /usr/local/nexus/nexus-3.14.0-04/bin/nexus start #这里启动的可能会慢一点,查看端口是否启动成功需要等一会儿才能查看的到
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
[root@localhost ~]# netstat -anput | grep 8081
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 4910/java
访问192.168.10.50:8081端口看服务是否安装成功(注:直接访问本机ip加端口号即可)
登录:
默认的用户名和密码
创建角色:
创建用户:
[root@localhost ~]# cd /usr/local/nexus/nexus-3.14.0-04/
[root@localhost nexus-3.14.0-04]# cd lib/support/
[root@localhost support]# java -jar nexus-orient-console.jar
orientdb> connect plocal:/usr/local/nexus/sonatype-work/nexus3/db/security admin admin
orientdb {db=security}> update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"
Updated record(s) '1' in 0.002000 sec(s).
orientdb {db=security}> exit
2、备份与迁移
[root@localhost support]# cd /usr/local/nexus/
[root@localhost nexus]# ls
nexus-3.14.0-04 sonatype-work
sonatype-work 工作数据目录,如果想要数据备份或者迁移,直接移走这个目录就可以了
仓库
仓库的分类:
创建阿里云的一个代理仓库
下载
环境:
主机 | ip |
---|---|
maven | 192.168.10.40 |
nexus | 192.168.10.50 |
前提准备:安装好maven的相关操作,前面有写过具体安装步骤和相关操作
nexus主机
[root@localhost nexus]# ulimit -HSn 655360
[root@localhost nexus]# ulimit -n
655360
maven主机:
[root@localhost target]# systemctl stop firewalld
[root@localhost target]# setenforce 0
[root@localhost target]# cd /root/.m2/repository/
[root@localhost repository]# rm -rf *
[root@localhost repository]# vim /usr/local/maven/conf/settings.xml
164 <mirror>
165 <id>kgcconf</id>
166 <name>nexus-kgcconf</name>
167 <url>http://192.168.10.50:8081/repository/maven-public/</url>
168 <mirrorOf>*</mirrorOf>
169 </mirror>
进去之前的项目当中
[root@localhost repository]# cd /usr/test/
[root@localhost test]# cd kgcapp/
[root@localhost kgcapp]# mvn clean package
下载完后去图形化界面查看
上传
[root@localhost repository]# cd /usr/test/
[root@localhost test]# cd kgcapp/
[root@localhost kgcapp]# vim /usr/local/maven/conf/settings.xml
258 <profile>
259 <id>kgcconf</id>
260 <repositories>
261 <repository>
262 <id>nexus</id>
263 <url>http://192.168.10.50:8081/repository/maven-public/</url>
264 </repository>
265 </repositories>
266 <pluginRepositories>
267 <pluginResitory>
268 <id>nexus</id>
269 <url>http://192.168.10.50:8081/repository/maven-public/</url>
270 </pluginResitory>
271 </pluginRepositories>
272 </profile>
273 </profile>
133 <server>
134 <id>nexus</id>
135 <username>admin</username>
136 <password>admin123</password>
137 </server>
279 <activeProfiles>
280 <activeProfile>alwaysActiveProfile</activeProfile>
281 </activeProfiles>
[root@localhost kgcapp]# vim pom.xml
8 <distributionManagement>
9 <snapshotRepository>
10 <id>nexus</id>
11 <name>maven-snapshots</name>
12 <url>http://192.168.10.50:8081/repository/maven-snapshots/</url>
13 </snapshotRepository>
14 <repository>
15 <id>nexus</id>
16 <name>maven-releases</name>
17 <url>http://192.168.10.50:8081/repository/maven-releases/</url>
18 </repository>
19 </distributionManagement>
[root@localhost kgcapp]# mvn clean deploy