ubuntu20.04上使用 Verdaccio 搭建 npm 私有仓库

安装nvm

  1. 首先安装必要的工具:
apt update
apt install curl
  1. 下载并执行nvm安装脚本:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  1. 添加环境变量(如果安装脚本没有自动添加)。编辑 ~/.bashrc:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  1. 使环境变量生效:
source ~/.bashrc
  1. 验证安装:
nvm --version

常用nvm命令:

nvm install node        # 安装最新版node
nvm install 20.18.0    # 安装特定版本
nvm use 20.18.0        # 使用特定版本
nvm ls                 # 列出已安装的版本
nvm current            # 显示当前使用的版本
nvm alias default 20.18.0  # 设置默认版本

如果遇到网络问题,可以设置淘宝镜像:

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

安装 Verdaccio

# 必须要加 -g 全局安装
npm install verdaccio -g

安装成功之后随即在命令行输出 verdaccio 随即我们会看到服务已经运行;出现以下内容

v1.png

根据服务启动后信息不难得到两个重要信息

verdaccio 配置文件:/root/.config/verdaccio/config.yaml

verdaccio 默认启动:默认占用 4873 端口(使用云服务器的小伙伴记得开启安全组)。

注意: 可能有些小伙伴的启用端口前面显示的是 localhost:4873,如果出现这种情况打开安全组也是不生效的,以下附上解决方案。

使用 vim 打开配置文件。在首行新增 listen 0.0.0.0:4873,端口可以任意指定。0.0.0.0 就是表示当前主机的 IPV4 地址;之后再重启服务就,在浏览器输入服务器 IP 加端口就可以访问了。

我的/root/.config/verdaccio/config.yaml 配置文件:

listen: 0.0.0.0:4873
# path to a directory with all packages
storage: /home/lzq/.local/share/verdaccio/storage
# path to a directory with plugins to include
plugins: ./plugins
# 添加以下配置来增加最大包体积限制
max_body_size: 1000mb# https://verdaccio.org/docs/webui
web:title: Verdaccio# comment out to disable gravatar support# gravatar: false# by default packages are ordercer ascendant (asc|desc)# sort_packages: asc# convert your UI to the dark side# darkMode: true# html_cache: true# by default all features are displayed# login: true# showInfo: true# showSettings: true# In combination with darkMode you can force specific theme# showThemeSwitch: true# showFooter: true# showSearch: true# showRaw: true# showDownloadTarball: true#  HTML tags injected after manifest <scripts/># scriptsBodyAfter:#    - '<script type="text/javascript" src="https://my.company.com/customJS.min.js"></script>'#  HTML tags injected before ends </head>#  metaScripts:#    - '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>'#    - '<script type="text/javascript" src="https://browser.sentry-cdn.com/5.15.5/bundle.min.js"></script>'#    - '<meta name="robots" content="noindex" />'#  HTML tags injected first child at <body/>#  bodyBefore:#    - '<div id="myId">html before webpack scripts</div>'#  Public path for template manifest scripts (only manifest)#  publicPath: http://somedomain.org/# https://verdaccio.org/docs/configuration#authentication
auth:htpasswd:file: ./htpasswd# Maximum amount of users allowed to register, defaults to "+inf".# You can set this to -1 to disable registration.# max_users: 1000# Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".# algorithm: bcrypt # by default is crypt, but is recommended use bcrypt for new installations# Rounds number for "bcrypt", will be ignored for other algorithms.# rounds: 10# https://verdaccio.org/docs/configuration#uplinks
# a list of other known repositories we can talk to
uplinks:npmjs:url: https://registry.npmmirror.com/maxage: 30mtimeout: 600smax_fails: 5fail_timeout: 5mcache: true# Learn how to protect your packages
# https://verdaccio.org/docs/protect-your-dependencies/
# https://verdaccio.org/docs/configuration#packages
packages:'@*/*':# scoped packagesaccess: $allpublish: $authenticatedunpublish: $authenticatedproxy: npmjs'**':# 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/publish packages# (anyone can register by default, remember?)publish: $authenticatedunpublish: $authenticated# if package is not available locally, proxy requests to 'npmjs' registryproxy: npmjsserver:keepAliveTimeout: 60timeout: 600000rateLimit:windowMs: 1000max: 10000bodyParser:json:limit: '1000mb'    # JSON请求体积限制encoded:limit: '1000mb'    # URL编码请求体积限制# Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer# See: https://expressjs.com/en/guide/behind-proxies.html# trustProxy: '127.0.0.1'# https://verdaccio.org/docs/configuration#offline-publish
# publish:
#   allow_offline: false# https://verdaccio.org/docs/configuration#url-prefix
# url_prefix: /verdaccio/
# VERDACCIO_PUBLIC_URL='https://somedomain.org';
# url_prefix: '/my_prefix'
# // url -> https://somedomain.org/my_prefix/
# VERDACCIO_PUBLIC_URL='https://somedomain.org';
# url_prefix: '/'
# // url -> https://somedomain.org/
# VERDACCIO_PUBLIC_URL='https://somedomain.org/first_prefix';
# url_prefix: '/second_prefix'
# // url -> https://somedomain.org/second_prefix/'# security:
#   api:
#     legacy: true
#     # recomended set to true for older installations
#     migrateToSecureLegacySignature: true
#     jwt:
#       sign:
#         expiresIn: 29d
#       verify:
#         someProp: [value]
#    web:
#      sign:
#        expiresIn: 1h # 1 hour by default
#      verify:
#         someProp: [value]# https://verdaccio.org/docs/configuration#user-rate-limit
# userRateLimit:
#   windowMs: 50000
#   max: 1000# https://verdaccio.org/docs/configuration#max-body-size
# max_body_size: 10mb# https://verdaccio.org/docs/configuration#listen-port
# listen:
# - localhost:4873            # default value
# - http://localhost:4873     # same thing
# - 0.0.0.0:4873              # listen on all addresses (INADDR_ANY)
# - https://example.org:4873  # if you want to use https
# - "[::1]:4873"                # ipv6
# - unix:/tmp/verdaccio.sock    # unix socket# The HTTPS configuration is useful if you do not consider use a HTTP Proxy
# https://verdaccio.org/docs/configuration#https
# https:
#   key: ./path/verdaccio-key.pem
#   cert: ./path/verdaccio-cert.pem
#   ca: ./path/verdaccio-csr.pem# https://verdaccio.org/docs/configuration#proxy
# http_proxy: http://something.local/
# https_proxy: https://something.local/# https://verdaccio.org/docs/configuration#notifications
# notify:
#   method: POST
#   headers: [{ "Content-Type": "application/json" }]
#   endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken
#   content: '{"color":"green","message":"New package published: * {{ name }}*","notify":true,"message_format":"text"}'middlewares:audit:enabled: true# https://verdaccio.org/docs/logger
# log settings
log: { type: stdout, format: pretty, level: http }
#experiments:
#  # support for npm token command
#  token: false
#  # disable writing body size to logs, read more on ticket 1912
#  bytesin_off: false
#  # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string
#  tarball_url_redirect: 'https://mycdn.com/verdaccio/${packageName}/${filename}'
#  # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file
#  tarball_url_redirect(packageName, filename) {
#    const signedUrl = // generate a signed url
#    return signedUrl;
#  }# translate your registry, api i18n not available yet
# i18n:
# list of the available translations https://github.com/verdaccio/verdaccio/blob/master/packages/plugins/ui-theme/src/i18n/ABOUT_TRANSLATIONS.md
#   web: en-US

