Environment configuration

Linux Centos7, NodeJS, Verdaccio, PM2

nodejsDownload, install, and configure environment variables

Download:

Wget HTTP: / / https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xzCopy the code

Unzip and rename:

Xz -d node-v12.18.3- Linux -x64.tar.xz tar -xf node-v12.18.3- Linux -x64.tar mv node-v12.18.3- Linux -x64 node-v12.18.3Copy the code

Set node global environment variables:

Vi. Bash_profile // Modify the user environment variable fileCopy the code

Type I to enter insert mode:

Export NODE_HOME = / usr/local/node - v12.18.3 / bin export PATH = $PATH: $NODE_HOMECopy the code

Esc exits the insert mode, shift+ enter wq to save the configuration and exit

Make the modified environment variable file take effect:

source .bash_profile
Copy the code

So far, so good, but check this out:

Node -v bash: node: command not found...Copy the code

Ha ha, a little awkward. This can’t blame me, I am strict and standard in accordance with the steps provided by the big guys on Baidu. Find out why. There should be no problem with the installation, since the Node package we downloaded has already been generated. The problem is the configuration of environment variables. Continue baidu, there is a configuration of environment variables, the global environment variable configuration of the system:

Vi /etc/profiler// The following procedure is the same as the preceding procedure......Copy the code

Time for a miracle?

Node -v bash: node: command not found...Copy the code

????? I have to poke fun at a bunch of Internet bigwigs. Did you not verify it, or did you hide some stuff and not complete it? Continue to look up information, filtering out and the above two methods of the same article, there is still a method of setting up soft connection. What is soft connection: a way to make it easy to use. Have a try.

Ln -s /root/node-v12.18.3-linux-x64/bin/node /usr/local/bin/node // ln -s Node address Decompressed target address of the soft connection ln -s /root/node-v12.18.3-linux-x64/bin/npm /usr/local/bin/npm node-v v12.18.3 NPM -v 6.14.6Copy the code

OK, node configuration is successful, equivalent to the long march half way, the rest is simple.

Install verdaccio

Follow the instructions in the official documentation to install Verdaccio globally.

npm install -g verdaccio ... In the installation... . In the installation... . In the installation... ERROR: GryWARN permission ERROR is reportedCopy the code

What? Does a permission error occur when I log in to the root account? Don’t comply with the martial virtue Here’s how:

npm install -g verdaccio --unsafe-perm ... In the installation... . In the installation... . In the installation... + [email protected]Copy the code

Once successful, let’s modify the config.yaml configuration file

vi /root/.config/verdaccio/config.yaml
Copy the code

Add the last listening port at the end of the configuration file:

Listen: 172.xx.xx.xx. Xx :4873 // Our server address, because we want to access this addressCopy the code

To verify this, follow the instructions in the official documentation:

Verdaccio bash: Verdaccio: command not found...Copy the code

Yi? Look familiar? Same error as validating NodeJS. That’s easy. You can’t step on the same pit twice.

Ln -s/root/node - v12.18.3 - Linux - x64 / bin/verdaccio/usr/local/bin/verdaccioCopy the code

To perform:

verdaccio *** WARNING: Verdaccio doesn't need superuser privileges. Don't run it under root! *** warn --- config file - /root/.config/verdaccio/config.yaml warn --- Verdaccio started warn --- Plugin successfully loaded: verdaccio-htpasswd warn --- Plugin successfully loaded: Verdaccio - audit warn the HTTP address - http://172.xx.xx.xx:4873/ - verdaccio / 4.11.0 fatal - always create a server: listen EADDRINUSE: address already in use 172.xx.xx.xx:4873/Copy the code

Is the port occupied? Netstat -tunlp:

Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 172.xx.xx.xx:4873 0.0.0.0:* LISTEN 7557/hr- UI component library...Copy the code

Kill -9 7557 before executing verdaccio:

warn --- config file - /root/.config/verdaccio/config.yaml warn --- Verdaccio started warn --- Plugin successfully loaded: verdaccio-htpasswd warn --- Plugin successfully loaded: Verdaccio - audit warn the HTTP address - http://172.xx.xx.xx:4873/ - verdaccio / 4.11.0Copy the code

Succeeded. We visited the browser, the page error: can not access the site, refused our connection request. Can’t access the Internet? To find out the reason, it is true that the port 4873 is not exposed to the outside, so it cannot be accessed. Then expose yourself and execute the order:

Firewall-cmd --zone=public --add-port=4873/ TCP --permanent success firewall-cmd --reload# Opening the port requires a firewall restart to take effectCopy the code

Visit http://172.xx.xx.xx:4873/ again, successfully entered the said the front page of the official document.

Use PM2 to always guardverdaccioprocess

Although verdaccio can be started normally, it cannot keep the process open all the time, so we can use PM2 to manage the Verdaccio process

1. Installpm2

npm install -g pm2 --unsafe-perm
Copy the code

2. Soft connectionpm2

Ln -s/root/node - v12.18.3 - Linux - x64 / bin/pm2 / usr/local/bin/pm2Copy the code

3.pm2Start theverdaccio

pm2 start verdaccio
Copy the code

Ok, so this process is always open.

verdaccioHow to use

All the above steps are related to the configuration of the Verdaccio service, so how to use it? Simple, the client executes the following command:

/ / need to manually add users when using NPM set registry http://172.xx.xx.xx:4873/ / / switch to our private library NPM adduser / / according to the prompt for user name and password // Upload NPM publish to the local NPM project libraryCopy the code

Refresh the http://172.xx.xx.xx:4873/ see, wuhu, successfully uploaded.

How do I use packages from private libraries?

Specify the source address of the installation:

npm install xxxx  --registry=http://172.xx.xx.xx:4873/
Copy the code