Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to purchase and deploy mongodb server

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What this article shares with you is about how to purchase and deploy mongodb on the server. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Server purchase & configuration

Open Aliyun and choose to purchase CVM ECS. Here you can choose one-click purchase for quick configuration. The operating system selects CentOS 7.264 bit. Other defaults or based on actual needs. If you choose custom purchase, please search on your own.

After you have successfully set the account password, you can connect to our server through the ftp tool (I use FileZilla) or git. At this time, we can also open Aliyun's console / CVM ECS to view the purchased server.

Open Aliyun's console / CVM ECS/ network and security / security group, click configure rules in the list of security groups, and click Quick create rules to expose the port. For example, if you expose port 80, select HTTP (80), enter 0.0.0.0Uniplet0 for the authorized object, and other defaults will be fine. To expose other ports, you can choose a custom port. For example, if you expose port 7001, you can select TCP on the custom port and enter 7001and7001.

To open the node performance platform, click to create a new application and follow the instructions. After successfully enabling it, you can monitor the data in the project configuration (see below for specific configuration).

Connect to the server

1.git connection

# ssh remote_username [@ remote_ip] (/ user/remote_ip) and then enter the password. If ssh does not exist, execute the following command to download client ssh by # yum install openssh-client

Connect to the 2.ftp tool (here take FileZilla as an example). After downloading filezilla, click New site, enter host ip, select sftp protocol, select normal login type, and enter the account password.

Deploy the node environment

1. Deploy the node environment

# ssh remote_username [@ remote_ip] (/ user/remote_ip) connect to server # wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz download node compressed file # tar xvf node-v6.9.5-linux-x64.tar.xz extract # ln-s / root/node-v6.9.5-linux-x64/bin/node / usr/local/bin/node create Soft connection # ln-s / root/node-v6.9.5-linux-x64/bin/npm / usr/local/bin/npm create soft connection # node-v View node version # npm-v View npm version

two。 Other

# download vim from yum install vim

Nginx installation & configuration

1.nginx installation

# yum install epel-release download epel-release # yun install nginx download nginx # cd / etc/nginx # vim nginx.conf Open nginx.conf with vim

two。 Modify nginx.conf

Change user to root

Modify the server as follows, where admin points to the management backend project, app points to the mobile project, and wx points to another node Wechat official account project (runs on port 7002, but the official Wechat account only allows port 80, so set the proxy. Our elm interface runs on 7001 without proxies)

Server {listen 80 default_server; listen [:]: 80 default_server; server_name _; root/ root/www/; # Load configuration files for the default server block. Include / etc/nginx/default.d/*.conf; location / admin/ {# is empty, and the frontend package file can be accessed in / root/www/admin. Note that the default is index.html} location / app/ {} location / wx/ {proxy_pass http://127.0.0.1:7002/;} error_page 404 / 404.html. Location = / 40x.html {} error_page 500 502 503 504 / 50x.html; location = / 50x.html {}}

3. Start nginx

Nginx-t tests whether the syntax of nginx is incorrect. Nginx starts nginx nginx-s reload and restarts nginx. Remember to restart after modifying nginx.conf.

4. Other commands

Ps-ef | grep nginx displays the nginx process nginx-s stop stops nginx nginx-v to view the nginx version

Deploy mongodb

1. Install mongodb

# ssh remote_username [@ remote_ip] (/ user/remote_ip) Connect to the server # curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz download # tar-zxvf mongodb-linux-x86_64-3.0.6.tgz extract # mkdir data create database folder # touch mongodb.log create log file # cd / usr/local/mongodb/bin #. / Mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/mongodb.log-logappend-port=27017-fork Note: fork is started in the background Avoid having to reopen a window to reconnect to the server and do other operations #. / mongo to connect to mongodb

two。 Configuration starts with linux

Add the following to / etc/rc.local:

# rm / usr/local/mongodb/data/mongod.lock stop mongo # /... / bin/mongod-dbpath / usr/local/mongodb/data-logpath / usr/local/mongodb/mongodb.log-logappend-fork-port 27017 that may be running

3. Set permissions

# cd / usr/local/mongodb/bin #. / mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/mongodb.log-logappend-port=27017-fork. / mongo > use admin > db.createUser (> {> user: "root", > pwd: "123456", > roles: [{role: "root", db: "admin"}] >} >) > db.shutdownServer () #. / mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/mongodb.log-logappend-port=27017-fork-auth # db.auth ("root", "123456")

4. Connect mongodb in the project (here take the koa framework egg project as an example, other node should be found by yourself)

# cnpm I egg-mongoose-S / / config/plugin.js exports.mongoose = {enable: true, package: 'egg-mongoose',} / / config/config.default.js config.mongoose = {url:' mongodb://127.0.0.1/eggadmin', options: {/ / if the password / / auth: {"authSource": "admin"}, / / user: "root" is set / / pass: "123456",}}

Deploy the node project

Deployment environment Ali Cloud CentOS 7.264-bit

1. Local project root directory (delete node_modules, it is recommended that you download it on the server)

# tar-zcvf. / file_name.tgz. Package # scp.. / file_name.tgz remote_username [@ remote_ip] (/ user/remote_ip): / root/www/server to upload to the server

two。 Server

# ssh remote_username [@ remote_ip] (/ user/remote_ip) connect to the server # cd / root/www # mkdir server here create a server folder and put the node project code # cd server # tar-zxvf file_name.tgz. Extract # cnpm install-production installation production environment dependency 1. Koa project (similar to express project) # cnpm I-g pm2 download pm2 # pm2 start bin/www daemon start # pm2 restart app_name | app_id restart # pm2 stop app_name | app_id stop # pm2 list View process status # pm2 stop all stop all applications # pm2 start. / bin/www-watch listening changes automatically restart 2. Egg Project # npm start run # npm stop stop

3. Ali node performance platform monitoring

1) koa project (similar to express project)

# wget-O-https://raw.githubusercontent.com/aliyun-node/tnvm/master/install.sh | bash installs version management tool tnvm # source ~ / .bashrc # tnvm ls-remote alinode to view the required version # tnvm install alinode-v3.11.4 installation version # tnvm use alinode-v3.11. Use the required version

Create a new config.json file as follows, and obtain the corresponding access parameters from the node performance platform

{"appid": "," secret ":"} # cnpm install [@ alicloud] (/ user/alicloud) / agenthub-g install agenthub # agenthub start config.json launch agenthub # agenthub list View agenthub list # ENABLE_NODE_LOG=YES pm2 start bin/www applications managed by pm2

2) egg Project

# cnpm i nodeinstall-g # nodeinstall-- install-alinode ^ 3 # cnpm I egg-alinode-- save # npm start / / config/plugin.js exports.alinode = {enable: true, package: 'egg-alinode',}; / / config/config.default.js config.alinode = {appid:', secret:',}

Deploy the front-end project (here take vue as an example)

In the project root directory npm run build, and then transfer the contents of the dist folder to the server, here we send the two project divisions to / root/www/app and / root/www/admin, remember to create the app and admin folders in advance.

The above is how to purchase and deploy mongodb on the server. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report