npm私服搭建

本文是在 centos7 下利用 nexus 搭建 npm 私服的整理

一、安装 JDK

1、下载 JDK

2、安装

tar zxvf jdk-8u191-linux-x64.tar.gz 
mv jdk1.8.0_191  /usr/local/

3、设置环境变量

vi /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_191
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile

4、查看

echo $JAVA_HOME
echo $PATH
java -version

二、安装 nexus

1、下载 nexus

2、解压

tar -zxvf nexus-3.14.0-04-unix.tar.gz -C /usr/local/

3、修改配置文件(可选)

// 端口
vi /usr/local/nexus-3.14.0-04/etc/nexus-default.properties

// 数据存储路径
/usr/local/nexus-3.14.0-04/bin/nexus.vmoptions

4、增加用户(可选)

useradd nexus
chown -R nexus:nexus /usr/local/nexus-3.14.0-04/
chown -R nexus:nexus /usr/local/sonatype-work/

如果使用的 root 用户运行会有警告信息

5、设置启动用户(可选)

vi /usr/local/nexus-3.14.0-04/bin/nexus.rc

添加一行

run_as_user="nexus"

6、修改 ulimit(可选)

vi /etc/security/limits.conf

添加

nexus - nofile 65536

重启,查看

ulimit -n

如果不修改

7、启动/停止

su nexus
/usr/local/nexus-3.14.0-04/bin/nexus start/stop/status/run

8、查看监听

netstat -lntp
ps:
netstat 安装:yum install net-tools
nexus 数据目录:/usr/local/sonatype-work

三、npm私服搭建

浏览器输入 http://localhost:8081 进入管理界面,默认账号密码 admin/ admin123

1、添加 npm

有三个选项可供选择,这里使用一种常用的方式,三种 npm 都分别创建

2、npm (proxy) 仓库

3、npm (hosted) 仓库

4、npm (group) 仓库

5、使用

在 .npmrc 文件中添加 registry = http://localhost:8081/repository/npm-g/ 

npm -loglevel info install axois

6、设置权限

npm login –registry=http://localhost:8081/repository/npm-g

7、发布

npm adduser –registry http://localhost:8081/repository/npm-g
npm publish –registry http://localhost:8081/repository/npm-g

参考资料:

http://www.cnblogs.com/grey-wolf/p/6480489.html

https://www.cnblogs.com/grey-wolf/p/6481166.html

https://blog.csdn.net/itKingOne/article/details/81448592

原文地址:https://www.cnblogs.com/lifefriend/p/10192756.html