centos 系統使用verdaccio搭建npm私庫

1.安裝nodejscss

1.1 下載nodejs包
[root@verdaccio www]# yum install wget
[root@verdaccio www]# wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz
--2019-07-02 22:01:02-- https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz
Resolving nodejs.org (nodejs.org)... 104.20.22.46, 104.20.23.46, 2606:4700:10::6814:172e, ...
Connecting to nodejs.org (nodejs.org)|104.20.22.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13039792 (12M) [application/x-xz]
Saving to: ‘node-v10.16.0-linux-x64.tar.xz’

100%[==============================================================================>] 13,039,792 6.87MB/s in 1.8s

2019-07-02 22:01:05 (6.87 MB/s) - ‘node-v10.16.0-linux-x64.tar.xz’ saved [13039792/13039792]

[root@verdaccio www]# tar -xf node-v10.16.0-linux-x64.tar.xz
[root@verdaccio www]# mv node-v10.16.0-linux-x64 node-v10.16.0node

 

1.2 測試node是否安裝成功
[root@verdaccio www]# node -v
v10.16.0
[root@verdaccio www]# npm -v
6.9.0linux

 

1.3 配置全局
[root@verdaccio www]# vim /etc/profile
++++++++++++++++++++++++++++++++++++++++++++
export NODE_HOME=/data/www/node-v10.16.0/
export PATH=$NODE_HOME/bin:$PATH
++++++++++++++++++++++++++++++++++++++++++++
[root@verdaccio www]# source /etc/profilenginx

 

 

2.安裝verdaccio
[zhou@verdaccio node-v10.16.0]$ npm install -g verdaccio --unsafe-perm
npm WARN deprecated async@3.0.1-0: 3.0.0 is out!
/data/www/node-v10.16.0/bin/verdaccio -> /data/www/node-v10.16.0/lib/node_modules/verdaccio/bin/verdaccio

> dtrace-provider@0.8.7 install /data/www/node-v10.16.0/lib/node_modules/verdaccio/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

make: Entering directory `/data/www/node-v10.16.0/lib/node_modules/verdaccio/node_modules/dtrace-provider/build'
TOUCH Release/obj.target/DTraceProviderStub.stamp
make: Leaving directory `/data/www/node-v10.16.0/lib/node_modules/verdaccio/node_modules/dtrace-provider/build'
+ verdaccio@4.0.4
added 241 packages from 248 contributors in 56.497sdocker

 

 

 

3.配置npm

1.安裝完須要啓動(執行 /data/app/node-v10.16.0/bin/verdaccio )一下,才能生成配置文件。vim

[zhou@verdaccio ~]$ cd /data/app/node-v10.16.0/
[zhou@verdaccio node-v10.16.0]$ verdaccio
warn --- config file - /data/www/node-v10.16.0/verdaccio/config.yaml
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http://www.javashuo.com/tag/http address - http://localhost:4873/ - verdaccio/4.0.4centos

 

2.修改配置文件 config.yaml,在其最後添加監聽端口(使其可在外網訪問)api

[zhou@verdaccio node-v10.16.0]$ vim /data/www/node-v10.16.0/verdaccio/config.yaml
須要改動2處:瀏覽器

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

uplinks:
npmjs:
url: http://r.cnpmjs.org/ #npm鏡像下載地址:

listen: 0.0.0.0:4873 #指定ip端口: 在配置文件末尾添加以下:(由於默認是localhost:4873 (弊端:只能在本機訪問))

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

3.啓動verdaccio

[zhou@verdaccio node-v10.16.0]$ verdaccio
*** WARNING: Verdaccio doesn't need superuser privileges. Don't run it under root! ***
warn --- config file - /data/www/node-v10.16.0/verdaccio/config.yaml
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http://www.javashuo.com/tag/http address - http://0.0.0.0:4873/ - verdaccio/4.0.4

 

 

4.瀏覽器打開地址   http://10.10.1.103:4873/    http://ip:4873

