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 deploy a single instance in MongoDB

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to deploy a single instance in MongoDB. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

1. Installation depends on yum install libcurl openssl2. Download the tar package

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

3. Extract the tar package

Upload the downloaded tar package to the server / apps path. If it does not exist, please create it yourself (Note: currently log in as root)

Root#cd / appsroot#tar-zxvf mongodb-linux-x86_64-rhel70-4.0.2.tgzroot# ls-ldrwxrwxr-x. 3 mongo mongo 86 Dec 8 18:34 mongodb-linux-x86_64-rhel70-4.0.2 RW Murray RW Murray. 1 mongo mongo 82140922 Oct 24 22:03 mongodb-linux-x86_64-rhel70-4.0.2.tgzroot# mv mongodb-linux-x86_64-rhel70-3.2.10 mongodb- for convenience, we renamed document 4. 0. Turn off the firewall root#sudo systemctl stop firewalldroot#sudo systemctl status firewalld5. Close the large memory page 5.1 first check the parameter values: root#sudo cat / sys/kernel/mm/transparent_hugepage/ enabled [always] madvise neverroot#sudo cat / sys/kernel/mm/transparent_hugepage/ defragmentary [always] madvise never5.2 configuration transparent_hugepage service root#sudo vim / etc/init.d/disable-transparent-hugepages

Fill in the following

#! / bin/bash### BEGIN INIT INFO# Provides: disable-transparent-hugepages# Required-Start: $local_fs# Required-Stop:# X-Start-Before: mongod mongodb-mms-automation-agent# Default-Start: 2 3 4 "Default-Stop: 0 1" Short-Description: Disable Linux transparent hugepages# Description: Disable Linux transparent hugepages To improve# database performance.### END INIT INFOcase $1 in start) if [- d / sys/kernel/mm/transparent_hugepage] Then thp_path=/sys/kernel/mm/transparent_hugepage elif [- d / sys/kernel/mm/redhat_transparent_hugepage] Then thp_path=/sys/kernel/mm/redhat_transparent_hugepage else return 0 fi echo 'never' > ${thp_path} / enabled echo' never' > ${thp_path} / defrag re=' ^ [0-1] + $'if [[$(cat ${thp_path} / khugepaged/defrag) = ~ $re]] then # RHEL 7 echo 0 > ${thp_path} / khugepaged/defrag else # RHEL 6 Echo 'no' > ${thp_path} / khugepaged/defrag fi unset re unset thp_path ; esac5.3 authorizes the service and sets boot

Root#sudo chmod 755 / etc/init.d/disable-transparent-hugepagesroot#sudo chkconfig-- check if this parameter is in effect after add disable-transparent-hugepages5.4 restarts the server: root#sudo cat / sys/kernel/mm/transparent_hugepage/enabledalways madvise [never] root#sudo cat / sys/kernel/mm/transparent_hugepage/defragalways madvise [never]

Note: the transparent_hugepage parameter must be set to never, otherwise, there will be the following alarm when logging in to mongo shell:

Official configuration link: Disable Transparent Huge Pages (THP) [https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/]

6. Modify open files

Sometimes the default open files (file handle) of the Linux system is 1024, but the mongod official website recommends 64000, and it really needs to be modified or you will be cheated (unfortunately, I encountered it)

View some settings of the Linux system: [mongo@mongodb01 ~] $ulimit-acore file size (blocks,-c) 0data seg size (kbytes,-d) unlimitedscheduling priority (- e) 0file size (blocks,-f) unlimitedpending signals (- I) 31206max locked memory (kbytes,-l) 64max memory size (kbytes -m) unlimitedopen files (- n) 1024pipe size (512 bytes,-p) 8POSIX message queues (bytes,-Q) 819200real-time priority (- r) 0stack size (kbytes,-s) 8192cpu time (seconds,-t) unlimitedmax user processes (- u) 1024virtual memory (kbytes -v) unlimitedfile locks (- x) unlimited6.2 modification

You can use the command to modify temporarily

Ulimit-n 64000

The server of the above method will be invalidated after restart. Permanent method, modify / etc/security/limits.conf, and add 4 pieces of configuration information related to mongo.

Root#vim / etc/security/limits.conf#@student-maxlogins 4mongo soft nproc 64000mongo hard nproc 64000mongo soft nofile 64000mongo hard nofile 6400 End of file

Note: restart mongod will take effect after successful modification.

7. Create user mongoroot#groupadd mongogrproot#useradd-g mongogrp mongo8. Create the required directory root#mkdir / dataroot#chown-R mongo:mongogrp / dataroot#su mongo$mkdir-p / data/dbdata/r1-data files store $mkdir-p / data/logs/r1_logs-create log file path $mkdir-p / data/pid-mongodb process id store 9. Configure the environment variable $cd / home/mongo$vim .bash _ profile

Modify the PATH variable

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/apps/mongodb/bin-add the mongo program path export PATH$source. Bash _ profile-to make the environment variable effective 10. Create a startup configuration file

Although there are a lot of complex parameters, don't worry, let's start first. Later, I will explain the meaning of the commonly used parameters in detail, because I like to put the configuration file mongodb.cnf (although the name can be called of course) in the / etc directory, you can also put it somewhere else, as you like.

$sudo vim / etc/mongodb.cnf

Fill in the following

Storage: dbPath: / data/dbdata/r1 # data file storage path journal: enabled: true commitIntervalMs: 100directoryPerDB: true engine: wiredTiger wiredTiger: engineConfig: directoryForIndexes: truesystemLog: quiet: false path: / data/logs/r1_logs/r1.log # log log path destination: file logAppend: trueprocessManagement: fork: true pidFilePath: / data/pid/r1.pid # process ID Store net: port: 27018 maxIncomingConnections: 3000 wireObjectCheck: true#security:# keyFile: / data/key/r1# authorization: enabled#replication:# oplogSizeMB: 1024 hours replSetName: rs1 # operationProfiling:# slowOpThresholdMs: 10 percent mode: slowOp

You can save after editing.

Grant authority

$sudo chown-R mongo:mongo / etc/mongodb.cnf11. Start the database instance $/ apps/mongodb/bin/mongod-f / etc/mongodb.cnf12. Connect to the database mongo 192.168.1.100VR 27018

We can verify that the startup is successful by checking whether we can connect to the mongo shell, or we can look at the process directly.

$ps-ef | grep mongod shares here on how to deploy a single instance in MongoDB. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

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

Database

Wechat

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

12
Report