instructions

This article uses aliyun and Centos7 as the premise to deploy web-based applications. If you want to modify or add files in this document, you can use Linux commands or FTP to upload files to the server.

Setting a Security Group

  • Security groups need to be added in the background of Aliyun because it involves publishing multiple applications using different ports for access
  • For convenience, open all ports and create security groups (you can also create multiple security groups or open individual ports) :

  • After the instance is created, add it to a security group

CMD enter server

Install git

  • Install git:sudo yum install git -y
  • Confirm installation success:git --version
  • Configure the user name:git config --global user.name "xxxx"
  • Configure the email address:git config --global user.email "[email protected]"
  • generateSSH keysto/root/.ssh/Under the path:ssh-keygen -t rsa -C "[email protected]"
  • willSSH keysAdd to Github:vi /root/.ssh/id_rsa.pub

Install Nginx

  • Installation:sudo yum install nginx -y
  • Activation:sudo systemctl start nginx
  • Access public IP address: The public IP address of the cloud server that the browser accessesxx.xxx.xxx.xxIf the nginx configuration is not modified, the following information is displayed:

  • Modify thenginx, configure different ports to access multiple static projects:vi /etc/nginx/nginx.conf/etc/nginx/conf/nginx.conf(Slightly different file paths for different versions)
  • willserverUnder therootChange the directory to another directory/usr/www/home/dist(The path can be modified according to personal habits)
  • Add multipleserverAccess multiple projects with different ports
  • After the modification is complete, upload your own code to the relevant directory, the default entry isindex.htmlTo update the configuration and run the commandnginx -s reloadRestart Nginx(you can also shut it down before running the start command); Nginx common command:
    1. Check whether the configuration file has syntax errorsnginx -t
    2. To quickly stop or close Nginx:nginx -s stop
    3. Stop or close Nginx normally:nginx -s quit
    4. Restart the Nginx:nginx -s reload

Install Nodejs

  • Download the NodeJS installation package:Wget HTTP: / / https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz(Download address and version can be selected from the official website and copied and modified)
  • Extract:The tar xf node - v10.13.0 - Linux - x64. Tar. Gz
  • Change the nodeJS package location:Node - mv v10.13.0 - Linux - x64 / usr/local/SRC /
  • Create soft link globally using node command:
  • Ln -s/usr/local/SRC/node - v10.13.0 - Linux - x64 / bin/node/usr/bin/node
  • Ln -s/usr/local/SRC/node - v10.13.0 - Linux - x64 / bin/NPM/usr/bin/NPM
  • Testing:node -v npm -v

The /usr/local/src/ directory can be changed. If the directory is changed, the directory must be unified

The node package in /usr/local/src cannot be deleted; otherwise, the node command will be invalid

Install PM2 (Node process management, can start multiple Node or SSR applications and manage)

  • Download pm2:npm install pm2 -g
  • Create soft link globally using pm2 command:Ln -s/usr/local/SRC/node - v10.13.0 - Linux - x64 / lib/node_modules/pm2 / bin/pm2 / usr/local/bin/pm2
  • Start theapp.jsApplications:pm2 start app.js
  • Testing:pm2 list
  • The following figure shows the successful startup. Nginx configuration is not done here. You can directly access the project using public IP + app.js program port number, for example:xx.xxx.xxx.xx:3000

  • Pm2 common commands:
    1. Resume:pm2 restart app.js
    2. Stop:pm2 stop app_name|app_id
    3. Delete:pm2 delete app_name|app_id
    4. Stop all applications:pm2 stop all
    5. Check the process status:pm2 list
    6. More interfaces:https://pm2.keymetrics.io/docs/usage/pm2-api/

App.js is the entry point for NodeJS, Koa, Express or SSR applications

Note: PM2 soft link address is not the same as node path. After downloading, the command line will show you the path

Install the mongo

  • Download:Wget HTTP: / / https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.13.tgz
  • Extract:Tar ZXVF mongo - Linux - x86_64-4.0.13. TGZ
  • Move file location:Mv mongo - Linux - x86_64-4.0.13 / usr/local/mongo /
  • Enter folder:cd /usr/local/mongodb
  • Create database directory:mkdir data
  • Create log file:touch logs
  • in/usr/local/mongodb/bin/Perform:./mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --port=27017 --fork
  • in/usr/local/mongodb/bin/Execute command:./mongo
  • Testing:show dbs