基於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界面
在這裏插入圖片描述

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