Ali cloud || Tencent cloud server instances need to be added to the "security group" open http && https communication
Set to open nodejs port: / sbin / iptables the INPUT -p tcp --dport the -I port number -j ACCEPT
1. Installation node environment:
Download archive:
wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz
Then cd to the installation directory:
cd / home
decompression:
the tar -xvf Node-v10.13.0-Linux-x64.tar.xz
provided soft connection global variables:
ln -s /home/node-v10.13.0-linux-x64.tar.xz/bin/npm /usr/local/bin/npm
ln -s /home/node-v10.13.0-linux-x64.tar.xz/bin/node /usr/local/bin/node
Then test whether the configuration is successful, the version number is displayed successfully
node -v
v10.13.0
altitude -v
6.4.1
If the error: -bash: node: command not found || -bash: npm: command not found
Solution:
Check environment variables have not / usr / local / bin / directory
echo $PATH
if there is not:
method one
The / usr / local / bin in the format add environmental variables
Method Two
Modify flexible connection ( echo $ the PATH queries to the directory, you need to remove soft link / usr / local / bin / npm || / usr / local / bin / node directory just set)
LN -s / Home / the Node-V10. x64.tar.xz-Linux-13.0 / bin / NPM / usr / bin / NPM
LN /home/node-v10.13.0-linux-x64.tar.xz/bin/node -s / usr / bin / Node
2. Install PM2
npm install -g PM2
enter nodejs project directory, I have to upload the program to the / usr / local / deployment,
So:
Enter cd / usr / local / deployment / nodejs project directory enter into the project directory to start nodejs project,
Our entry file nodejs project is app.js, so: Enter input pm2 start app.js
Enter pm2 list enter, display task process is successful
If the error is displayed: -bash: pm2: command not found
you need to configure the global pm2: LN /usr/local/node/node-v10.13.0/bin/pm2 -s / usr / bin /
If you can not access the service's words:
turn off the firewall
1: View the status of fire:
systemctl Status firewalld
or
service iptables status
2: Temporarily turn off the firewall:
systemctl stop firewalld
或
service iptables stop
3: Permanently turn off the firewall:
systemctl disable firewalld
或
chkconfig iptables off
4: Restart Firewall:
systemctl enable firewalld
或
service iptables restart
Or firewall allows the port provided:
iptables -I -p TCP. 4 the INPUT NEW -m -m --state State TCP port number --dport -j ACCEPT
service iptables save