nexus3.x Liunx私库安装教程 (亲测有用)

@

前言

书接上文?enn....

嘛~ ,上文:nexus 3.x下载 3.18.1(maven 私服)

上面是教如何下载nexus的

嘛,开始吧,有啥阔以聊的我后面再放吧(づ ̄ 3 ̄)づ

在这里插入图片描述


一、环境准备

1、一台服务器 :我的是Centos7云服务器(可云,可本地,只不过重点在有无外网)
2、jdk:jdk1.8(老牌)
3、maven:maven3.6.2 (都不陌生吧,版本看着来)
4、nexus:nexus3.18.1 (上面有攻略)


二、nexus环境配置

(1)解压

tar -xvf nexus-3.18.1-01-unix.tar.gz

./nexus-3.18.1-01 程序home路径
./sonatype-work 工作目录,包含缓存信息,日志,上传到私服的相关包的信息

在这里插入图片描述
(2)配置环境变量

nexus的环境变量最好要配置(关于后面自启动的配置),至于jdk,maven这些这里就不过多赘述了

vim /etc/profile 
#和NEXUS_HOME
export NEXUS_HOME=/home/nexus/nexus-3.18.1-01
export PATH=$NEXUS_HOME/bin;
#完成以后使更改后的文件立即生效
source /etc/profile
#检验配置是否成功
nexus

在这里插入图片描述
(3)启动服务

使用./nexus run 就是直接放到主线程里跑

在这里我们最好就试一试主线程能不能跑通,跑不通的话请看下面的 问题一

使用./nexus start 就是后台运行

如果主线程跑的没问题的话,就可以直接起了

(4)设置自启服务

在/etc/rc.local 文件最底下加入行 nexus start

三、了解nexus

(1)登录

默认端口号为:ip:8081,如果有需要可以到/nexus/sonatype-work/nexus3/etc/nexus.properties ,进行修改端口即可

在这里插入图片描述

首次登录的话是需要到它提示的文件里找初始密码的

在这里插入图片描述

(2)基本仓库

  • maven-releases (Version policy=Release)默认只允许上传不带SNAPSHOT版本尾缀的包,默认部署策略是Disable redeploy
    不允许重复上传相同版本号信息的jar,避免包版本更新以后使用方无法获取到最新的包。
  • maven-snapshots (Versionpolicy=Snapshot)只允许上传带SNAPSHOT版本尾缀的包,默认部署策略是Allow
  • redeploy,允许重复上传相同版本号信息的jar,每次上传的时候会在jar的版本号上面增加时间后缀信息。 maven-central
    中央仓库的拷贝,如果环境可以访问中央仓库,则可以获取到相关的包,否则没用
  • maven-public
    仓库组,不是实际个一个仓库地址,只是将现有的组合到一次,可以通过它看到所属组内全部仓库的jar信息

在这里插入图片描述

我得说一下,我这里并不管其他角色和权限仓库之类的,不过如有需要,可以参考后面的博客。


四、上传naxus

(1)项目打包

setting.xml需要配置:

<servers>
		<server>
			<id>maven-snapshots</id>
			<username>账号名</username>
			<password>账号密码</password>
		</server>
		<server>
			<id>maven-releases</id>
			<username>账号名</username>
			<password>账号密码</password>
		</server>
	</servers>

在这里插入图片描述

pom.xml需要配置:

<!--    发布项目的时候有用 deploy-->
    <distributionManagement>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://www.javawwl.com:9081/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>maven-releases</id>
            <url>http://www.javawwl.com:9081/repository/maven-releases/</url>
        </repository>
    </distributionManagement>

就可以直接上传了,记得要配置好maven

在这里插入图片描述

在这里插入图片描述

(2)window本地maven仓库批量上传

在本地maven仓库下新建一个 mavenimport.sh
在这里插入图片描述

文件内容:

#!/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}/{} ;

打开此文件的cmd,运行命令:

mavenimport.sh -u 用户名 -p 密码 -r http://ip:端口/repository/maven-releases/

在这里插入图片描述

五、使用nexus

就像之前一样配置阿里的镜像,配置自己的镜像就行了。不过也有两种方式:

(1)第一种: 设置镜像仓库
setting.xml内

 <!-- 镜像仓库,将releases snapshots thirdparty的jar同步到一起-->
	<mirrors>
		<mirror>
			<!--This sends everything else to /public -->
			<id>maven-releases</id>
			<name> Maven Hundusn Yuntai Mirror(zjrc)</name>
			<mirrorOf>*</mirrorOf>
			<url>http://www.javawwl.com:9081/repository/maven-releases/</url>
		</mirror>   
	</mirrors>

