MongoDB installation and multi-instance start MongoDB Introduction
MongoDB is a cross-platform, document-oriented database. Can achieve high performance, high availability, and can easily scale, is a distributed file storage based open source database system, in the case of high load, add more nodes can guarantee the performance of the server.
In the age of big data, the processing of large data volumes has become one of the most important reasons to consider a database. One of the main goals of MongoDB is to keep the database as excellent as possible, which largely determines the design of MongoDB. MongoDB chooses to maximize its use of memory resources as a cache for superior performance, and automatically selects the fastest index for querying. MongoDB is one of the reasons why MongoDB can maintain superior performance by streamlining the database as much as possible and handing over as many operations as possible to the client.
MongoDB is the most versatile non-relational database (NoSQL), most like a relational database. Without a relational model for better extensibility, MongoDB does not have a "line" concept, and it works primarily on two concepts: Collections (collection) and documents.
Features of MongoDB
MONGO is a high-performance, open-source, modeless, document-based database that can be used in many scenarios to replace traditional relational databases or key/value storage methods.
1. Collection-oriented storage: suitable for storing objects and data in JSON form.
2, the MongoDB installation is simple, provides the document-oriented storage function, the operation is relatively easy.
3. MONGODB provides replication, high availability and automatic sharding capabilities. If the load increases (requiring more storage space and greater processing power), it can be distributed across other nodes in the computer network, which is called sharding.
4. MongoDB supports rich query expressions.
5, efficient traditional storage: support binary data and large objects (such as photos or pictures).
MongoDB Areas of Application
1. MongoDB can provide a scalable and high-performance data storage solution for Web applications. MongoDB's main areas of application are Web site data, distributed scenarios, data caches, and JSON document format storage. For Internet applications with large data volumes, high concurrency, and weak transactions, the built-in horizontal scaling mechanism provides data processing capabilities from millions of to 1 billion levels, which can be used to meet the requirements of Web2.0 and mobile Internet application storage.
MongoDB installation 1, download and install MongoDB and support software.
We chose to download the package directly, because the virtual machine I use is CentOS7 and is a 64-bit version, so we choose the corresponding REDHAT7 version 64-bit. After downloading, the configuration can be used directly. Because the package has SSL secure encryption enabled, we need to install the OpenSSL dependent package.
[[email protected] ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.0.tgz #可以直接下载[[email protected] ~]# yum install openssl openssl-devel -y #安装相关依赖包[[email protected] ~]# tar xvfz mongodb-linux-x86_64-rhel70-4.0.0.tgz -C /usr/local/#将压缩包解压到指定的目录中[[email protected] ~]# mv /usr/local/mongodb-linux-x86_64-rhel70-4.0.0/ /usr/local/mongodb#重命名软件包,方便以后使用
2. Create data store directory, log storage directory and log file
Since we are downloading a compiled package, we need to create our own data store directory, log storage log and log file.
[[email protected] ~]# mkdir -p /data/mongodb1#创建数据存储目录[[email protected] ~]# mkdir -p /data/logs/mongodb#创建日志存储目录[[email protected] ~]# touch /data/logs/mongodb/mongodb1.log#创建日志文件[[email protected] ~]# chmod -R 777 /data/logs/mongodb/mongodb1.log #修改日志文件权限,方便下面操作
When MongoDB is in a state of frequent access, if the shell startup process consumes a resource set too low, it will generate an error to be unable to connect to MongoDB.
[[email protected] ~]# ulimit -n 2500 #修改shell所能启用的最大进程数[[email protected] ~]# ulimit -u 2500 #修改shell所能打开的最大文件数
3. Create MongoDB profile and configure startup parameters
The downloaded package does not have a configuration file and we need to create it ourselves.
[[email protected] ~]# cd /usr/local/mongodb/bin/[[email protected] bin]# vim mongodb1.confport=27017 #默认服务器端口号dbpath=/data/mongodb1 #数据存储目录,就是我们上一步创建的logpath=/data/logs/mongodb/mongodb1.log #日志文件logappend=true #使用追加方式写日志fork=true #后台运行maxConns=5000 #最大连接数
4. Start and stop MongoDB
The MongoDB service that can be started after the installation and configuration is ready.
[[email protected] bin]# Export path= $PATH:/usr/local/mongodb/bin/#可以把MongoDB的路径加入到环境变量 so that you can use the relevant commands of MongoDB directly [[email protected] bin]# mongod-f/usr/local/mongodb/bin/mongodb1.conf#mongod用于启动服务进程,-F followed by the configuration file path of the service [[email protected] bin]# Netstat-ntap | grep Mongod #可以查看MongoDB的进程启动状态tcp00127.0.0.1:270170.0.0.0:* LISTEN78984/mongo[[email protected] bin]# MONGO #可以进入到数据库中 [[email protected] bin]# mongod-f/usr/local/mongodb/bin/mongodb1.conf--shutdown#-- Shutdown indicates that the MongoDB service process is closed 2018-07-T21: 828+0800 I CONTROL [main] automatically disabling TLS 1.0, to force-enable TLS 1.0 Specify--ssldisabledpro Tocols ' None ' killing process with PID: 78984[[email protected] bin]# Netstat-ntap | grep mongod #没有Mo Ngodb process
Start a MongoDB multi-instance
With sufficient resources for a single server, multiple instances can be used to make full use of server resources. Steps are the same as above, creating a set of data store directories, log files, and configuration files.
[[email protected] bin]# mkdir-p/DATA/MONGODB2#创建新的数据存储目录 [[email protected] bin]# Touch/data/logs/mongodb/mongodb2.log#创建新的日志文件 [[email protected] bin]# Chmod-r 777/data/logs/mongodb/mongodb2.log#赋予日志文件对应权限 [[email protected] bin]# chmod-r 777/data/logs/mongodb/mongodb2.log [[email protected] bin]# cp/usr/local/mongodb/bin/mongodb1.conf/usr/local/mongodb/bin/mongodb2.conf#复制一份新的配置文件, then modify the corresponding parameters port=27018#设置一个新的端口号dbpath =/data/mongodb2#设置新的数据存储目录 logpath=/data/logs/mongodb/mongodb2.log#设置新的日志文件logappend =truefork=truemaxconns=5000[[email protected] bin]# mongod-f/usr/local/mongodb/bin/mongodb2.conf #开启新实例的进程 [[email protected] bin]# mongod-f/usr/local/mongodb/bin/mongodb1.conf2018-07-16T21:31:16.103+0800 I CONTROL [main] automatically disabling TLS1.0, to Force-enable TLS1.0 Specify--ssldisabledprotocols' None ' about-to-fork child process, waitingUntil server is readyFor connections.forkedProcess79334child process started successfully, parent Exiting[[email protected] bin]# Netstat-ntap | grep mongotcp00 127.0. 0.1:27017 0.0. 0.0:* LISTEN 79334/mongod TCP 0 0 127.0. 0.1:27018 0.0. 0.0:* LISTEN 79304/mongod #可以看到开启了两个实例
MongoDB installation and multi-instance startup