ndoe.js 和npm私有仓库的搭建
下载nodejs的压缩包 网址:https://nodejs.org/en/
下载以tar.xz结尾的包例如:node-v8.9.4-linux-x64.tar.xz
上传包到制定的目录 可以用lrzsz
解压:xz -d
node-v8.9.4-linux-x64.tar.xz
然后在 拆包: tar –xvf node-v8.9.4-linux-x64.tar
配置环境变量在/etc/profile
Vim /etc/profilr 最后加入node的变量
export NODE=/root/node-v8.9.4-linux-x64 #node的安装路径
export PATH=$PATH:$NODE/bin #node的bin目录
推出声明一下
Source /etc/profile #环境变量就设好了
查看是否安装成功:出现版本号就是安装成功了

配置npm的源:
npm set registry https://registry.npm.taobao.org/ # 推荐淘宝npm镜像
安装配置sinopia
npm install -g sinopia
启动sinopia
输入:sinopia 启动了就

配置文件config.yaml如下:
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
# Look here for more config file examples:
# https://github.com/rlidwka/sinopia/tree/master/conf
# path to a directory with all packages
storage: /home/{user}/.local/share/sinopia/storage # 库存路径,需要考虑磁盘空间
web: # 自定义web项,即浏览器访问页面
# web interface is disabled by default in 0.x, will be enabled soon in 1.x
# when all its issues will be fixed
# set this to `true` if you want to experiment with web ui now;
# this has a lot of issues, e.g. no auth yet, so use at your own risk
#enable: true
title: Sinopia
# logo: logo.png
# template: custom.hbs
auth:
htpasswd:
file: ./htpasswd # 添加用户(npm adduser)后自动创建,保存用户信息,可以初始化用户
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
#max_users: 1000 # 设置为-1不能npm adduser
# a list of other known repositories we can talk to
uplinks: # 可以配置多个上游地址,后面packages中的proxy指定用哪个
npmjs:
url: https://registry.npm.taobao.org/ # 更改此上游地址
# amount of time to wait for repository to respond
# before giving up and use the local cached copy
#timeout: 30s # 请求上游地址超时时间
# maximum time in which data is considered up to date
# default is 2 minutes, so server won't request the same data from
# uplink if a similar request was made less than 2 minutes ago
#maxage: 2m # 包过期时间
# if two subsequent requests fail, no further requests will be sent to
# this uplink for five minutes
#max_fails: 2 # 容许依赖请求最大失败数
#fail_timeout: 5m # 依赖请求超时时间
packages: # 包的权限管理,$all为所有人,$authenticated为通过验证人
# 分布和安装两种权限,值可以特指某几人
'@*/*': # 跟package.json中的name属性进行匹配
# scoped packages
access: $all
publish: $authenticated
'*':
# allow all users (including non-authenticated users) to read and
# publish all packages
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish packages
# (anyone can register by default, remember?)
publish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
listen: 0.0.0.0:4873 # 设置监听地址,0.0.0.0匹配本机地址
# if you use nginx with custom path, use this to override links
#url_prefix: https://dev.company.local/sinopia/
# Configure HTTPS, it is required if you use "https" protocol above.
#https:
# key: path/to/server.key
# cert: path/to/server.crt
# you can specify proxy used with all requests in wget-like manner here
# (or set up ENV variables with the same name)
#http_proxy: http://something.local/ # 设置代理服务器
#https_proxy: https://something.local/
#no_proxy: localhost,127.0.0.1
# maximum size of uploaded json document
# increase it if you have "request entity too large" errors
#max_body_size: 1mb # http请求body大小
修改uplinks及listen值,同上,重启sinopia
如果想引用别的配置文件,请通过sinopia -c <配置文件>指定
用pm2托管sinopia
上面方式启动sinopia只是暂时的,退出命令行就没有了,因此需要一个长期开启sinopia方案,通过pm2托管,可以让sinopia进程永远活着,就算意外挂了也可自动重启。
安装pm2
$ npm install -g pm2
安装完后,使用pm2启动sinopia
$ pm2 start sinopia
关闭时
pm2 stop sinopia
最后更改npm源地址为私有库地址
$ npm set registryhttp://{服务器ip}:4873/# 内网测试可行
Nrm是npm的管理工具:
nrm的安装:

添加私有仓库
nrm add mynpm http://192.168.44.139:4873
使用私有仓库
nrm use mynpm
测试私有仓库
$ mkdir test
$ cd test
$ npm install webpack# 第一次安装比较慢
...
$ rm -rf webpack
$ npm install webpack # 第二次安装就比较快了
搭建好私有npm仓库后遇到什么坑?
我发现使用nrm切换到私有npm仓库对应的源后,下载带@ 符号的包都下载失败,比如下载 @angular/core,就会下载失败,这是为什么呢,查阅了一些资料,发现这其实是Sinopia自己的bug,bug产生的原因就是:sinopia在代理到npmjs.org公有库时将@符号转码为%40,致使在公有库中找不到对应的包,返回404 ,简单点说就是 @angular/core 代理请求的时候被转换成了 %40angular/core,所以我们需要在代理请求发出之前将其转回 @angular/core
修改sinopia源码:修改位于sinopia/lib/up-storage.js文件第10行:将var encode = encodeURIComponen;,更改为:var encode = function(thing) {return encodeURIComponent(thing).replace(/^%40/, '@');}; ,这段代码的含义就是将%40转回@,于是就解决了不能下载带有@符号的npm包的bug
现在sinopia不好用有时解决不了下载带@ 符号的包都下载失败的问题 ,就不需要安装sinopia可以安装更好的verdaccio
安装 verdaccio
npm install –g verdaccio
安装完以后可以启动
verdaccio 例:

