美文网首页
持续集成环境搭建(2)nexus搭建和使用

持续集成环境搭建(2)nexus搭建和使用

作者: 遇见你时风好暖 | 来源:发表于2018-12-17 23:45 被阅读0次

概述

Nexus Repository OSS 3是一个开源的仓库管理系统,提供了更加丰富的功能,而且安装、配置、使用起来也更加简单方便。OSS 3版本主要支持的仓库(Repository)包括如下:

  • bower
  • docker
  • maven
  • npm
  • nuget
  • pypi
  • raw
  • rubygems
  • yum

其中,对于上述每种类型的Nexus仓库,都分别具有如下主要3种类型:

  • hosted:本地仓库,可以将我们内部使用的一些Maven项目,发布到该类型仓库,供内部开发人员使用。
  • proxy:代理仓库,用来代理远程公共仓库,比如Maven中央仓库。
  • group:仓库组,用来合并多个类型(hosted/proxy)的仓库。

环境准备

jdk和maven安装

1. 解压安装包
[root@localhost ~]# tar -xvf jdk-8u192-linux-x64.tar -C /usr/local/
[root@localhost ~]# tar -xvf apache-maven-3.6.0-bin.tar -C /usr/local/
注: .tar.gz后缀的需要用参数-zxvf

2. 配置环境变量
[root@localhost ~]# vi /etc/profile
在最后添加上

export JAVA_HOME=/usr/local/jdk1.8.0_192
export JRE_HOME=/usr/local/jdk1.8.0_192
export MAVEN_HOME=/usr/local/apache-maven-3.6.0
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

3. 让配置生效
[root@localhost ~]# source /etc/profile

4. 验证
[root@localhost ~]# java -version
[root@localhost ~]# mvn -version

搭建nexus

1. 解压安装包
[root@localhost ~]# tar -xvf nexus-3.14.0-04-unix.tar -C /usr/local/
2. 修改配置
[root@localhost ~]# vi /usr/local/nexus-3.14.0-04/etc/nexus-default.properties

## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

可以看到,nexus运行的端口为8081

3. 开放防火墙端口8081
[root@localhost ~]# firewall-cmd --zone=public --add-port=8081/tcp --permanent
[root@localhost ~]# sudo systemctl reload firewalld

4. 启动
[root@localhost ~]# /usr/local/nexus-3.14.0-04/bin/nexus start
提示不建议采用root账户

WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
Starting nexus

查找nexus进程并杀掉
[root@localhost ~]# ps aux | grep nexus
[root@localhost ~]# kill 57340
添加新用户
[root@localhost ~]# useradd nexus
修改nexus文件的拥有者
[root@localhost ~]# chown -R nexus:nexus /usr/local/nexus-3.14.0-04/
[root@localhost ~]# chown -R nexus:nexus /usr/local/sonatype-work/
切换用户
[root@localhost ~]# su nexus
启动nexus
[nexus@localhost root]$ /usr/local/nexus-3.14.0-04/bin/nexus start

5. 登录访问
默认账户和密码 admin/admin123

6. 问题解决
System Requirement: max file descriptors [4096] likely too low, increase to at least [65536].
修改配置文件
[root@localhost ~]# vi /etc/security/limits.conf
新增下面两行

* soft nofile 65536
* hard nofile 65536

7. 开机启动
编辑文件
[root@localhost ~]# vi /etc/rc.d/rc.local
添加以下代码

su nexus -c '/usr/local/nexus-3.14.0-04/bin/nexus start'

在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
[root@localhost ~]# chmod +x /etc/rc.d/rc.local

nexus使用

设置maven使用本地仓库

1. 在maven的配置文件setting.xml加上以下代码

<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">
  ...
  <profiles>
    <profile>
      <id>nexus-profile</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>nexus-repository</id>
          <name>Nexus Repository</name>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://192.168.1.177:8081/repository/maven-public/</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>nexus-plugin</id>
          <name>Nexus Plugin Repository</name>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://192.168.1.177:8081/repository/maven-public/</url>
          <layout>default</layout>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus-profile</activeProfile>
  </activeProfiles>
</settings>

打包提交到本地仓库

1. 在setting.xml文件增加配置

  <servers> 
    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

2. 在项目的pom.xml加上

    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus ReleaseRepository</name>
            <url>http://192.168.1.177:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus SnapshotRepository</name>
            <url>http://192.168.1.177:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

3. 执行mvn deploy命令

以上例子可参考https://github.com/xiangxik/castle-microservices-platform.git

相关文章

网友评论

      本文标题:持续集成环境搭建(2)nexus搭建和使用

      本文链接:https://www.haomeiwen.com/subject/bbdfkqtx.html