(2)第二种: 配置全局pom.xml仓库地址
setting.xml内

<profiles>
	<profile>  
	    <id>jdk-1.8</id>  
	    <activation>  
			<activeByDefault>true</activeByDefault>  
			<jdk>1.8</jdk>  
		</activation>  
		<properties>  
			<maven.compiler.source>1.8</maven.compiler.source>  
			<maven.compiler.target>1.8</maven.compiler.target>  
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
		</properties>  
	</profile> 

   <!-- maven开发库 -->
   <profile>
       <id>dev</id>
          <repositories>

			<repository>
                 <id>maven-releases</id>
                 <url>http://www.javawwl.com:9081/repository/maven-releases/</url>
                 <releases>
                    <enabled>true</enabled>
					<updatePolicy>always</updatePolicy> 
                 </releases>
                 <snapshots>
                    <enabled>false</enabled>
                 </snapshots>
              </repository>
			  <repository>
                 <id>maven-snapshots</id>
				 <url>http://www.javawwl.com:9081/repository/maven-snapshots/</url>
                 <releases>
                    <enabled>false</enabled>
                 </releases>
                 <snapshots>
                    <enabled>true</enabled>
					<updatePolicy>always</updatePolicy> 
                 </snapshots>
              </repository>
			</repositories>
        </profile>
  </profiles>
	<activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>

(3)讲解一下

(3)参考setting.xml (大佬的)

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user, 
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in 
 |                 ${maven.home}/conf/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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>/home/maven/repository</localRepository> 
  -->
  <localRepository>D:\AboutWork\maven\repository</localRepository>
  
  <!--Maven是否需要和用户交互以获得输入。如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。 -->  
  <interactiveMode>true</interactiveMode>  
  
   <!--Maven是否需要使用plugin-registry.xml文件来管理插件版本。  -->  
   <!--如果设置为true,则在{user.home}/.m2下需要有一个plugin-registry.xml来对plugin的版本进行管理  -->  
   <!--默认为false。 -->  
   <usePluginRegistry>false</usePluginRegistry> 
   
   <!--表示Maven是否需要在离线模式下运行。如果构建系统需要在离线模式下运行,则为true,默认为false。  -->  
   <!--当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。  -->  
   <offline>false</offline>  
   
   <!--当插件的组织Id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。  -->  
   <!--该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId)。  -->  
   <!--当我们使用某个插件,并且没有在命令行为其提供组织Id(groupId)的时候,Maven就会使用该列表。  -->  
   <!--默认情况下该列表包含了org.apache.maven.plugins和 org.codehaus.mojo -->  
   <pluginGroups>
		<pluginGroup>org.mortbay.jetty</pluginGroup>
		<pluginGroup>org.codehaus.cargo</pluginGroup>
		<pluginGroup>com.hundsun.scm.maven.plugins</pluginGroup> 
		<pluginGroup>org.apache.maven.plugins</pluginGroup> 
		<pluginGroup>org.codehaus.mojo</pluginGroup>
   </pluginGroups>


  <!--用来配置不同的代理,多代理profiles可以应对笔记本或移动设备的工作环境:通过简单的设置profile id就可以很容易的更换整个代理配置。  -->  
    <proxies>  
            
        <!--代理元素包含配置代理时需要的信息
        <proxy>  
                
            代理的唯一定义符,用来区分不同的代理元素。 
            <id>myproxy</id>  
                
            该代理是否是激活的那个。true则激活代理。当我们声明了一组代理,而某个时候只需要激活一个代理的时候,该元素就可以派上用处。
            <active>true</active>  
                
            代理的协议。 协议://主机名:端口,分隔成离散的元素以方便配置。
            <protocol>http://…</protocol>  
                
            代理的主机名。协议://主机名:端口,分隔成离散的元素以方便配置。
            <host>proxy.somewhere.com</host>  
                
            代理的端口。协议://主机名:端口,分隔成离散的元素以方便配置。 
            <port>8080</port>  
                
            代理的用户名,用户名和密码表示代理服务器认证的登录名和密码。 
            <username>proxyuser</username>  
                
           代理的密码,用户名和密码表示代理服务器认证的登录名和密码。
            <password>somepassword</password>  
                
            不该被代理的主机名列表。该列表的分隔符由代理服务器指定;例子中使用了竖线分隔符,使用逗号分隔也很常见。
            <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>  
                
        </proxy>  
           -->
    </proxies>  