会显示撇子文件的路径等等,但是这个是其他运行,退出终端就挂,所以要安装mp2 来管理verdaccio
修改配置文件Verdaccio
cd /root/.config/verdaccio
vim config.yaml (实例)(也可以参考https://verdaccio.org/docs/en/configuration)



(2)安装pm2进程管理 并启动verdaccio服务
•npm install –g pm2
•ls –s/root/node-v6.9.5-linux-x64/bin/pm2 /usr/local/bin/pm2 (这不可以不做)
•pm2 start `which verdaccio` #启动

网上的资料散 搞了好半天,总算完成了 哈哈哈哈
可以参考 https://segmentfault.com/a/1190000005790827
ndoe.js 和npm私有仓库的搭建的更多相关文章
- NPM 私有仓库的搭建
NPM 私有仓库的搭建 为什么搭建私有仓库 balabala,当然是有需求的时候嘛 搭建流程 介绍和安装verdaccio 备注: 程序启动后,配置文件为/home/work/.config/verd ...
- 使用verdaccio 搭建npm私有仓库
使用verdaccio 搭建npm私有仓库 1. 为什么要搭建私有的npm仓库? 随着公司的业务越来越复杂,项目迭代速度也越来越快,那么项目间的常用的业务代码共享变得非常之有必要.但是对于公司的 ...
- docker学习------docker私有仓库的搭建
192.168.138.102:23451.私有仓库的搭建(docker pull registry),拉取最新的镜像 2.查看拉取的仓库镜像(docker images) 3.启用registry镜 ...
- docker 私有仓库简易搭建
概要 本地私有仓库 局域网私有仓库 总结 概要 docker hub 使用非常方便,而且上面有大量的镜像可以使用. 但是,每次都远程下载镜像速度非常慢,如果能在本地做一个 docker 的仓库,多人协 ...
- Git 安装及用法 github 代码发布 gitlab私有仓库的搭建
版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统. 这个版本控制软件,有 svn还有git,是一个工具. git是由linux的作者开发的 git是一个分布式版本控制系统 ...
- 使用 docker + verdaccio 搭建npm私有仓库
本文介绍如何使用 verdaccio 搭建私有npm仓库,以及使用 docker 时如何映射到本地目录,方便简单对仓库进行各种操作.系统环境是 Linux. verdaccio verdaccio 是 ...
- 使用verdaccio+docker搭建npm私有仓库以及使用
公司内部前端组件或库的共享等,搭建一个npm私有库就很方便,现在中大型公司也基本都有自己的npm私有库,这篇文章,和大家一起共同搭建一个npm私有库,共同学习 前置条件 一台电脑 可以联网 一.安装d ...
- npm私有仓库 配置verdaccio在docker环境
前端开发过程中,少不了自己封装一些通用的包,但又不想放在公共的平台,所以搭建一个npm私有的仓库是很有必要的. 在这里简单介绍如何使用 verdoccio 在docker环境下的配置.verdocci ...
- Docker私有仓库Registry 搭建
1. 关于Registry 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候,我们的使用场景需要我们拥有一个私有 ...
随机推荐
- Zookeeper浏览器工具和Eclipse插件
公司很多产品会使用zookeeper,比如Meta消息中间件,在测试的过程中,我们经常需要查询zookeeper里面的信息来精确定位问题.目前项目中有开发团队自己写的浏览器node-zk-browse ...
- Spring注解之@validated的使用
spring-boot中可以用@validated来校验数据,如果数据异常则会统一抛出异常,方便异常中心统一处理.比如,我们判断一个输入参数是否合法,可以用如下方式 一 基础使用 因为spring-b ...
- OllyDbg安装教程
1.下载 http://tools.pediy.com/windows/debuggers.htm 我们这里选择OllyDbg1.10下载 2.安装 解压下载的压缩包直接双击启动即可使用 3.插件安装 ...
- System.gc()和-XX:+DisableExplicitGC启动参数,以及DirectByteBuffer的内存释放
首先我们修改下JVM的启动参数,重新运行之前博客中的代码.JVM启动参数和测试代码如下: -verbose:gc -XX:+PrintGCDetails -XX:+DisableExplicitGC ...
- Spring之缓存注解@Cacheable
https://www.cnblogs.com/fashflying/p/6908028.html https://blog.csdn.net/syani/article/details/522399 ...
- linux磁盘管理 磁盘查看操作
df查看磁盘分区使用状况 df --显示磁盘分区使用状况 'l' 仅显示本地磁盘(默认) 'a' 显示所有文件系统的磁盘使用情况,包含比如/proc/ 'h' 以1024进制计算最合适的单位显示磁盘容 ...
- html <iframe>介绍
iframe 元素会创建包含另外一个文档的内联框架 属性 值 描述 align left.right.top.middle.bottom 不赞成使用.请使用样式代替.规定如何根据周围的元素来对齐此框架 ...
- centos6.5 安装php-5.6.31
1 从PHP官网下载所需要的PHP版本 下载地址: http://php.net/get/php-5.6.31.tar.gz/from/a/mirror 把下载好的文件上传到服务器 2 安装PHP ...
- vue中的axios
数据的获取最常用的就是用ajax,但在vue框架中,axios则更为方便.它是基于es6的promise 以下内容引用自[最骚的就是你] 不再继续维护vue-resource,并推荐大家使用 axio ...
- lodash 学习资料
lodash.js 是什么不多说,工作时间长了就基本绕不过去他,工作项目中也很好的弥补angular ,jquery 的不足,由中文bootstrap 退出的中文版学习资料 http://lodash ...