npm私有库verdaccio部署

安装

1
npm install --global verdaccio

将数据存储到/data/verdaccio的话,按下面的方法配置

配置文件

1
2
mkdir /data/verdaccio
vim /data/verdaccio/config.yaml

内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
storage: /data/verdaccio/storage
auth:
htpasswd:
file: /data/verdaccio/htpasswd
algorithm: bcrypt
rounds: 10
max_users: -1
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
access: $authenticated
publish: $authenticated
proxy: npmjs
'**':
access: $authenticated
publish: $authenticated
proxy: npmjs
web:
enable: true
title: 前端私有库
login: true
listen: 0.0.0.0:4873
max_body_size: 100mb
log: { type: stdout, format: pretty, level: http }

配置说明: 需要管理员手动新增用户,只有授权的用户才能查看和上传包,上游为npm官方库。

启动

新建启动脚本

1
vim /data/verdaccio/start.sh

内容:

1
verdaccio --config /data/verdaccio/config.yaml

添加执行权限

1
chmod +x /data/verdaccio/start.sh

使用pm2管理服务

1
2
npm i -g pm2
pm2 start /data/verdaccio/start.sh -n verdaccio

开机自启

1
2
pm2 startup
pm2 save

添加用户

创建 Bcrypt格式的htpasswd文件并添加一个用户和密码

1
htpasswd -bBc /data/verdaccio/htpasswd user password

继续添加一个用户的话用下面的命令

1
htpasswd -bB /data/verdaccio/htpasswd user2 password2
作者

全肝鸽鸽

发布于

2023-03-23

更新于

2024-04-30

许可协议

评论