一、安装nodejs
???1、查看操作系统信息
??????? uname -a
???2、安装wget
??????? yum install wget -y
???3、安装nodejs
??????? 1、下载 wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz
??????? 2、解压 xz -d node-v10.13.0-linux-x64.tar.xz
??????? 3、解压 tar xvf node-v10.13.0-linux-x64.tar
??????? 4、安装nodejs
??????????? 1、cd node-v10.13.0-linux-x64
??????????? 2、cd bin
??????????? 3、mv ./node /bin/
??????????? 4、mv ./npm /bin/
??????????? 5、mv ./npx /bin/
??????????? 6、cd .. cd lib
??????????? 7、mv ./node_modules /lib/
??????? 5、安装nrm
??????????? npm install nrm -g
??????? 6、安装 ngnix
??????????? rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
??????????? yum install -y nginx
??????????? 运行nginx
??????????? service nginx start
??????????? 重启nginx
??????????? nginx -s reload
??????????? 查看nginxV默认安装目录 whereis nginx
??????? 7、安装pm2
??????????? npm install pm2 -g
二、node监听的8080端口,网站无法访问
??? 1、关闭防火墙 systemctl stop firewalld.service
??????? 启动: systemctl start firewalld
??????? 关闭: systemctl stop firewalld
??????? 查看状态: systemctl status firewalld
??????? 开机禁用 ?: systemctl disable firewalld
??????? 开机启用 ?: systemctl enable firewalld
??? 2、开放8080端口
??????? 添加
??????? firewall-cmd --zone=public --add-port=8080/tcp --permanent ???(--permanent永久生效,没有此参数重启后失效)
??????? 重新载入
??????? firewall-cmd --reload
??????? 查看
??????? firewall-cmd --zone=public --query-port=8080/tcp
??????? 删除
??????? firewall-cmd --zone=public --remove-port=8080/tcp --permanent
三、全局化运行node
??? 1、node server.js & ?(该方法如果某一进程出错,则服务停止,不推荐)
??? 2、pm2
??????? 启动服务 pm2 start server.js
??????? 停止服务 pm2 stop server.js
??????? 查看服务 pm2 ls
四、查看进程,Kill进程
??? 1、查看 ps -ef
??? 2、Kill kill [pid]
CentOS 7.4安装nodejs & nginx
原文地址:https://www.cnblogs.com/aipeli/p/9941202.html