In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Installation and configuration of MongoDB 1. Overview
NoSQL refers to a non-relational database. NoSQL, sometimes referred to as the abbreviation of Not Only SQL, is a general term for database management systems that are different from traditional relational databases.
NoSQL is used to store very large-scale data. Google or Facebook, for example, collect terabytes of data for their users every day. These types of data stores do not require fixed schemas and can be scaled out without redundant operations.
Today we can easily access and grab data through third-party platforms (such as Google,Facebook, etc.). Users' personal information, social networks, geographic locations, user-generated data and user action logs have increased exponentially. If we want to mine these user data, then SQL database is no longer suitable for these applications, but the development of NoSQL database can well deal with these large data.
Advantages of NoSQL
High scalability can be scaled horizontally or vertically
Distributed computing
Low cost and high performance
Architectural flexibility, semi-structured data
There are no complicated relationships.
MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications.
MongoDB is a product between relational database and non-relational database, which is the most functional and most similar to relational database. Support for object-oriented query language, can achieve almost most of the functions similar to relational database single table query, but also support the establishment of data indexing. So this is very convenient, we can use sql to operate MongoDB, migrate from the relational database, developers will greatly reduce the cost of learning. If you encapsulate the underlying sql API, the developer can hardly feel the difference between mongodb and relational database. Similarly, MongoDB claims to be able to quickly build a highly available and scalable distributed cluster.
II. Installation, configuration and application
MongoDB can be installed and used on windows, as well as the linux platform. I choose linux platform installation here.
1. First download and extract the installation package
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 mv mongodb-linux-x86_64-3.0.6 / / usr/local/mongodb # copy the unzipped package to the specified directory
Add the executable path of MongoDB to the PATH variable (~ / .bash_profile)
PATH=$PATH:$HOME/bin:/usr/local/mongodb/bin
two。 Create the paths and files needed for mongodb startup
Mkdir / data/db # create a data folder for mongodb mkdir / usr/local/mongodb/logs/ # create a folder for mongodb logs touch / usr/local/mongodb/logs/mongodb.log # create a log file for mongodb
3. Start the mongodb service. Just execute the command window directly.
[root@DB] # mongod 2017-11-14T13:14:19.809+0800 I JOURNAL [initandlisten] journal dir=/data/db/journal2017-11-14T13:14:19.809+0800 I JOURNAL [initandlisten] recover: no journal files present No recovery needed2017-11-14T13:14:19.815+0800 I JOURNAL [durability] Durability thread started2017-11-14T13:14:19.815+0800 I JOURNAL [journal writer] Journal writer thread started2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] MongoDB starting: pid=4287 port=27017 dbpath=/data/db 64-bit host=DB2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user Which is not recommended.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2017-11-14T13:14:19 .834 + 0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: soft rlimits too low. Rlimits set to 16384 processes, 65536 files. Number of processes should be at least 32768: 2017 times number of files.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] db version v3.0.62017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f22017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] build info: Linux build6.ny.cbi.10gen.cc 2.6.32-431.3.1.el6 .x86 _ 64 # 1 SMP Fri Jan 3 21:39:27 UTC 2014 x86 14T13:14:19.834+0800 64 BOOST_LIB_VERSION=1_492017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] allocator: tcmalloc2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] options: {} 2017-11-14T13:14:19.849+0800 I NETWORK [initandlisten] waiting for connections on port 27017
You can see that the mongodb service process is started and port 27017 is open waiting to connect.
Open another command window and use the mongo command to interact with mongodb. Because it is a JavaScript Shell, you can test it by typing a simple arithmetic operation:
[root@DB mongodb] # mongo MongoDB shell version: 3.0.6connecting to: testServer has startup warnings: 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user Which is not recommended.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2017-11-14T13:14:19 .834 + 0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] 2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] * * WARNING: soft rlimits too low. Rlimits set to 16384 processes, 65536 files. Number of processes should be at least 32768: 0.5 times number of files.2017-11-14T13:14:19.834+0800 I CONTROL [initandlisten] > 3: 25
You can also insert some simple data to query and verify:
> db.a.insert ({nInserted 1}) WriteResult ({"nInserted": 1}) > db.a.find () {"_ id": ObjectId ("5a0a7fa7766decd974b3ad3f"), "a": 1} >
3. Description of mongodb startup command parameters
The main parameters of mongod are:
-- quiet# quiet output-- port arg# specifies the service port number. The default port 27017--bind_ip arg# binds to the service IP. If it is bound to 127.0.0.1, it can only be accessed locally. Do not specify all local IP--logpath arg# by default to specify MongoDB log files. Note that the specified file is not a directory-- logappend# writes the log by append-- the full path of pidfilepath arg# PID File, if not set. Then there is no PID file-- the full path to the private key of the keyFile arg# cluster, and is only valid for the Replica Set architecture-- unixSocketPrefix arg# UNIX domain socket replacement directory, (default is / tmp)-- fork# runs MongoDB as a daemon Create server process-auth# enable authentication-cpu# periodically displays CPU utilization of CPU and iowait--dbpath arg# specified database path-diaglog arg# diaglog option 0=off 1W2R 3=both 7=W+some reads--directoryperdb# setting each database will be saved in a separate directory-journal# enable logging option The data operation of MongoDB will be written to the file in the journal folder-- journalOptions arg# enables log diagnostics option-- ipv6# enables IPv6 option-- jsonp# allows JSONP access through HTTP (with security implications)-- maxConns arg# maximum number of simultaneous connections default 2000--noauth# does not enable authentication-- nohttpinterface# shuts down the http interface. Turn off port 27018 access by default-noprealloc# disables data file pre-allocation (often affecting performance)-noscripting# disables scripting engine-notablescan# does not allow table scanning-nounixsocket# disables Unix socket snooping-nssize arg (= 16) # sets letter database .ns file size (MB)-objcheck# checks for validity after receiving customer data -- profile arg# archive parameter 0=off 1=slow, 2=all--quota# limits the number of files per database Set to 8--quotaFiles arg# number of files allower per db by default, requires-- the directory where quota--rest# enables simple rest API--repair# repair of all the files generated by the run repair on all dbs--repairpath arg# repair library. The default is the directory name dbpath--slowms arg (= 100) # value of slow for profile and console log--smallfiles# uses the smaller default file-- syncdelay arg (= 60) # the number of seconds in which data is written to disk (0=never) (not recommended)-- sysinfo# prints some diagnostic system information-- upgrade# if you need to upgrade the database * Replicaton parameter-- -- fastsync# enables replication from the library from a dbpath The database of the dbpath is a snapshot of the master library and can be used to quickly enable synchronization-autoresync# automatically resynchronizes if the synchronization data between the slave library and the master library is much worse -- oplogSize arg# sets the size of oplog (MB) * Master / slave parameters-master# master library mode-- slave# slave Library mode-source arg# slave library port number-only arg# specifies a single database replication-slavedelay arg# sets the delay time for synchronizing the master database from the library * Replica set (replica set) option: -replSet arg# sets the replica set name * Sharding (sharding) option -configsvr# declares that this is a clustered config service Default port 27019 The default directory / data/configdb--shardsvr# declares that this is a cluster shard, and the default port 27018--noMoveParanoia# is paranoid that moveChunk data is saved. All the above parameters can be written into the mongodb.conf configuration file: [root@DB mongodb] # cat mongodb.conf dbpath=/data/dblogpath=/usr/local/mongodb/logs/mongodb.loglogappend=trueport=27017fork=trueauth=falsenohttpinterface=falsebind_ip=192.168.221.160journal=truequiet=true.
Use the-f parameter to refer to this location at startup
[root@DB mongodb] # mongod-f / usr/local/mongodb/mongodb.conf about to fork child process, waiting until server is ready for connections.forked process: 4319child process started successfully Parent exiting [root@DB mongodb] # ps-ef | grep mongoroot 4319 11 13:36? 00:00:00 mongod-f / usr/local/mongodb/mongodb.conf [root@DB mongodb] # mongo 192.168.221.160 MongoDB shell version: 3.0.6connecting to: 192.168.221.160/testServer has startup warnings: 2017-11-14T13:36:25.213+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user Which is not recommended.2017-11-14T13:36:25.213+0800 I CONTROL [initandlisten] 2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] 2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2017-11-14T13:36:25 .214 + 0800 I CONTROL [initandlisten] 2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] 2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] * * WARNING: soft rlimits too low. Rlimits set to 16384 processes, 65536 files. Number of processes should be at least 32768: 0.5 times number of files.2017-11-14T13:36:25.214+0800 I CONTROL [initandlisten] > db.a.find () {"_ id": ObjectId ("5a0a7fa7766decd974b3ad3f"), "a": 1} >
As we all know, this single-instance configuration is only suitable for learning and development, and production will definitely not use it in this way, otherwise the whole data stream will be lost if a single node is hung up.
In the next article, we will continue to learn the configuration of mongodb master and slave.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.