[zhou@verdaccio node-v10.16.0]$ verdaccio
*** WARNING: Verdaccio doesn't need superuser privileges. Don't run it under root! ***
warn --- config file - /data/www/node-v10.16.0/verdaccio/config.yaml
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http://www.javashuo.com/tag/http address - http://localhost:4873/ - verdaccio/4.0.4
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /', bytes: 0/575
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/manifest.b6891b53f2830d5ac3cb.js', bytes: 0/1547
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/0.style.cdd1fdf79cd6bec30c42.css', bytes: 0/863
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/main.b6891b53f2830d5ac3cb.js', bytes: 0/18698
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/favicon.ico', bytes: 0/2054
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/vendors.b6891b53f2830d5ac3cb.js', bytes: 0/178097
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/favicon.ico', bytes: 0/2054
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', bytes: 0/3
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/93df1ce974e744e7d98f5d842da74ba0.svg', bytes: 0/753
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/3025c327f6f127d5190f14b16e75b41b.svg', bytes: 0/851
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/b1e0d4d4ee23474aee6616f444fc7aa9.svg', bytes: 0/1045
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/d96f386211a24e791aaa1f929fd56f91.svg', bytes: 0/1291
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/de092a6cac20ccf2cd373644425a13ce.svg', bytes: 0/577
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fa99a58eb30e323243a5b2dbae7eacdd.svg', bytes: 0/898
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/ac0877b3e5dab78d7b5319b32cb03b11.svg', bytes: 0/833
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/24fd3a77ee5710ead382075bbfa36d17.svg', bytes: 0/380
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fonts/roboto-latin-400.woff2', bytes: 0/15344
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fonts/roboto-latin-500.woff2', bytes: 0/15552
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/1.b6891b53f2830d5ac3cb.js', bytes: 0/6598
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/6f6560222974090c1ef11e84623ff803.svg', bytes: 0/692
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/5.b6891b53f2830d5ac3cb.js', bytes: 0/5116

 

 

5.使用pm2啓動verdicco(pm2託管的進程能夠保證進程永遠是活着的,嘗試經過kill -9去殺verdaccio的進程發現殺了以後又自動啓起來)

5.1.全局安裝pm2

[zhou@verdaccio node-v10.16.0]$ npm install -g pm2 --unsafe-perm
/data/www/node-v10.16.0/bin/pm2 -> /data/app/node-v10.16.0/lib/node_modules/pm2/bin/pm2
/data/www/node-v10.16.0/bin/pm2-dev -> /data/app/node-v10.16.0/lib/node_modules/pm2/bin/pm2-dev
/data/www/node-v10.16.0/bin/pm2-docker -> /data/app/node-v10.16.0/lib/node_modules/pm2/bin/pm2-docker
/data/www/node-v10.16.0/bin/pm2-runtime -> /data/app/node-v10.16.0/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ pm2@3.5.1
added 317 packages from 256 contributors in 101.39s

 

5.2.使用pm2啓動verdicco

 [zhou@verdaccio node-v10.16.0]$ pm2 start `which verdaccio`

-------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
_\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
_\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
_\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
_\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
_\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
_\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
_\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
_\///______________\///______________\///__\///////////////__


Runtime Edition

PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.

Start and Daemonize any application:
$ pm2 start app.js

Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4

Monitor in production:
$ pm2 monitor

Make pm2 auto-boot at server restart:
$ pm2 startup

To go further checkout:
http://pm2.io/


-------------

[PM2] Spawning PM2 daemon with pm2_home=/home/zhou/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /data/www/node-v10.16.0/bin/verdaccio in fork_mode (1 instance)
[PM2] Done.

┌───────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬─────────┐
App name     │ id   version      │ mode  pid       status    restart     uptime    │ cpu    │ mem            │ user    │ watching  
├───────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼─────────┤
verdaccio      │ 0     │ N/A          │ fork    │ 29344    │ online     │ 0              │ 0s          │ 0%    │ 13.4 MB        │ zhou │ disabled    │
└───────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴─────────┘

 

Use `pm2 show <id|name>` to get more details about an app

 

5.3查看pm2 守護下的進程verdaccio的實時日誌
[root@verdaccio node-v10.16.0]# pm2 show verdaccio
Describing process with id 0 - name verdaccio

┌───────────────────┬─────────────────────────────────────┐
│ status                        │ online                         │
│ name           │ verdaccio                                │
│ version          │ N/A                                            │
│ restarts                   │ 0                             │
│ uptim                         │ 38m                         │
│ script path              │ /usr/bin/verdaccio                   │
│ script args           │ N/A                           │
│ error log path          │ /root/.pm2/logs/verdaccio-error.log           │
│ out log path         │ /root/.pm2/logs/verdaccio-out.log             │
│ pid path              │ /root/.pm2/pids/verdaccio-0.pid              │
│ interpreter            │ node                                  │
│ interpreter args       │ N/A                              │
│ script id            │ 0                                     │
│ exec cwd            │ /data/www/node-v10.16.0                   │
│ exec mode           │ fork_mode                           │
│ node.js version       │ 10.16.0                        │
│ node env            │ N/A                            │
│ watch & reload         │ ✘                                │
│ unstable restarts     │ 0                          │
│ created at         │ 2019-07-03T05:57:33.089Z               │
└───────────────────┴─────────────────────────────────────┘

