linux系统npm私服搭建
搭建环境:centos7 需要4核cpu
一、安装基础环境
1.安装Java(直接用yum安装)
[root@test ~]# yum install java -y
2.查看Java是否安装好
[root@test ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
二、安装nexus
1.下载nexus
下载地址:https://www.sonatype.com/download-oss-sonatype (点击OSS下载最新版本)
2.解压
[root@test ~]# tar xf nexus-3.23.0-03-unix.tar.gz -C /usr/local/
3.修改配置文件(可选,如果端口冲突可以修改端口,默认8081)
#端口
[root@test ~]# vim /usr/local/nexus-3.23.0-03/etc/nexus-default.properties
application-port=8081
#数据存储路径
[root@test ~]# vim /usr/local/nexus-3.23.0-03/bin/nexus.vmoptions
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=2G
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3 #数据存储路径
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
4.增加用户(可选)
[root@test ~]# useradd nexus
[root@test ~]# chown -R nexus:nexus /usr/local/nexus-3.23.0-03
[root@test ~]# chown -R nexus:nexus /usr/local/sonatype-work/
如果使用的root用户运行会有警告
5.设置启动用户(可选)
[root@test ~]# vim /usr/local/nexus-3.23.0-03/bin/nexus.rc
run_as_user="nexus"
6.修改 ulimit(可选)
#修改ulimit最大文件限制数
[root@test ~]# echo ulimit -n 65536 >>/etc/profile
[root@test ~]# source /etc/profile
#查看
[root@test ~]# ulimit -n
65536
7.启动/停止
[root@test ~]# su nexus
[nexus@grafana root]$
/usr/local/nexus-3.14.0-04/bin/nexus start/stop/status/run
8.查看监听
[root@test ~]# netstat -lntp | grep 8081
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 8563/java
三、npm私服搭建
浏览器输入 http://localhost:8081 进入管理界面,默认账号密码 admin 密码在:/usr/local/sonatype-work/nexus3/admin.password(登录的时候登录界面会告诉你,登录进去之后记得先修改密码)
登录进去的页面
这里创建一个npm组、一个npm代理(代理到https://registry.npm.taobao.org)、一个本地npm
1.创建npm代理
2.创建本地npm
3.创建npm组
4.配置node的仓库地址
1) 首先查看nodejs的默认仓库地址
[root@test ~]# npm config get registry
https://registry.npmjs.org/
2) 查看搭建好的npm私服地址
#注意IP地址是你搭建服务的IP或者是域名
#添加本地源
[root@test ~]# npm config set registry http://111.111.111.111:8082/repository/npm-group/
#查看本地源
[root@test ~]# npm config get registry
http://111.111.111.111:8082/repository/npm-group/
至此搭建完毕。