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 do I install and configure MongoDB?

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

Share

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

Introduction to MongoDB

MongoDB is written in C++ language and is an open source database system based on distributed file storage.

In the case of high load, adding more nodes can ensure server performance.

MongoDB aims to provide scalable, high-performance data storage solutions for WEB applications.

Install MongoDB and configuration

1. Install related software packages

[root@centos-01] # wget-b http://downloads.mongodb.org/linux/mongodb-linux-x86_64-3.6.14.tgz

[root@centos-01 ~] # tar zxvf mongodb-linux-x86_64-3.6.14.tgz

[root@centos-01] # mv mongodb-linux-x86_64-3.6.14 / ust/local/mongodb

2. Create the data storage directory and log storage directory of MongoDB

[root@centos-01] # mkdir-p / data/mongodb/data

[root@centos-01] # mkdir-p / data/logs/mongodb

[root@centos-01] # ln-s / usr/local/mongodb/bin/* / usr/bin/

3. When the MongoDB is accessed frequently, if the resource consumed by the shell startup process is set too low, an error will result in the failure to connect to the MongoDB instance. The values of ulimit-n and ulimit-u need to be greater than 20000.

[root@centos-01] # ulimit-n 25000

[root@centos-01] # ulimit-u 25000

4. Create a MongoDB configuration file and define the relevant parameters needed for startup.

[root@centos-01 ~] # vim / etc/mongodb.cnf# system log systemLog: # log output destination, you can specify "file" or "syslog" destination: file # write log logAppend: true # log storage directory path: / data/logs/mongodb/mongo.logstorage: # data storage directory dbPath: / data/mongodb/data # whether journal log persistent storage is enabled Journal log is used for data recovery and is the most basic feature of mongod. Commonly used for failure recovery journal: enabled: true# engine: wiredTiger# mmapv1:# the following configuration is only valid for wiredTiger engines (version 3.0 or later) wiredTiger: engineConfig: # wiredTiger cache working set (working set) memory size cacheSizeGB: 4 # whether to store index and collections data in a separate directory of dbPath directoryForIndexes: false collectionConfig: blockCompressor: zlib IndexConfig: prefixCompression: false# how the process runsprocessManagement:# the full path of running the process fork: true # PID File in a later mode If it is not set, there is no PID file pidFilePath: / data/mongodb/mongod.pid # network interfacesnet:# default server port number port: 27017#mongodb bound ip address bindIp: 127.0.0.1security:# indicates whether to enable user access control authorization: enabled# performance analyzer operationProfiling: # enable slow log slowOpThresholdMs: 100 mode: slowOp# if the architecture mode is replication Set Then you also need to add the following configuration to all "replication set" members: # replication:# oplogSizeMB: 2048 # replSetName: mongodb # sharding:## Enterprise-Only Options#auditLog:

5. Set kernel parameters and turn off NUMA

[root@centos-01 ~] # echo 0 > / proc/sys/vm/zone_reclaim_mode / / when one node runs out of available memory, the system allocates memory from other nodes

[root@centos-01 ~] # sysctl-w vm.zone_reclaim_mode=0 / / permanent setting

6. Mongodb start and stop

[root@centos-01 ~] # mongod-f / etc/mongodb.cnf / / start

[root@centos-01] # mongod-f / etc/mongodb.cnf-- shutdown / / stop

[root@centos-01 ~] # netstat-anpt | grep mongod

Tcp 0 0 127.0.0.1 27017 0.0.0.0 * LISTEN 33475/mongod

7. Set it to boot automatically.

[root@centos-01 ~] # echo "mongod-f / etc/mongodb.cnf" > > / etc/rc.local

8. After entering MongoDB, you can also close mongoDB in this way.

Use admin;db.shutdownServer ()

9. In order to facilitate the management of operation and maintenance personnel, write a control script for MongoDB database

[root@centos-01 ~] # vim / etc/init.d/mongod

#! / bin/bash

PROG= "/ usr/local/mongodb/bin/mongod"

CONFIG=$1

CONF= "/ etc/$CONFIG.cnf"

Case "$2" in

Start)

$PROG-f $CONF

Stop)

$PROG-f $CONF-- shutdown

Restart)

$0 stop

Sleep 1

$0 start

Sleep 1

Echo "mongod has been restarted successfully"

*)

Echo "Usage: $0 {start | stop | restart}"

Exit 2

Esac

Exit 0

[root@centos-01 ~] # chmod + x / etc/init.d/mongod

[root@centos-01] # chkconfig-- add mongod

[root@centos-01 ~] # / etc/init.d/mongod start

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