linux 安装nexus

 

Sonatype nexus是一款Maven仓库管理软件。

 

一、硬件环境要求

CPU(推荐1C+) 系统默认要求4C+,低于4C有警告

内存(推荐2G+)

硬盘(推荐40GB+)

 

二、安装依赖环境

1、JDK

java -version    // 检查
yum install java-1.8.0-openjdk* -y    // 安装

 

yum安装包,可能遇到的错误:
Failed to download metadata for repo ‘AppStream’
错误原因:
CentOS 8停止更新后,CentOS开发团队移除了官方镜像源上关于CentOS 8所有的包,如果yum命令安装包需要更换下载源
错误处理:
// 进入目录: cd /etc/yum.repos.d/ // 修改源链接 sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* // mirror.centos.org 改成 vault.centos.org sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

 

三、安装nexus

 官方下载(列表):https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3

#创建目录
cd /usr/local && mkdir nexus && cd nexus

#官方下载
wget https://download.sonatype.com/nexus/3/nexus-3.38.0-01-unix.tar.gz    // 此版本用迅雷下载较快 版本发布日期2021年7月

#解压
tar -zxvf nexus-3.38.0-01-unix.tar.gz

#重命名
mv nexus-3.38.0-01  nexus

#目录结构说明(了解)
nexus    //nexus 服务器相关的文件
sonatype-work    //nexus工作数据文件,存放生成的配置文件、日志文件、仓库文件等

 

四、配置与访问

#配置端口(可选)
vi /usr/local/nexus/nexus/etc/nexus-default.properties

#虚拟机 运行参数配置(可选)
vi nexus/bin/nexus.vmoptions

#运行角色配置(可选)
vi nexus/bin/nexus    // 将run_as_user修改为root,若提示 Detected execution as "root" user.  This is NOT recommended! 可设置run_as_root=true,改为false

#启动
nexus/bin/nexus start    //显示 Started Sonatype Nexus OSS 启动成功
#访问 https://IP:8081

#登录
admin/1

 

五、设置开机启动

# (1)创建nexus启动脚本
cd /etc/init.d
vi  nexus

# (2)脚本内容
#!/bin/bash
#chkconfig:2345 20 90
#description:nexus
#processname:nexus

#设置JDK路径(可忽略)
#查看通过yum安装的jdk路径:ls -lrt /etc/alternatives/java 或 ls -lrt /usr/bin/java #export JAVA_HOME
=/root/apps/jdk1.8/ case $1 in start) su root /usr/local/nexus/nexus/bin/nexus start;; stop) su root /usr/local/nexus/nexus/bin/nexus stop;; status) su root /usr/local/nexus/nexus/bin/nexus status;; restart) su root /usr/local/nexus/nexus/bin/nexus restart;; dump) su root /usr/local/nexus/nexus/bin/nexus dump;; console) su root /usr/local/nexus/nexus/bin/nexus console;; *) echo "Usage: nexus {start|stop|run|run-redirect|status|restart|force-reload}" esac # (3)给脚本添加执行权限 chmod +x /etc/init.d/nexus # (4)测试脚本 service nexus status # (5)添加到开机启动 chkconfig nexus on # (6)查看开机启动列表 chkconfig --list

 

六、nexus 3.x 忘记admin密码

// 停止nexus服务
service nexus stop

// 进入安装目录
cd /usr/local/nexus/nexus

// 进入OrientDB控制台,进入成功后命令行变为 orientdb>
java -jar ./lib/support/nexus-orient-console.jar

// 连接数据库,连接成功后命令行变为 orientdb {db=security}>
connect plocal:../sonatype-work/nexus3/db/security admin admin

// 重置密码为admin123
update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"

// 退出OrientDB控制台
exit

// 启动nexus服务
service nexus start

 

七、其他异常处理

提示:Recommended file descriptor limit is 65536 but count is 4096. 警告

// 处理方式
vi /etc/security/limits.conf

// 在最末尾加入:
# End of file
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072

// 重启验证
ulimit -Sn
ulimit -Hn

 

提速:配置

①配置阿里云代理

阿里云public仓库地址:https://maven.aliyun.com/repository/public

 

②设置public库添加ali-repo,注意顺序,排在中央库前面。(顺序:先请求阿里云仓库,阿里云仓库找不到的情况再请求中央仓库)

   

问题:私服未起作用,项目配置私服以后,未经过私服下载依赖包(401),通过settings.xml文件中mirror资源(中央仓库或其他,例如:阿里镜像)下载。

解决:设置所有人均可访问私服,不要限制访问。(正规处理:当然是配置用户、权限了)

 

提示:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project sc2022:

Deployment failed: repository element was not specified in the POM inside distributionManagement element 

<!-- 添加 maven-deploy-plugin 插件 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

 

七、添加私有依赖包(JDBC)

1、添加私有资源 (jdbc)

 

八、settings.xml

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

<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>D:/maven-repository</localRepository>

  <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>password</password>
    </server>
  </servers>

<mirrors>
  <mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <name>nexus</name>
    <!-- <url>https://maven.aliyun.com/repository/public/</url> -->
    <url>http://192.168.1.1:8081/repository/maven-public/</url>
  </mirror>
</mirrors>

  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus-public</id>
          <url>http://192.168.1.1:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>nexus-public</id>
          <url>http://192.168.1.1:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
 
 <!-- 激活配置 -->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

</settings>

规则解释: 

<mirror> 中 mirrorOf 的值为 星号 时,表示该镜像代理所有远程仓库,任何对于远程仓库的下载请求都会被转至该镜像服务。

<mirror> 中 mirrorOf 的值为 central 时,表示该镜像代理 central 远程仓库,对 central 远程仓库下载时请求会被转至该镜像服务。

当 <mirror> 中 mirrorOf 的值为 星号 时,<profile> 中的配置就无关紧要了,因为所有的请求都会通过镜像中配置的服务地址进行访问。

 

posted @ 2021-09-08 09:53  vv_online  阅读(1490)  评论(0编辑  收藏  举报