Actions available
┌────────────────────────┐
│ km:heapdump          │
│ km:cpu:profiling:start      │
│ km:cpu:profiling:stop          │
│ km:heap:sampling:start      │
│ km:heap:sampling:stop     │
└────────────────────────┘
Trigger via: pm2 trigger verdaccio <action_name>

Code metrics value
┌────────────────────────┬──────────────┐
│ Heap Size                    │ 40.84 MiB          │
│ Heap Usage              │ 86.73 %         │
│ Used Heap Size           │ 35.42 MiB        │
│ Active requests           │ 0            │
│ Active handles              │ 4               │
│ Event Loop Latency           │ 2.90 ms              │
│ Event Loop Latency p95        │ 7.00 ms        │
│ HTTP Mean Latency         │ 3.5 ms       │
│ HTTP P95 Latency        │ 32 ms        │
│ HTTP               │ 0.01 req/min    │
└────────────────────────┴──────────────┘
Divergent env variables from local env
┌───────────────────────────┬─────┐
│ SELINUX_ROLE_REQUESTED        │      │
│ SELINUX_USE_CURRENT_RANGE    │       │
│ SELINUX_LEVEL_REQUESTED       │      │
│ OLDPWD                     │ N/A   │
└───────────────────────────┴─────┘

Add your own code metrics: http://bit.ly/code-metrics
Use `pm2 logs verdaccio [--lines 1000]` to display logs
Use `pm2 env 0` to display environement variables
Use `pm2 monit` to monitor CPU and Memory usage verdaccio

[root@verdaccio node-v10.16.0]# tail -f /root/.pm2/logs/verdaccio-out.log
http://www.javashuo.com/tag/http <-- 401, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', error: jwt not active
http://www.javashuo.com/tag/http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fonts/roboto-latin-700.woff2', bytes: 0/15436
http://www.javashuo.com/tag/http <-- 404, user: 1k(10.10.1.103), req: 'POST /-/v1/login', bytes: 24/150
http://www.javashuo.com/tag/http <-- 400, user: 1k(10.10.1.103), req: 'PUT /-/user/org.couchdb.user:2k', error: The provided password is too short. Please pick a password longer than 3 characters.
http://www.javashuo.com/tag/http <-- 400, user: 1k(10.10.1.103), req: 'PUT /-/user/org.couchdb.user:2k', error: The provided password is too short. Please pick a password longer than 3 characters.
http://www.javashuo.com/tag/http <-- 404, user: 1k(10.10.1.103), req: 'POST /-/v1/login', bytes: 24/150
http://www.javashuo.com/tag/http <-- 201, user: 1k(10.10.1.103), req: 'PUT /-/user/org.couchdb.user:1k', bytes: 124/611
http://www.javashuo.com/tag/http <-- 304, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', bytes: 0/0
http://www.javashuo.com/tag/http <-- 200, user: 1k(10.10.1.1), req: 'POST /-/verdaccio/login', bytes: 41/333
http://www.javashuo.com/tag/http <-- 401, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', error: jwt not active

 

6.添加用戶
[root@verdaccio node-v10.16.0]# npm adduser --registry http://10.10.1.103:4873
Username: 1k
Password:    (密碼:123456)
Email: (this IS public) 1k@qq.group
Logged in as 1k on http://10.10.1.103:4873/.

 

 

 

 

7.配置nginx反向代理

因爲 verdaccio 默認是啓動在 4873 端口,方便起見,配置 nginx 反向代理到該端口
若是須要查看 verdaccio 的端口號,能夠用 pm2 ls 查看到 verdaccio 的 pid,而後使用:

$ netstat -nap | grep <pid>

查看佔用的端口號

下面貼出 nginx 配置,centos 的nginx 配置文件在 /etc/nginx/conf.d/
新建一個配置文件,而後使用以下內容便可

[root@verdaccio node-v10.16.0]# vim /etc/nginx/conf.d/default.conf 

======================================================

server {
listen 80;
server_name npm.www.group;

location / {
proxy_set_header Host $host;
proxy_pass http://10.10.1.103:4873;
}

}

======================================================

重載 nginx

[root@verdaccio node-v10.16.0]# systemctl reload nginx

相關文章
相關標籤/搜索