<!-- 	<server> -->
<!-- 		<id>nexus</id> -->
<!-- 		<username>readOnly</username> -->
<!-- 		<password>hscmreadonly</password> -->
<!-- 	</server> -->
 <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
    
	<servers>
		<server>
			<id>maven-snapshots</id>
			<username>username</username>
			<password>password</password>
		</server>
		<server>
			<id>maven-releases</id>
			<username>username</username>
			<password>password</password>
		</server>
	</servers>
    <!-- maven 默认的中央仓库 -->
    <!--
	<repositories>
		<repository>
			<id> central</id>
			<name> Maven Repository Switchboard</name>
			<layout> default</layout>
			<url> http://repo1.maven.org/maven2</url>
			<snapshots>
				<enabled> false</enabled>
			</snapshots>
		</repository>
	</repositories> 
    -->
   
   <!-- 镜像仓库,将releases snapshots thirdparty的jar同步到一起-->
	<mirrors>
		<mirror>
			<!--This sends everything else to /public -->
			<id>public</id>
			<name> Maven Hundusn Yuntai Mirror(zjrc)</name>
			<mirrorOf>*</mirrorOf>
			<url>http://nexusIp:8081/repository/maven-public/</url>
		</mirror>   
	</mirrors>
	

    
  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is 
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a 
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
	<profile>  
	    <id>jdk-1.8</id>  
	    <activation>  
			<activeByDefault>true</activeByDefault>  
			<jdk>1.8</jdk>  
		</activation>  
		<properties>  
			<maven.compiler.source>1.8</maven.compiler.source>  
			<maven.compiler.target>1.8</maven.compiler.target>  
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
		</properties>  
	</profile> 

   <!-- maven开发库 -->
   <profile>
       <id>dev</id>
          <repositories>

			<repository>
                 <id>maven-releases</id>
                 <url>http://nexusIp:8081/repository/maven-releases/</url>
                 <releases>
                    <enabled>true</enabled>
					<updatePolicy>always</updatePolicy> 
                 </releases>
                 <snapshots>
                    <enabled>false</enabled>
                 </snapshots>
              </repository>
			  <repository>
                 <id>maven-snapshots</id>
				 <url>http://nexusIp:8081/repository/maven-snapshots/</url>
                 <releases>
                    <enabled>false</enabled>
                 </releases>
                 <snapshots>
                    <enabled>true</enabled>
					<updatePolicy>always</updatePolicy> 
                 </snapshots>
              </repository>
			</repositories>
        </profile>
  </profiles>
	<activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>


然后就可以用了,
在这里插入图片描述

六、问题

1、问题一

nexus起不来。。。
我就是遇到过这个问题滴。
就是所谓交换区不够:

下面是我解决之后的图片,在没解决之前还全都是0。
在这里插入图片描述

按照步骤来就行

执行命令 free 查看内存是不是还有 最主要的是 看有没有交换空间 swap (这很重要)如果没有交换空间 或者交换空间比较小 要先安装交换空间 或者增大空间

(1)、创建swapfile:
root权限下,创建swapfile

dd  if=/dev/zero  of=swapfile  bs=1024  count=10000000  

(有时会遇到dd命令不识别 可能是你安装过一次了 没事 先把swapfile删除就ok了)

(2)、将swapfile设置为swap空间

mkswap swapfile

(3)、启用交换空间,这个操作有点类似于mount操作(个人理解):

 swapon  swapfile 

(删除交换空间 swapoff swapfile)
至此增加交换空间的操作结束了,可以使用free命令查看swap空间大小是否发生变化;

后言

如果还有其他需求的,比我这个详细的多: Linux Nexus Repository Manager OSS 3.18.1-01 搭建指南

毕竟我这个只是简单的教你如何上传依赖到私库,又如何使用罢了。

不过话说(○` 3′○),像这种东西感觉只适合那些大公司来使用(毕竟小公司也不会写那种自研的源码)
又或者是嫌下载依赖的速度还是不过快的人。

公司内部如果装了一个私库的话,把当前正在开发的项目所需依赖全放进去,那么如果有新成员来了,连接下载依赖肯定就快很多了。。。。

我的云服务器只是最辣鸡的一种(一核两G)
宽带只有1M,enn...但是感觉下载一下2,3M的依赖包还是没多大问题滴。

我看了下5M宽带的服务器,哇(っ °Д °;)っ,感觉一定很快吧。

在最后再附上娇小的服务器照:
服务器:“awsl” 。
在这里插入图片描述

有其他了解私库的用途的小伙伴也可以跟我讲一下咯,谢谢

posted @ 2020-07-01 16:38  陌陌卡上  阅读(1267)  评论(0编辑  收藏  举报