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
ssh [email protected]
- Enter your password:
xxxxxx
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]"
- generate
SSH keys
to/root/.ssh/
Under the path:ssh-keygen -t rsa -C "[email protected]"
- will
SSH keys
Add 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 accesses
xx.xxx.xxx.xx
If the nginx configuration is not modified, the following information is displayed:
- Modify the
nginx
, 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) - will
server
Under theroot
Change the directory to another directory/usr/www/home/dist
(The path can be modified according to personal habits) - Add multiple
server
Access multiple projects with different ports - After the modification is complete, upload your own code to the relevant directory, the default entry is
index.html
To update the configuration and run the commandnginx -s reload
Restart Nginx(you can also shut it down before running the start command); Nginx common command:- Check whether the configuration file has syntax errors
nginx -t
- To quickly stop or close Nginx:
nginx -s stop
- Stop or close Nginx normally:
nginx -s quit
- Restart the Nginx:
nginx -s reload
- Check whether the configuration file has syntax errors
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 the
app.js
Applications: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:
- Resume:
pm2 restart app.js
- Stop:
pm2 stop app_name|app_id
- Delete:
pm2 delete app_name|app_id
- Stop all applications:
pm2 stop all
- Check the process status:
pm2 list
- More interfaces:
https://pm2.keymetrics.io/docs/usage/pm2-api/
- Resume:
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