1.安装nodejs
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.0
1.2 测试node是否安装成功
[root@verdaccio www]# node -v
v10.16.0
[root@verdaccio www]# npm -v
6.9.0
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/profile
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.497s
3.配置
1.安装完需要启动(执行 /data/app/node-v10.16.0/bin/verdaccio )一下,才能生成配置文件。
[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 address - http://localhost:4873/ - verdaccio/4.0.4
2.修改配置文件 config.yaml,在其最后添加监听端口(使其可在外网访问)
[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 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 address - http://localhost:4873/ - verdaccio/4.0.4
http <-- 200, user: null(10.10.1.1), req: 'GET /', bytes: 0/575
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/manifest.b6891b53f2830d5ac3cb.js', bytes: 0/1547
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/0.style.cdd1fdf79cd6bec30c42.css', bytes: 0/863
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/main.b6891b53f2830d5ac3cb.js', bytes: 0/18698
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/favicon.ico', bytes: 0/2054
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/vendors.b6891b53f2830d5ac3cb.js', bytes: 0/178097
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/favicon.ico', bytes: 0/2054
http <-- 200, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', bytes: 0/3
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/93df1ce974e744e7d98f5d842da74ba0.svg', bytes: 0/753
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/3025c327f6f127d5190f14b16e75b41b.svg', bytes: 0/851
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/b1e0d4d4ee23474aee6616f444fc7aa9.svg', bytes: 0/1045
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/d96f386211a24e791aaa1f929fd56f91.svg', bytes: 0/1291
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/de092a6cac20ccf2cd373644425a13ce.svg', bytes: 0/577
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fa99a58eb30e323243a5b2dbae7eacdd.svg', bytes: 0/898
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/ac0877b3e5dab78d7b5319b32cb03b11.svg', bytes: 0/833
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/24fd3a77ee5710ead382075bbfa36d17.svg', bytes: 0/380
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fonts/roboto-latin-400.woff2', bytes: 0/15344
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fonts/roboto-latin-500.woff2', bytes: 0/15552
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/1.b6891b53f2830d5ac3cb.js', bytes: 0/6598
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/6f6560222974090c1ef11e84623ff803.svg', bytes: 0/692
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 │
│ uptime │ 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 <-- 401, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', error: jwt not active
http <-- 200, user: null(10.10.1.1), req: 'GET /-/static/fonts/roboto-latin-700.woff2', bytes: 0/15436
http <-- 404, user: 1k(10.10.1.103), req: 'POST /-/v1/login', bytes: 24/150
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 <-- 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 <-- 404, user: 1k(10.10.1.103), req: 'POST /-/v1/login', bytes: 24/150
http <-- 201, user: 1k(10.10.1.103), req: 'PUT /-/user/org.couchdb.user:1k', bytes: 124/611
http <-- 304, user: null(10.10.1.1), req: 'GET /-/verdaccio/packages', bytes: 0/0
http <-- 200, user: 1k(10.10.1.1), req: 'POST /-/verdaccio/login', bytes: 41/333
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。