Building a NPM
As the online documents adopted Nodejs and CNPM version too old, including GitHub official website, there are more or less problems, eventually after tossing and finishing this document, the document database selection MySQL, the erection of Nginx proxy is not necessary.
1. Installing Nodejs
Mkdir-p/app/srccd/app/srcwget tar jxf node-v6.4.0-linux-x64.tar.xzmv node-v6.4.0-linux-x64/app/nodeuseradd Nodeecho ' Export path=/app/node/bin: $PATH ' >>/home/node/.bash_profile
2. Installing the CNPM server
Su-nodegit Clone CD CNPMJS.ORG/NPM Install
3.MySQL Create a database and authorize
CREATE DATABASE Cnpmjs; GRANT all on cnpmjs.* in [email protected] ' 127.0.0.1 ' identified by ' Password '; FLUSH privileges;
4. Database Import data
Mysql-uroot Cnpmjs < Docs/db.sql
5. Modify the configuration fileconfig/index.js
Enablecluster:true,
Port settings, registryPort
for the registration service port, webPort
for the Web Access port, by default
REGISTRYPORT:7001,WEBPORT:7002,
admin: ' [email protected] ',
DB: ' Cnpmjs ', username: ' Cnpmjs ', Password: ' Password ', dialect: ' MySQL ', Host: ' 127.0.0.1 ', port:3306,
Binding listener address, optional. If you do not need access to this machine, add the symbolic //
comment line. You can also set nginx in this machine to do reverse proxy, there is no need to modify this line.
Bindinghost: ' 127.0.0.1 ',
Registryhost: ' npm.songsong.org ',
Enableprivate:true,
Scopes: [' @songsong. org '],
sourcenpmregistry: ' https://registry.npm.taobao.org ',
Synchronous mode, none
Different steps only proxy source public module, exist
synchronizes only existing modules, all
synchronizes all modules.
Syncmodel: ' Exist ',
6. Start the CNPM service
Bin/nodejsctl start
7. Add Nginx reverse proxy, use two domain name to differentiate CNPM Web service and registration service, overload configuration
upstream npm.songsong.org{ server 127.0.0.1:7002 weight=10;} server{ listen 80; server_name npm.songsong.org; index index.html; location / { proxy_redirect off; proxy_ set_header host $host; proxy_set_header x-real-ip $remote _addr; proxy_set_header remote-host $remote _addr; proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; proxy_connect_timeout 60; proxy_send_timeout 60; proxy_read_timeout 60; proxy_pass }}
upstream reg.songsong.org{ server 127.0.0.1:7001 weight=10;} server{ listen 80; server_name reg.songsong.org; index index.html; location / { proxy_redirect off; proxy_ set_header host $host; proxy_set_header x-real-ip $remote _addr; proxy_set_header remote-host $remote _addr; proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; proxy_connect_timeout 60; proxy_send_timeout 60; proxy_read_timeout 60; proxy_pass }}
8. Installing the CNPM Client
NPM install-g CNPM
9. Set the CNPM client access, the same effect in both ways
CNPM Set Registry http://reg.songsong.org
registry=http://reg.songsong.org
This article is from the "Pine" blog, be sure to keep this source http://dongsong.blog.51cto.com/916653/1850814
Building a NPM