CentOS7 Nodejs布署环境

一、服务器设置:https://www.youtube.com/watch?v=1OU5ngq-WyM&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=1

1.更新系统

yam -y update

2.安装开发者工具

yum -y groupinstall "Development Tools"

使用命令yum groupinfo Development Tools查看工具包包含的具体工具

yum -y install vim net-tools

二、安装Nodejs / PM2 / yarn:https://www.youtube.com/watch?v=XCgCjasqEFo&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=2

3.下载Nodejs,进入至Nodejs官网下载页面,https://nodejs.org/en/download/

选择Centos 版本,可以使用Enterprise Linux and Fedora这个选项

地址:https://rpm.nodesource.com/setup_10.x,其实是一些脚本,会帮忙执行下载动作

4.安装Nodejs,运行命令

yum -y install nodejs

#安装完成后使用
node -v查看是否已经成功完成安装
npm -v

5.安装PM2及yarn

npm install -g pm2 http-server
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yam install yarn

#安装完成后使用
yarn --version 查看是否已经成功安装yarn

三、创建用户 :https://www.youtube.com/watch?v=LbJK48gvXcA&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=3

6.创建用户

adduser weschen
usermod -aG whell weschen
sudo su - weschen

whoami

cd ~
mkdir .ssh

chmod 700 .ssh
touch .ssh/authorized_keys
chomd 600 .ssh/authorized_keys
cat ~/.ssh/id_rsa.pub
#把生成的ssh key复制出来
并将内容复制至
vim .ssh/authorized_keys
再查看是否已经复制过来了
cat .ssh/authorized_keys
logout 退出weschen
当下次登陆时,可以直接登陆

四、使用PM2发布Nodejs程序:https://www.youtube.com/watch?v=RF6Dzwwpduo&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=4

7.将Nodejs程序压缩并上传至服务器,这一步,如果不是苹果电脑,也可以借助github达到目的,将代码签入至github中,在服务器中下载源代码

当解压了文件夹后,进入至某个解压后的文件夹
yarn #安装Nodejs依赖包

npm start #运行应用程序

8.以上当关闭了进程,Nodejs程序将停止运行,需要使用PM2创建守护进程

进入至解压缩后的文件夹

pm2 start --name demoproject main.js

pm2 ls #查看已经运行的项目列表


切换至root用户

pm2 startup systemd -u weschen --hp /home/demoProjectFolder  #加入至开机启动


切换至weschen

pm2 save #创建一个特殊文件至服务器,可以允许开机启动

五、自动布署:https://www.youtube.com/watch?v=AQClj-lLqRs&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=5

9.即将上面的步骤做成一个脚本(.sh)的方式,运行在苹果电脑的客户端


六、配置服务器DNS:https://www.youtube.com/watch?v=d8TRPMI8lVk&index=6&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh


七、使用Nginx配置反向代理:https://www.youtube.com/watch?v=ng5DsxYp-Bk&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=7 


八、网络解释:https://www.youtube.com/watch?v=PYTG7bvpvRI&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh&index=8 


九: 了解及配置SELinux:https://www.youtube.com/watch?v=HhydNtaLEK0&index=9&list=PLQlWzK5tU-gDyxC1JTpyC2avvJlt3hrIh

猜你喜欢

转载自www.cnblogs.com/weschen/p/9273679.html
今日推荐