You can access the tutorial artifact, including deployment script (Terraform), related source code, sample data, and instruction guidance from this GitHub project.
Please refer to this link for more tutorials around Alibaba Cloud Database
Database Deployment Tutorials Series: https://community.alibabacloud.com/series/118
Run the Terraform script to initialize the resources. (IIn this tutorial, we use MongoDB as a backend database, so ECS and MongoDB are included in the Terraform script.*) Please specify the necessary information and region to deploy.
After the Terraform script execution finishes, the ECS instance information is listed below:
eip_ecs: The public EIP of the ECS for web app host
Go to the Alibaba Cloud ECS console to see the ECS instance you just created:
Go to the Alibaba Cloud MongoDB console to view the MongoDB instance:
Copy the public IP address of the "mongodb-tech" instance you just created and log in remotely via SSH.
The default account name and password of the ECS instance:
Account name: root
Enter the following command to download the Node.js installation package:
Enter the following command to decompress the installation package:
tar xf node-v16.9.1-linux-x64.tar.xz
Run the following command to move the decompressed directory to the
mv node-v16.9.1-linux-x64 /usr/local/node
vim /etc/profile command to open the environment variable configuration file. Append the following content to the end of the file:
export NODE_HOME=/usr/local/node export PATH=$PATH:$NODE_HOME/bin
Run the following command to make the modification take effect:
Run the following commands. You can see the corresponding service version, which indicates the installation is completed:
node -v npm -v
Enter the following command to install the Git tool:
apt update && apt -y install git
Enter the following command to create a projects directory and enter:
mkdir projects && cd projects
Enter the following command to download the sample project:
git clone https://github.com/hoangvvo/nextjs-mongodb-app ls
Enter the following command to enter the sample project directory:
Enter the following command to install the Next.js framework dependency package:
npm install next react react-dom
Enter the following command to copy an ".env" configuration file first:
cp .env.example .env
Enter the command:
vim .env, open the ".env" configuration file, and modify the connection address of MongoDB referring to the figure below:
The connection method to obtain MongoDB is shown in the figure below. Please pay attention and replace "**" with the password "Aliyuntest123":
Enter the following command to start the project:
npm run dev
Visit the public IP address of the current ECS in the browser, and the project is installed successfully.
Users can register their accounts to post messages.
Usually, we need to run the Node.js app as a daemon process. Now, install pm2 to start or manage the lifecycle of the Node.js web app.
Ctrl + C to stop the web app process started by executing
npm run dev beforehand. Then, execute the following commands to install pm2 and start the web app via pm2.
npm i -g pm2 npm run build
pm2 start npm -- run start
Then, visit the public IP address of the current ECS with port
3000 again in the browser, and the project is started by pm2 successfully.
Execute the following commands to install the open-source MongoDB Web Admin tool Mongoku on ECS to manage data on MongoDB.
cd ~ npm install -g mongoku mongoku start --pm2
http://<ECS_EIP>:3100/ again in the web browser to visit the Mongoku Web Admin. Mongoku uses the
3100 port for web apps by default. I've already set this in the security group rule within the Terraform script.
Now, we can add the MongoDB connection URI here as the server to navigate and manage the data for this social web app via Mongoku. Please enjoy.
Alibaba Clouder - April 16, 2018
Alibaba Cloud Community - August 5, 2022
Alibaba Clouder - November 23, 2020
ApsaraDB - October 14, 2021
ApsaraDB - November 1, 2021
Alibaba Clouder - December 17, 2018
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
Apsara Stack Agility Elastic Compute Service (Alibaba Cloud ZStack) is a light-weight hybrid cloud solution.Learn More
A secure, reliable, and elastically scalable cloud database service for automatic monitoring, backup, and recovery by time pointLearn More
Block-level data storage attached to ECS instances to achieve high performance, low latency, and high reliabilityLearn More
More Posts by ApsaraDB