By Sumathi Kuppusamy,Alibaba Cloud Tech Share Author
MEAN stack is one of the modern web application javascript framework that’s rapidly improving and easy to collaborate and learn. The MEAN Stack contains, from backend to frontend, a schemaless NoSQL database (MongoDB), a server-side JavaScript platform (Node.js), a web application framework running on Node.js to make it easier to write apps (Express.js), and a frontend client-side framework that runs in the browser (AngularJS).
In this article, we will walk through the steps to deploy MEAN stack on CentOS 7.2 deployed in Alibaba Cloud ECS.
Let us look at the steps in detail to deploy MEAN stack on an Alibaba Cloud ECS instance with CentOS 7.2.
NodeJS is one of the faster way to build scalable network application. In order to install nodeJS, run the following commands on CentOS 7:
curl -sL https://rpm.nodesource.com/setup_4.x
yum install -y nodejs
Sample output:
MongoDB is the leading NoSQL database service. We will now install it on our ECS instance.
cat > /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
Press Ctrl+D to save and exit.
yum install -y mongodb-org
● Start the mongod service in noauth mode following the below command:
mongod –fork –dbpath /var/lib/mongo –logpath /var/log/meandb.log
Note: The default dbpath is /var/lib/mongo
● Create the admin user by going to mongo shell by typing “mongo” in terminal and feed in the below commands in mongo shell:
mongo
use admin
db.createUser({user:‘siteUserAdmin’,pwd:‘’,roles:[{role:‘userAdminAnyDatabase’,db:‘admin’}]})
Enter the command “exit” when complete to exit from the mongo shell.
● Now stop the mongod service.
mongod –shutdown –dbpath /var/lib/mongo
● Now start the mongod service in -auth mode
mongod –fork –auth –dbpath /var/lib/mongo –logpath /var/log/meandb.log
● Create a user for your mongo collection (new-mean) by going to mongo shell in the terminal and feed in the below commands in mongo shell. You need to login to your MongoDB account by using the “-u” and “-p” commands:
mongo -u siteUserAdmin -p pa55word --authenticationDatabase admin
use new-mean;
db.createUser({user:'meanuser',pwd:'',roles:[{role:'readWrite',db:'new-mean'}]})
Enter the command “exit” when complete to exit from the mongo shell.
Note: In this example, we have used the following username and passwords. For your environment, use appropriate password of your choice.
Database | Username | Password |
admin | siteUserAdmin | ******** |
new-mean | meanuser | ******** |
yum install -y git
sudo npm install -g bower
sudo npm install -g gulp
yum update -y opensslOutput:
git clone https://github.com/linnovate/mean.git
cd mean(Optional) You can inspect the directory structure of mean by using the command “ls”:
npm installNote: This may take few seconds to complete. c. Configure MONGO_HOST settings in server-start.js to connect to mongo server using the created user meanuser. You can use one of the text editor ‘vi’ or ‘nano’:
nano server-start.jsChange the line containing “MONGO_HOST”: process.env.MONGO_HOST='mongodb://localhost/new-mean' To
process.env.MONGO_HOST='mongodb://meanuser@********@localhost/new-mean'
c. Start the mean service with production mode
export NODE_ENV=production npm start
WordPress with LEMP on Alibaba Cloud – Part 1 Provision and Secure an Ubuntu 16.04 Server
2,598 posts | 769 followers
FollowAlibaba Clouder - January 25, 2019
Alibaba Clouder - May 29, 2019
Alibaba Clouder - May 7, 2019
Alibaba Clouder - April 12, 2019
Alibaba Clouder - December 7, 2017
Alibaba Clouder - July 12, 2018
2,598 posts | 769 followers
FollowAlibaba Cloud Elasticsearch helps users easy to build AI-powered search applications seamlessly integrated with large language models, and featuring for the enterprise: robust access control, security monitoring, and automatic updates.
Learn MoreMore Posts by Alibaba Clouder
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
Get Started for Free Get Started for Free