使用 pm2 管理 verdaccio

此时我们虽然能够访问到 npm 私服,但是有个很严重的问题,就是启动服务后在命令行中不能进行其他操作。这里推荐使用 pm2 对 verdaccio 进程进行管理。即使退出 ssh 连接也能在后台运行。

# 全局安装 verdaccio和pm2
$ npm install -g pm2
$ pm2 start verdaccio
[PM2] Starting /usr/local/bin/verdaccio in fork_mode (1 instance)
[PM2] Done.
┌─────┬──────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name         │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ verdaccio    │ default     │ N/A     │ fork    │ 20889    │ 0s     │ 0    │ online    │ 0%       │ 10.2mb   │ cm       │ disabled │
└─────┴──────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

常用命令

指令	  描述	                                    示例
pm2 -ls	  列出当前被 pm2 管理的所有进程	
pm2 stop  <app_name | namespace|id|'all'|json_conf>	关闭某个进程	pm2 stop vardaccio
pm2 restart <app_name|namespace|id|'all'|json_conf>	重启某个进程	pm2 restart verdaccio
pm2 delete <app_name|namespace|id]|'all'|json_conf>	删除某个进程	pm2 delete verdaccio
pm2 start <app_name|namespace|id|'all'|json_conf>	启动某个进程	pm2 start verdaccio

nrm 管理 npm 源

npm install -g nrm
# 添加私有库
$ nrm add localnpm http://服务器ip:4873# 查看现有的npm源
$ nrm ls
* npm -------- https://registry.npmjs.org/yarn ------- https://registry.yarnpkg.com/cnpm ------- http://r.cnpmjs.org/taobao ----- https://registry.npm.taobao.org/nj --------- https://registry.nodejitsu.com/npmMirror -- https://skimdb.npmjs.com/registry/edunpm ----- http://registry.enpmjs.org/localnpm -- http://服务器ip:4873/
# 设置npm源
$ nrm use localnpm 

