Deploying MEAN Stack on CentOS 7.2
By Sumathi Kuppusamy,Alibaba Cloud Tech Share Author
IntroductionMEAN 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 WalkthroughLet 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 Login to Alibaba ECS console and go to “Instances” section in the left hand side bar. 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”. For better security, add SSH key pair and choose the created key pair from the list while creating the instance. Also choose security group with strict rules. After filling the instance name and other details, click on “Add to Cart”. Preview the details in the shopping cart.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.
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.
Install the MongoDB server by executing the following command:yum install -y mongodb-org
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
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’}]})
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:pa55w0rd,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.
![8 8](https://yqfile.alicdn.com/2c418276c64f1315f3571556ba058e8cfb42e8b1.png)
sudo npm install -g bower
![9 9](https://yqfile.alicdn.com/ff1129cae012f18dbc54407427c5618d8dd5f52d.png)
sudo npm install -g gulp
![10 10](https://yqfile.alicdn.com/11714fe98c0630a0314c04600b476e7bb20a0197.png)
yum update -y opensslOutput:
![11 11](https://yqfile.alicdn.com/f5516c186f7e9fa80e93c8ebc457cbdb8e740a3f.png)
git clone https://github.com/linnovate/mean.git
![12 12](https://yqfile.alicdn.com/d8819bca549af064512508322ae0822474d227ef.png)
cd mean(Optional) You can inspect the directory structure of mean by using the command “ls”:
![13 13](https://yqfile.alicdn.com/2ab1fbbac0439c67c4c49e3ccae9f4f8a507f907.png)
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 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 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 14](https://yqfile.alicdn.com/aff61fa5728afcb391d8100ef3d1fd9f7f3a27d2.png)
![last last](https://yqfile.alicdn.com/c7248aa5233f5031999c19d6a39e8eae148c1c4a.png)
Run containerd as Container Runtime in production 立即下载
相关文章
- Win7 VNC远程连接Centos桌面
- Centos 安装Apache软件
- CentOS系统查看本机IP地址
- centos 8.2 配置 go 项目开发环境
- 如何在CentOS 5/6上安装EPEL 源
- 如何在RedHat/CentOS 7.x中使用nmcli管理网络
- 【大数据】虚拟机网络配置-CentOS
- centos 6升级内核小版本、更新yum源和升级gcc版本
- Installing Supervisor and Superlance on CentOS
- How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7
- Centos网络配置小工具
- Linux简介与常用命令合集(for CentOS)——Linux入门就靠这一篇
- Centos下将sh脚本变为可全局运行的方法
- IP Failover Setup using Keepalived on CentOS/Redhat 6
- 转载--How to Install VMware Tools on CentOS 6.3
- install keepalived on RedHat/CentOS to provide IP failover for web cluster
- centos 7 查看磁盘io ,找出占用io读写很高的进程
- 最新系统centos安装最新版python 3.8.5以及pip换源、临时指定源,pytest安装后的使用以及出现pytest命令not found无法识别
- centos硬件查询