Deploying MEAN Stack on CentOS 7.2

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: MEAN stack is one of the modern web application javascript framework that’s rapidly improving and easy to collaborate and learn.

0213_Continuous_delivery_with_Docker_change_the_way_of_delivery_with_technology_Part_1

By Sumathi Kuppusamy,Alibaba Cloud Tech Share Author

Introduction

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.

Step by Step Walkthrough

Let us look at the steps in detail to deploy MEAN stack on an Alibaba Cloud ECS instance with CentOS 7.2.

Step 1: Create an instance on ECS

  1. Login to Alibaba ECS console and go to “Instances” section in the left hand side bar.
  2. Click on “Create Instance” in Instances page and choose the pricing model, the nearest datacenter region and zone, instance type, network type, security group, network billing type and then the operating system “CentOS 7.2 64bit”.
  3. For better security, add SSH key pair and choose the created key pair from the list while creating the instance.
  4. Also choose security group with strict rules.
  5. After filling the instance name and other details, click on “Add to Cart”. Preview the details in the shopping cart.

01

  1. Once VM is created, you can look at the instance details in ECS Overview page.

02

  1. You can procure Elastic IP and assign to VM for mapping to your domain name. Otherwise by default, a temporary IP Address will be assigned.

Step 2: Install NodeJS

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:

1

Step 3: Install MongoDB

MongoDB is the leading NoSQL database service. We will now install it on our ECS instance.

  1. Setup the repo as given in the below steps by creating a file “mongodb.repo” in the directory “/etc/yum.repos.d”.

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.

  1. Install the MongoDB server by executing the following command:

yum install -y mongodb-org

2

  1. Configuring MongoDB server in authentication mode:
    By default, when you start MongoDB server it runs in promiscuous mode. In order to restrict MongoDB server based on authentication, you need to create users and run mongod service with ‘-auth’ mode.

● Start the mongod service in noauth mode following the below command:

mongod –fork –dbpath /var/lib/mongo –logpath /var/log/meandb.log

3

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:‘pa55w0rd’,roles:[{role:‘userAdminAnyDatabase’,db:‘admin’}]})

4

Enter the command “exit” when complete to exit from the mongo shell.

● Now stop the mongod service.

mongod –shutdown –dbpath /var/lib/mongo

5

● Now start the mongod service in -auth mode

mongod –fork –auth –dbpath /var/lib/mongo –logpath /var/log/meandb.log

6

● 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:'pa55w0rd',roles:[{role:'readWrite',db:'new-mean'}]})

7

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 pa55word
new-mean meanuser pa55w0rd

Step 4: Installing Dependencies

a. Install the git by giving the below command:
yum install -y git
8 b. Install bower and gulp packages In order to bring up the MEAN stack, package managers such as npm, bower, gulp need to be installed. Bower is the package manager for web components. Install these dependencies by running the following commands: ●
sudo npm install -g bower
9
sudo npm install -g gulp
10 Note: ●“-g” flag is important to ensure that bower and gulp are installed globally. ●If you encounter the below error “npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference”, please run the following command and then re-run the above commands.
yum update -y openssl
Output: 11

Step 5: Installing MEAN Application

a. Clone the mean repo service and change the current working directory to mean:
git clone https://github.com/linnovate/mean.git
12
cd mean
(Optional) You can inspect the directory structure of mean by using the command “ls”: 13 The package.json file describes dependencies for AngularJS, Web Components and NodeJS. MEAN uses the https://webpack.github.io/”>webpack for bundling web assets. b. Install mean project packages by running the following command:
npm install 
Note: 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.js
Change the line containing “MONGO_HOST”: process.env.MONGO_HOST='mongodb://localhost/new-mean' To process.env.MONGO_HOST='mongodb://meanuser@pa55w0rd@localhost/new-mean' c. Start the mean service with production mode
export NODE_ENV=production
npm start
14

Step 6: Grant public access to your MEAN app

As a security measure, all your “inbound” network connections are blocked. You can add a rule to security group of your instance to allow inbound traffic on port 8080 through Alibaba ECS console. last

Step 7: Browser access to the MEAN application

Launch the browser with the URL http://<external_ip_of_instance>:8080/ Note: Replace with the actual IP address of your ECS instance.

Summary

Thus, we could bring up a MEAN stack based web application on Alibaba Cloud ECS in just few minutes. Now, you have a fully functional https://github.com/linnovate/mean”>MEAN stack on your server!
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。 &nbsp; 相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
监控 Java 应用服务中间件
|
应用服务中间件 Linux 开发工具
|
关系型数据库 应用服务中间件 Linux
|
9天前
|
Linux 网络安全 Python
linux centos上安装python3.11.x详细完整教程
这篇文章提供了在CentOS系统上安装Python 3.11.x版本的详细步骤,包括下载、解压、安装依赖、编译配置、解决常见错误以及版本验证。
67 1
linux centos上安装python3.11.x详细完整教程
|
2月前
|
消息中间件 Linux API
centos7 安装rabbitmq自定义版本及配置
centos7 安装rabbitmq自定义版本及配置
|
7天前
|
Unix Linux 开发工具
centos的官网下载和vm16虚拟机安装centos8【保姆级教程图解】
本文详细介绍了如何在官网下载CentOS 8以及在VMware Workstation Pro 16虚拟机上安装CentOS 8的步骤,包括可能出现的问题和解决方案,如vcpu-0错误的处理方法。
centos的官网下载和vm16虚拟机安装centos8【保姆级教程图解】
|
8天前
|
消息中间件 Linux
centos7安装rabbitmq
centos7安装rabbitmq
|
7天前
|
Linux 虚拟化 Windows
完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)
这篇文章提供了解决VMware Tools无法重新安装(显示为灰色)问题的步骤,并介绍了如何在CentOS 8上创建和配置VMware共享文件夹。
完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)
|
8天前
|
Docker 容器
centos7.3之安装docker
centos7.3之安装docker
下一篇
无影云桌面