发布包到私有库上

注册用户

# 注册用户
$ npm adduser
npm notice Log in on http://服务器ip:4873/
Username: yourusername
Password:
Email: (this IS public) xxxxxx@qq.com
Logged in as yourusername on http://服务器ip:4873/.

登录

# 登录用户
$ npm login
npm notice Log in on http://服务器ip:4873/
Username: yourusername
Password:
Email: (this IS public) xxxxxx@qq.com
Logged in as yourusername on http://服务器ip:4873/.
# 查看当前登录用户
$ npm who am i
yourusername

发布
进入含有package.json的目录,执行命令

# 发布当前包
$ npm publish
...
npm notice === Tarball Details ===
npm notice name:          marriage-service-manage
npm notice version:       3.2.1
npm notice package size:  11.9 MB
npm notice unpacked size: 22.3 MB
npm notice shasum:        cb0cb1535cedd1a36edb070d10829fb5fb1213ef
npm notice integrity:     sha512-WV65rERQZZona[...]iRNAtK7Kz+cxg==
npm notice total files:   725
npm notice
+ marriage-service-manage@3.2.1
# 最后看到 + [你的包名@版本号]既可

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/883251.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

精通正则表达式:在Python中实现高效的文本匹配与替换

精通正则表达式:在Python中实现高效的文本匹配与替换 正则表达式是文本处理中的一项强大工具,尤其是在Python中,它为我们提供了灵活而高效的文本匹配与替换能力。无论是在数据清洗、文本解析还是格式化输出中,正则表达式都能够大幅提高我们的工作效率。在这篇博文中,我们…

mysql建表

作业要求&#xff1a; 根据以下需求完成图书管理系统数据库及表设计&#xff0c;并建库建表&#xff0c;并截图创建表的详细信息(desc 表名),不用添加数据 1. 用户表: 字段: 姓名&#xff0c;用户名&#xff0c;密码&#xff0c;电话&#xff0c;住址&#xff0c;专业及年级…

命名空间std, using namespace std

命名空间std&#xff0c;using namespace std 在标准C以前&#xff0c;都是用#include<iostream.h>这样的写法的&#xff0c;因为要包含进来的头文件名就是iostream.h。标准C引入了名字空间的概念&#xff0c;并把iostream等标准库中的东东封装到了std名字空间中&#x…

系统设计-通用用户权限管理系统

通用用户权限管理系统 一、系统安全二、登录授权三、系统内部安全1. 相关实体1.1 实体关系(ER)2. 菜单权限3. 接口权限3.1 权限获取3.2 接口调用鉴权4. 数据权限四、其他一个没有权限控制的系统,是非常不安全的。 在日常业务运营的系统中台,基本都会存在用户的菜单权限控制,…

【华为路由】OSPF多区域配置

网络拓扑 设备接口地址 设备 端口 IP地址 RTA Loopback 0 1.1.1.1/32 G0/0/0 10.1.1.1/24 RTB Loopback 0 2.2.2.2/32 G0/0/0 10.1.1.2/24 G0/0/1 10.1.2.1/24 RTC Loopback 0 3.3.3.3/32 G0/0/0 10.1.2.2/24 G0/0/1 10.1.3.1/24 RTD Loopback 0 4.4.4…

与ai聊我的代码架构

以包目录结构模块&#xff0c;以*.py脚本收纳模块。 (笔记模板由python脚本于2024年10月25日 18:39:10创建&#xff0c;本篇笔记适合编程基础的coder翻阅) 【学习的细节是欢悦的历程】 Python 官网&#xff1a;https://www.python.org/ Free&#xff1a;大咖免费“圣经”教程《…

在线教育(培训+考试)/企业培训-企业培训平台-企业培训平台系统-企业内部培训系统-在线教育-Java语言开发

介绍 企业培训平台支持企业培训考试全流程&#xff0c;在线学习、在线考试&#xff0c;成熟的企业培训考试解决方案&#xff0c;充分满足企业培训需求。 独立部署&#xff0c;仅内部员工登录使用&#xff0c;稳定、安全、高效&#xff0c;满足企业、政府、教育行业的各种在线学…

STM32-Modbus协议(一文通)

Modbus协议原理 RT-Thread官网开源modbus RT-Thread官方提供 FreeModbus开源。 野火有移植的例程。 QT经常用 libModbus库。 Modbus是什么&#xff1f; Modbus协议&#xff0c;从字面理解它包括Mod和Bus两部分&#xff0c;首先它是一种bus&#xff0c;即总线协议&#xff0c;和…

希尔排序的增量和缩小增量问题

