linux operation and maintenance, road -MongoDB standalone deployment architecture

A, MongoDB Introduction

MongoDB is a distributed file storage based database. Written by C ++ language. Designed to provide scalable, high-performance data storage solution for WEB applications.

MongoDB is a product with function between relational databases and non-relational databases, non-relational database functions among the richest, most relational database like.

MongoDB the data is stored as a document data structure of the key (key => value) pairs. MongoDB document similar to JSON object. Field value can contain other documents, arrays and array of documents.

Second, the main features

  • MongoDB is a document-oriented database that stores operate more simple and easy.
  • Any attribute can be provided in the recording MongoDB index (eg: FirstName = "Sameer", Address = "8 Gandhi Road") to achieve faster sorting.
  • Image data can be created locally or through a network, which makes it stronger MongoDB scalability.
  • If the load increases (requires more storage space and more processing power), it can be distributed in a computer network on a different node This is called fragmentation.
  • Mongo supports a rich query expressions. JSON query instruction using the form tag can easily query document embedded objects and arrays.
  • MongoDb using update () command to implement the document (data) or complete replacement of some of the specified data fields.
  • Map / reduce Mongodb it is mainly used for data processing and batch polymerization operations.
  • Map and Reduce. Map function call EMIT (key, value) through all of the record set, and the key value passed to Reduce function processing.
  • Map and Reduce functions are functions written using Javascript, and MapReduce operation can be performed by db.runCommand or mapreduce command.
  • GridFS is a built-in feature in MongoDB can be used to store a large number of small files.
  • MongoDB allows the server to execute the script, you can use Javascript to write a function, execute directly on the server, you can put the function definitions are stored in the server, you can directly call the next time.
  • MongoDB supports a variety of programming languages: RUBY, PYTHON, JAVA, C ++, PHP, C # and other languages.
  • Easy to install MongoDB

Three, MongoDB deployment

1, the installation required dependencies

yum install libcurl openssl

2. Download Source Package

Download: HTTPS: // www.mongodb.com/download-center?jmp=nav#community

3, create the required directories

mkdir -p /app/mongodb4.0/{install,logs,conf,data}

4, upload unpack mongodb-linux-x86_64-4.0.0.tgz to /app/mongodb4.0/install directory

tar xf mongodb-linux-x86_64-4.0.0.tgz -C /app/mongodb4.0/install/

5, create MongoDB configuration files, log files

touch /app/mongodb4.0/logs/mongodb.log
touch /app/mongodb4.0/conf/mongodb.conf

6, edit mongodb.conf

port=27017
fork=true
logpath=/app/mongodb4.0/logs/mongodb.log
#logappen=true
dbpath=/app/mongodb4.0/data
auth=false

7, start MongoDB

/app/mongodb4.0/install/bin/mongod -f /app/mongodb4.0/conf/mongodb.conf

8, configure MongoDB

① into the MongoDB command mode

/app/mongodb4.0/install/bin/mongo 127.0.0.1:27017

② create a database

use demon

③ create a user administrator

Add a user with userAdminAnyDatabase role in the admin database

use admin
db.createUser({user:"admin",pwd:"admin",roles:[{role:"readWrite",db:"demon"}]});
db.createUser({user:"admin",pwd:"admin",roles:[{role:"readWriteAnyDatabase",db:"demon"}]});

9, stop MongoDB

/app/mongodb4.0/install/bin/mongod -f /app/mongodb4.0/conf/mongodb.conf -shutdown

10, edited mongodb.conf auth = true

/app/mongodb4.0/install/bin/mongod -f /app/mongodb4.0/conf/mongodb.conf

11, using the above created user login MongoDB

/app/mongodb4.0/install/bin/mongo --port 27017 -u "admin" -p "admin" --authenticationDatabase "admin"

Fourth, the development of MongoDB startup script

1, scripting

#!/bin/bash
# chkconfig: - 98 21
Mongod_Path="/app/mongodb4.0/install/bin/mongod"
Mongod_Conf="/app/mongodb4.0/conf/mongodb.conf"

usage() {
    echo "usage: $0 [start|stop|restart]"
}


start_Mongod() {
   $Mongod_Path -f $Mongod_Conf
   echo "Mongodb is starting"
}

stop_Mongod() {
   $Mongod_Path -f $Mongod_Conf --shutdown
   echo "Mongodb is stopped"
}


main() {
case $1 in
    start)
         start_Mongod;;
    stop)
         stop_Mongod;;
    restart)
         stop_Mongod && start_Mongod;;
    *)
         usage;
esac
}
main $1

2, grant script executable permissions

chmod +x /etc/init.d/mongod
chkconfig --add mongod

3, start, stop, re MongoDB service

/etc/init.d/mongod start
/etc/init.d/mongod stop
/etc/init.d/mongod restart

Fifth, the MongoDB database related operations


> Show dbs; # view the database under the current instance
> show databases; #-compliant relational database MySQL command
> use local; # switch databases local
> Show the Collections; # to view the collection database local of
> show tables; #-compliant relational database MySQL command
operation used is as follows:

 

Guess you like

Origin www.cnblogs.com/yanxinjiang/p/11009513.html