CentOS 7.4安裝nodejs & nginx
阿新 • • 發佈:2018-11-11
一、安裝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]