对于这个问题&#xff0c;我犹豫了很久。现在鼓起勇气来聊一聊。但是我仍然觉的自己会说不好。这里藏着一些令人惊讶的东西&#xff0c;一直沉睡在没有被注意的角落里。 现在不用y_tab解释器。直接用c 语言。 void shellsort(int a[], int n) {int i,j,t, gapn;for(gap/2;gap…

Maya---骨骼绑定

调节骨骼大小 回车键确认骨骼 FK子集跟父集走 IK子集不跟父集走 前视图中按shift键添加骨骼 清零、删除历史记录&#xff0c;创建新的物体

多元线性回归【正规方程/sklearn】

多元线性回归【正规方程/sklearn】 1. 基本概念1.1 线性回归1.2 一元简单线性回归1.3 最优解1.4 多元线性回归 2. 正规方程求最优解2.1 线性回归的损失函数&#xff08;最小二乘法&#xff09;2.2 推导正规方程2.3 正规方程练习2.4 使用sklearn计算多元线性方程2.5 凸函数 3. 线…

哪款宠物空气净化器噪音低?希喂、美的、安德迈测评分享

今年双11&#xff0c;宠物空气净化器到底应该如何选&#xff1f;在所有的家电品类里&#xff0c;宠物空气净化器算是比较特殊的那个&#xff0c;产品迭代太快&#xff0c;我们把今年双11在售的各大主流品牌的宠物空气净化器统一汇总整理&#xff0c;发现基本一多半都是24年下半…

【Unity 安装教程】

Unity 中国官网地址链接 Unity - 实时内容开发平台 | 3D、2D、VR & AR可视化https://unity.cn/首先我们想要安装Unity之前&#xff0c;需要安装Unity Hub&#xff1a; Unity Hub 是 Unity Technologies 开发的一个集成软件&#xff0c;它为使用 Unity 引擎的开发者提供了一…

jaavascript使用正则表达式校验字符串pwd,是否符合 包含大写小写数字特殊字符长度超过8位

当然&#xff0c;您可以使用JavaScript中的正则表达式来校验一个字符串&#xff08;例如密码&#xff09;是否符合包含大写字母、小写字母、数字和特殊字符&#xff0c;并且长度超过8位的要求。以下是一个示例代码&#xff1a; function validatePassword(password) {// 定义正…

使用Angular构建动态Web应用

&#x1f496; 博客主页&#xff1a;瑕疵的CSDN主页 &#x1f4bb; Gitee主页&#xff1a;瑕疵的gitee主页 &#x1f680; 文章专栏&#xff1a;《热点资讯》 使用Angular构建动态Web应用 1 引言 2 Angular简介 3 安装Angular CLI 4 创建Angular项目 5 设计应用结构 6 创建组件…

Nature Communications|一种3D打印和激光诱导协同策略用于定制功能化器件(3D打印/激光直写/柔性电子/人机交互/柔性电路)

美国密苏里大学机械与航天工程系Jian Lin团队,在《Nature Communications》上发布了一篇题为“Programmed multimaterial assembly by synergized 3D printing and freeform laser induction”的论文。论文内容如下: 一、 摘要 在自然界中,结构和功能材料经常形成程序化的三…

《面向对象系统分析与设计》三级项目

文章目录 一、项目总体要求<设计模式应用>第一次文档要求第二次文档要求 二、示例第一次文档 - 设计原则应用1、题目描述2、设计:(1&#xff09;优化理由陈述(2&#xff09;类图(3)实现代码 第二次文档 - 设计模式应用1、题目描述2、设计:(1) 优化理由陈述(2&#xff09;…

Python基础之循环语句

在Python的编程世界里&#xff0c;循环结构犹如一把神奇的钥匙&#xff0c;开启高效处理数据和重复执行任务的大门。它赋予程序员强大的力量&#xff0c;让代码充满活力。Python主要有两种类型的循环语句&#xff1a;for循环和while循环。 一、for循环 for循环通常用于遍历一个…

Redis学习文档(常见面试题)

什么是Redis&#xff1f; Redis本质上是一个Key-Value类型的内存数据库&#xff0c;很像memcached&#xff0c;整个数据库统统加 载在内存当中进行操作&#xff0c;定期通过异步操作把数据库数据flush到硬盘上进行保存。因为是 纯内存操作&#xff0c;Redis的性能非常出色&…

深入探讨 Linux 命令行中的筛选方法与技巧

深入探讨 Linux 命令行中的筛选方法与技巧 1. 筛选命令概述2. 结合筛选的基本方法awk 筛选方法grep 筛选方法find 筛选方法 3. awk、grep 和 find 筛选参数解析4. awk、grep 和 find 的实用场景5. 如何将筛选逻辑应用到其他命令5. 高级组合技巧 在 Linux/Unix 系统中&#xff0…