基于verdaccio 搭建npm 私服工具

1.安装node环境
查看官方文档
2.安装verdaccio
加上–unsafe-perm的原因是防止报grywarn权限的错。

npm install -g verdaccio --unsafe-perm

3. 配置
(1)、修改配置文件
config.yaml在第一次启动之后生成

#vim /root/.config/verdaccio/config.yaml

# path to a directory with all packages
storage: ./storage   #npm包存放的路径
# path to a directory with plugins to include
plugins: ./plugins   

web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  #enable: false
  title: Verdaccio

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   #默认1000 修改为-1,禁止注册

# a list of other known repositories we can talk to
uplinks:
  npmjs:   
    url: https://registry.npmjs.org/  #配置上游的npm服务器,主要是用于请求的私有仓库不存在所需依赖包时去上游服务器拉取

packages:
  '@*/*':
    # scoped packages  ##配置权限管理
    access: $all
    publish: $authenticated
    proxy: 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 packages
    # (anyone can register by default, remember?)
    publish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

# You can specify HTTP/1.1 server keep alive timeout in seconds for incomming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enought.
server:
  keepAliveTimeout: 60

# To use `npm audit` uncomment the following section
middlewares:
  audit:
    enabled: true

# log settings
logs:
  - {type: stdout, format: pretty, level: http}
  #- {type: file, path: verdaccio.log, level: info}
listen: 0.0.0.0:4873                    # 允许任何人访问

(2)启动

verdaccio

在这里插入图片描述
4.pm2启动
安装pm2并使用pm2启动verdaccio,使用pm2托管的进程可以保证进程永远是活着的,尝试通过kill -9去杀verdaccio的进程发现杀了之后又自动启起来。推荐使用此种方式启动verdaccio.
(1)安装pm2

npm install -g pm2 --unsafe-perm

(2)使用pm2启动verdaccio

pm2 start verdaccio

(3)查看pm2 守护下的进程

pm2 status 

在这里插入图片描述
5、添加用户

npm adduser --registry http://x.x.x.x:4873    

在这里插入图片描述
6、verdaccio界面
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章