In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "MongoDB database installation and deployment and warning optimization methods are", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "MongoDB database installation and deployment and warning optimization method is what" it!
1. Software download
Version 3.6.13
Version 4.0.14
Official website document: https://docs.mongodb.com/manual/
two。 Deploy MongoDB2.1. Planning deployment directory program directory [root@mongodb-1 ~] # mkdir / data/mongodb_cluster/mongodb_27017/ {conf,data,logs Pid}-p Software directory [root@mongodb-1 ~] # mkdir / data/ Software [root @ mongodb-1] # tree / data//data/ ├── mongodb_cluster │ └── mongodb_27017 │ ├── conf │ data │ logs │ └── pid └── soft7 directories, 0 files2.2. Download the package [root@mongodb-1 ~] # cd / data/soft/ [root @ mongodb-1 / data/soft] # wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.14.tgz2.3. Install MongoDB
After downloading, MongoDB can be decompressed and used. It does not contain configuration files and needs to be created by yourself.
1. Extract MongoDB [root @ mongodb-1 / data/soft] # tar xf mongodb-linux-x86_64-4.0.14.tgz-C / data/mongodb_cluster/2. Make a soft connection [root@mongodb-1 / data/soft] # cd / data/mongodb_cluster/ [root @ mongodb-1 / data/mongodb_cluster] # ln-s mongodb-linux-x86_64-4.0.14 / mongodb3. Create the MongoDB configuration file directory [root@mongodb-1 ~] # mkdir / data/mongodb_cluster/mongodb_27017/ {conf,data,logs Pid}-p [root @ mongodb-1] # tree / data/-d/data/ ├── mongodb_cluster │ ├── mongodb- > mongodb-linux-x86_64-4.0.14 / │ ├── mongodb_27017 │ │ ├── conf │ │ ├── data │ │ ├── logs │ │ └── pid │ └── mongodb-linux-x86_64. 14 │ └── bin └── soft2.4.MongoDB configuration file introduction configuration file Note: systemLog: destination: file / / Mongodb log output to file logAppend: true / / when the instance is restarted Instead of creating a new log file, continue to add path: / data/mongodb_cluster/mongodb_27017/logs/mongodb.log / / log path storage: journal: / / rollback log at the end of the old log file Binlog enabled similar to mysql: true / / enable rollback log dbPath: / data/mongodb_cluster/mongodb_27017/data / / data storage directory directoryPerDB: true / / default False does not apply to inmemoryengine wiredTiger: / / storage engine engineConfig: cacheSizeGB: 1 / / the size that will be used for all data caches directoryForIndexes: true / / default false index collection storage.dbPath is stored in a single subdirectory of data, which must be configured as true Otherwise, the data files of all libraries will be stored in a directory collectionConfig: blockCompressor: zlib / / enable compressed indexConfig: prefixCompression: true / / Open index processManagement: / / system daemon control processing fork: true / / Run pidFilePath: / data/mongodb_cluster/mongodb_27017/pid/mongod.pid / / pid file path net: port: 27017 / / listen port bindIp: 127.0.0.1192.168.81.210 / bind ip2.5. Write MongoDB configuration file [root@mongodb-1 ~] # cd / data/mongodb_cluster/mongodb_27017/ [root @ mongodb-1 / data/mongodb_cluster/mongodb_27017] # vim conf/mongodb.ymlsystemLog: destination: file logAppend: true path: / data/mongodb_cluster/mongodb_27017/logs/mongodb.logstorage: journal: enabled: true dbPath: / data/mongodb_cluster/mongodb_27017/data directoryPerDB: true wiredTiger: engineConfig: cacheSizeGB: 1 DirectoryForIndexes: true collectionConfig: blockCompressor: zlib indexConfig: prefixCompression: trueprocessManagement: fork: true pidFilePath: / data/mongodb_cluster/mongodb_27017/pid/mongod.pidnet: port: 27017 bindIp: 127.0.0.1192.168.81.2102.6. Start MongoDB1. Start MongoDB [root @ mongodb-1 ~] # cd / data/mongodb_ cluster [root @ mongodb-1 / data/mongodb_cluster] #. / mongodb/bin/mongod-f mongodb_27017/conf/mongodb.yml about to fork child process, waiting until server is ready for connections.forked process: 73550child process started successfully, parent exiting2. View the process and port [root@mongodb-1 / data/mongodb_cluster] # ps aux | grep Mongo [root @ mongodb-1 / data/mongodb_cluster] # netstat-lnpt | grep mongo
2.7. How to turn off MongoDB
You can shut down MongoDB by adding a-shutdown after the startup command.
There are two ways to turn off MongoDB
1. Command line shuts down MongoDB [root @ mongodb-1 ~] # cd / data/mongodb_ cluster [root @ mongodb-1 / data/mongodb_cluster] #. / mongodb/bin/mongod-f mongodb_27017/conf/mongodb.yml-- shutdownkilling process with pid: 735502. Interactively shut down MongoDB [mongodb-1] $mongo > use adminswitched to db admin > db.shutdownServer () to view the process and port [root@mongodb-1 / data/mongodb_cluster] # ps aux | grep Mongo [root @ mongodb-1 / data/mongodb_cluster] # netstat-lnpt | grep mongo2.8. Log in to MongoDB
Login to MongoDB requires the use of the mongo command
1. Start MongoDB [root @ mongodb-1 ~] # cd / data/mongodb_ cluster [root @ mongodb-1 / data/mongodb_cluster] #. / mongodb/bin/mongod-f mongodb_27017/conf/mongodb.yml 2. Log in to MongoDB [root @ mongodb-1 / data/mongodb_cluster] #. / mongodb/bin/mongo
There will be some warning messages after logging in, and we will optimize them in 3.
3. Optimize MongoDB warning message 3.1. Optimize startup user warning
Warning content: 2021-02-13T10:44:47.832+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user, which is not recommended.
This warning prompts us to try not to start directly with root, we need to start with ordinary users.
Idea: create an ordinary user, authorize the deployment directory of MongoDB to the ordinary user, and start it with the ordinary user.
1. Close MongoDB [root @ mongodb-1 / data/mongodb_cluster] #. / mongodb/bin/mongod-f mongodb_27017/conf/mongodb.yml-- shutdown2. Create user [root@mongodb-1 ~] # useradd Mongo [root @ mongodb-1 ~] # echo "123456" | passwd-- stdin mongo3. Weight [root@mongodb-1] # chown-R mongo.mongo / data/mongodb_cluster/4. Log in to the ordinary user and configure the environment variable [root@mongodb-1 ~] # su-Mongo [Mongo @ mongodb-1 ~] $vim .bashrcexport PATH=/data/mongodb_cluster/mongodb/bin/:$ path [mongo @ mongodb-1 ~] $source .bashrc5. Start MongoDB [mongodb-1 @ mongo] $mongod-f / data/mongodb_cluster/mongodb_27017/conf/mongodb.yml about to fork child process, waiting until server is ready for connections.forked process: 73835child process started successfully, parent exiting6. Log in to MongoDB [mongodb-1 @ mongo ~] $mongo
The warning message available to the startup user has disappeared.
3.2. Optimize large memory page warning
Alarm content: * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.
* * We suggest setting it to 'never'
* * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.
* * We suggest setting it to 'never'
This is due to the fact that always,MongoDB is set up in large memory. Never is recommended.
3.2.1. Permanently close large memory pages
Official document: https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
1. Prepare the init script [root@mongodb-1 ~] # vim / etcbind init.dqqqquli transparenttransparentWhishugepagesinit.Bingray Basil script # BEGIN INIT INFO# Provides: disable-transparent-hugepages# Required-Start: $local_fs# Required-Stop:# X-Start-Before: mongod mongodb-mms-automation-agent# Default-Start: 2 34 "Default-Stop: 01" 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' | tee ${thp_path} / enabled > / dev/null unset thp_path;; esac2. Empower and add to boot [root@mongodb-1 ~] # chmod 755 / etc/init.d/disable-transparent-hugepages [root@mongodb-1 ~] # chkconfig-- add disable-transparent-hugepages [root@mongodb-1 ~] # chkconfig-- list | grep disa
3. Restart MongoDB [mongo @ mongodb-1 ~] $mongod-f / data/mongodb_cluster/mongodb_27017/conf/mongodb.yml-- shutdown [mongo @ mongodb-1 ~] $mongod-f / data/mongodb_cluster/mongodb_27017/conf/mongodb.yml 4. Log in to mongdo to see the warning [mongo@mongodb-1 ~] $mongo3.2.2. Temporarily close large memory page 1. Temporarily close the memory page [root@mongodb-1 ~] # echo "never" > / sys/kernel/mm/transparent_hugepage/ enabled [root @ mongodb-1 ~] # echo "never" > / sys/kernel/mm/transparent_hugepage/ defragility [root @ mongodb-1 ~] # cat / sys/kernel/mm/transparent_hugepage/enabled always madvise [root@mongodb-1 ~] # cat / sys/kernel/mm/transparent_hugepage/defrag always madvise [never] 2. Restart MongoDB [root @ mongodb-1 ~] # su-mongo [Mongo @ mongodb-1 ~] $mongod-f / data/mongodb_cluster/mongodb_27017/conf/mongodb.yml-- shutdownmongo @ mongodb-1 ~] $mongod-f / data/mongodb_cluster/mongodb_27017/conf/mongodb.yml3. Log in to MongoDB to view the alarm [mongo@mongodb-1 ~] $mongo
You can see that the large memory page warning has been resolved
3.3. Optimize limit warnin
Alarm content: * * WARNING: soft rlimits too low. Rlimits set to 15324 processes, 65535 files. Number of processes should be at least 32767.5: 0.5 times number of files.
The prompt is that the number of open files set by limt is too low.
1. Adjust limit (this method takes effect without restarting the machine) cat > / etc/profile
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.