当前位置: 移动技术网 > 科技>操作系统>Linux > Nexus Repository3安装和maven,npm配置(Linux)

Nexus Repository3安装和maven,npm配置(Linux)

2018年12月21日  | 移动技术网科技  | 我要评论

nexus repository下载

根据操作系统选择指定版本,本文针对linux安装,其他的安装过程可能有所差异。

安装

建议先创建一个nexus用户,将文件拷贝到/home/nexus

# 按具体下载文件名
tar -zxvf nexus-3.14.0-04-unix.tar.gz

# 按具体解压目录
cd nexus-3.14.0-04/bin


## 启动
./nexus start
# ./nexus stop #停止
# ./nexus status # 查看状态

配置修改

nexusrepository 默认占用8081端口,如果与其他服务有冲突,需要在sonatype-work/etc目录下创建一个nexus.properties,

注意不是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不建议在root用户下运行,需要创建用户nexus用户,修改bin/nexus.rc文件

run_as_user="nexus"

开机自启动

开启自启动有init.d和systemd两种方式。

init.d

1.创建一个nexus用户

2.拷贝nexus的软链接到init.d目录
注意:最好在root做自启动配置,省的没权限

# 原文件路径按实际
ln -s /home/nexus/nexus-3.14.0-04/bin/nexus /etc/init.d/nexus

3.1 chkconfig 写法(和3.2二选一)

cd /etc/init.d
chkconfig --add nexus
chkconfig --levels 345 nexus on

3.2 update-rc.d写法(和3.1 二选一)

cd /etc/init.d
update-rc.d nexus defaults
service nexus start

4.切换到nexus用户窗口,启动服务

su nexus

service nexus start

systemd

前提是服务器有安装systemd工具,一般cenos7默认安装。

创建一个nexus用户

在/etc/systemd/system/ 目录添加如下文件

nexus.service

[unit]
description=nexus service
after=network.target
  
[service]
type=forking
limitnofile=65536
execstart=/opt/nexus/bin/nexus start
execstop=/opt/nexus/bin/nexus stop
user=nexus
restart=on-abort
  
[install]
wantedby=multi-user.target
activate the service with the following commands:

启动服务命令

systemctl daemon-reload
systemctl enable nexus.service
systemctl start nexus.service

查看服务运行日志

tail -f /opt/sonatype-work/nexus3/log/nexus.log

maven仓库配置

admin账户登录,访问repository >repositories,仓库默认配置maven本地库和代理库

默认代理maven库地址是https://repo1.maven.org/maven2/,可以修改

npm仓库配置

npm仓库不是内置的,需要手动配置,需要配置release,snapshots,proxy三个资源库,同时通过public合并起来,对外提供服务

具体配置见下图:




maven私服使用

maven私服使用有两种方式,你可以任选一种

1.在maven的setting.xml配置mirror

<mirrors>
     <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/mvn/view</url>
        <mirrorof>central</mirrorof>
    </mirror>
    <mirror>
        <id>jboss-public-repository-group</id>
        <mirrorof>central</mirrorof>
        <name>jboss public repository group</name>
        <url>http://repository.jboss.org/nexus/content/groups/public</url>
    </mirror>
    <mirror>
        <id>ibiblio</id>
        <mirrorof>central</mirrorof>
        <name>human readable name for this mirror.</name>
        <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
    </mirror>
    <mirror>
        <id>central</id>
        <name>maven repository switchboard</name>
        <url>http://repo1.maven.org/maven2/</url>
        <mirrorof>central</mirrorof>
    </mirror>
    <mirror>
        <id>repo2</id>
        <mirrorof>central</mirrorof>
        <name>human readable name for this mirror.</name>
        <url>http://repo2.maven.org/maven2/</url>
    </mirror>
</mirrors>

2.在具体项目的pom.xml文件配置资源库

    <repositories>
        <repository>
            <id>nexus</id>
            <name>nexus repository</name>
            <url>http://192.168.3.28:8084/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <!--snapshots默认是关闭的,需要开启  -->
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>  

npm私服使用

如上npm,npm的私服地址为http://192.168.3.28:8084/repository/npm-public/

建议安装nrm工具,这样可以快速切换npm的资源库

# 安装nrm
npm install -g nrm

# 添加资源库
nrm add test http://192.168.3.28:8084/repository/npm-public/

# 切换资源库
nrm use test

maven私服发布

在pom.xml配置maven私服仓库地址,有snapshot和release两个仓库

<distributionmanagement>
        <repository>
            <id>nexus-maven-repository-releases</id>
            <url>http://192.168.3.28:8084/repository/maven-releases/</url>
        </repository>
        <snapshotrepository>
            <id>nexus-maven-repository-snapshots</id>
            <url>http://192.168.3.28:8084/repository/maven-snapshots/</url>
        </snapshotrepository>
    </distributionmanagement>

npm私服发布

自己开发的组件通过如下命令发布到npm私服

#  用户登录
npm login 

# 编译打包
npm init

# 发布
npm publish

这时候你会发现发布不上去,报401,即使你的用户名和密码都是对的

你需要将npm的认证组件在nexus中开启

maven和npm发布注意事项

npm和maven发布都不能用group类型的资源库,他们是没有发布权限,只有拉取权限,你需要找到对应group的hostd资源库做发布

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网