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

Detailed record of mongodb 3.2.5 installation process

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

2016-10-19 mongodb 3.2.5 installation

1 prepare to install the media

Download the installation media:

For the installation of mongodb, I usually use the binary package. The yum source connected to the external network cannot be configured in the internal network.

The official recommended download address for mongodb is: Downloads.mongodb.org

But in fact, this address, it is difficult to find the download table, normal download, you can usually use the following download address to choose to download:

What I download here is mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz corresponding to version 3.2.5.

If you have scripted the entire mongodb installation process, you can get the installation script and use the script to perform the installation

If you install manually, you can skip this step

The procedure for manually installing mongodb is generally as follows:

Mkdir-p / root/ {software,scripts}

Wget-Q http://ptmaster.test.cn/files/init/mongodb_install.sh-O / root/scripts/mongodb_install.sh

Cd / root/scripts

. / mongodb_install.sh-p 27117

2 add mongodb user and environment variables and modify system parameters

Groupadd mongodb

Useradd-g mongodb mongodb

Create a mongodb script directory

Mkdir-p / home/mongodb/scripts/

Modify directory permissions:

Chown-R mongodb:mongodb / home/mongodb/scripts/

Add the environment variable for the mongodb user to / etc/profile:

# MongoDB Environment Variables

Export PATH=$PATH:$HOME/bin:/usr/local/mongodb/bin:/home/mongodb/scripts/

The above variable takes effect:

Source / etc/profile

The actual operation process is as follows:

[root@yq-mapp-otadb248 etc] # id mongodbid: mongodb: No such user [root@yq-mapp-otadb248 etc] # [root@yq-mapp-otadb248 etc] # [root@yq-mapp-otadb248 etc] # groupadd mongodbuseradd-g mongodb mongodb [root@yq-mapp-otadb248 etc] # useradd-g mongodb mongodb [root@yq-mapp-otadb248 etc] # [root@yq-mapp-otadb248 etc] # [root@yq-mapp-otadb248 etc] # id mongodbuid=801 (mongodb) groups=801 (mongodb) [root@yq-mapp-otadb248 etc] #

Mongodb requires that hugepage be set to disabled, and the soft limit setting is large enough to be modified at the beginning or later.

Cat / etc/security/limits.d/90-nproc.conf

Modify the following values in this file

* soft nproc 2048

Make sure that the value of soft nproc is at least half of the value of soft nofile

After modification, exit the current user, re-enter, and the settings will take effect.

Disable the value of hugepage:

# echo "never" > / sys/kernel/mm/transparent_hugepage/enabled

# echo "never" > / sys/kernel/mm/transparent_hugepage/defrag

Note: the above two warnings will not be modified or affect the installation process, and will be prompted later.

3. Install mongodb softwar

Upload and extract the software:

Cd / usr/local

Rz mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz

Tar-zxvf mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz

Ln-sv mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 / usr/local/mongodb

Modify file permissions:

Chown-R mongodb:mongodb mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8

Chown-R mongodb:mongodb / usr/local/mongodb

The actual operation process is as follows:

[root@yq-mapp-otadb248 src] # rz rz waiting to receive.Starting zmodem transfer. Press Ctrl+C to cancel.Transferring mongodb-linux-x86_64-rhel62-3.2.5.tar.gz... 66999 KB 16749 KB/sec 00:00:04 0 Errors [root@yq-mapp-otadb248 src] # lltotal 277792 mongodb-linux-x86_64-rhel62-v3.2-latest [root@yq-mapp-otadb248 src] # [root@yq-mapp] 1 root root 68607629 Oct 19 11:53 mongodb-linux-x86_64-rhel62- 3.2.5.tar.gz Murray RW Apr 19 2016 mongodb-linux-x86_64-rhel62-v3.2-latest [root@yq-mapp-otadb248 src] -otadb248 src] # tar-zxvf mongodb-linux-x86_64-rhel62-3.2.5.tar.gz mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongooplogmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongodmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongomongodb-linux-x86 _ 64-rhel62-3.2.5-20-g07e21d8/bin/mongofilesmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/bsondumpmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongorestoremongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongosmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongoexportmongodb-linux-x86_64-rhel62-3.2.5 -20-g07e21d8/bin/mongodumpmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongoimportmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongotopmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongostatmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongoperfmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/GNU-AGPL-3 .0Mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/MPL-2mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/READMEmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/THIRD-PARTY-NOTICES [root@yq-mapp-otadb248 src] # [root@yq-mapp-otadb248 src] # lltotal 277796drwxr-xr-x 3 root root 4096 Oct 19 11:54 mongodb-linux-x86_64-rhel62-3. Root root-1 root root 68607629 Oct 19 11:53 mongodb-linux-x86_64-rhel62- 3.2.5.tar.gzuki-1 root root 215848960 Apr 19 2016 mongodb-linux-x86_64-rhel62-v3.2-latest [root@yq-mapp-otadb248 src] # [root@yq-mapp-otadb248 src] # mv mongodb-linux-x86_64-rhel62- 3.2.5-20-g07e21d8. / [root@yq-mapp-otadb248 src] # cd.. [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # ln-sv mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 / usr/local/ mongodb` / usr/local/mongodb'-> `mongodb-linux-x86_64-rhel62-3.2.5-20licg07e21d8' [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # chown -R mongodb:mongodb mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 [root@yq-mapp-otadb248 local] # chown-R mongodb:mongodb / usr/local/mongodb [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # lltotal 52drwxr-xr-x. 2 root root 4096 Apr 24 2014 bindrwxr-xr-x. 2 root root 4096 Sep 23 2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23 2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23 2011 includedrwxr-xr-x. 2 root root 4096 Sep 23 2011 libdrwxr-xr-x. 3 root root 4096 Apr 25 2014 lib64drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexeclrwxrwxrwx 1 root root 25 Mar 6 2015 logstash- > / usr/local/logstash-1.4.2drwxrwxr-x 8 logstash logstash 4096 Jun 24 2014 logstash-1.4.2lrwxrwxrwx 1 mongodb mongodb 45 Oct 19 11:59 mongodb- > mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8drwxr-xr-x 3 mongodb mongodb 4096 Oct 19 11:54 mongodb-linux-x86_64-rhel62-3.2.5- 20-g07e21d8lrwxrwxrwx 1 root root 39 Apr 23 2014 mysql- > / usr/local/mysql-5.5.19-linux2.6-x86_64drwxr-xr-x 12 root mysql 4096 Apr 23 2014 mysql-5.5.19-linux2.6-x86_64drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbindrwxr-xr-x. 6 root root 4096 Apr 25 2014 sharedrwxr-xr-x. 2 root root 4096 Oct 19 11:54 src [root@yq-mapp-otadb248 local] #

4 directories and configuration files required to create an mongodb instance

The directory required to create the mongodb instance:

Mkdir-p / data/mongo_27117/ {db,log,tmp}

The directories and files required to create the mongodb instance configuration file:

Mkdir-p / etc/mongodb

Touch / etc/mongodb/mongo_27117.conf

Configure the startup parameters of mongodb as needed. My startup parameters are as follows:

Vim / etc/mongodb/mongo_27117.conf

Dbpath=/data/mongo_27117/dblogpath=/data/mongo_27117/log/mongo_27117.logpidfilepath = / data/mongo_27117/tmp/mongo_27117.pidstorageEngine = wiredTigerwiredTigerCacheSizeGB = 2syncdelay = 30wiredTigerCollectionBlockCompressor = zlibport=27117auth = true directoryperdb = trueoplogSize=2048logappend=truefork=true#rest=truejournal = truejournalCommitInterval = 50slowms = 200

Modify the permissions and groups of directories and files:

Chown-R mongodb:mongodb / data/mongo_27117/

Chown-R mongodb:mongodb / etc/mongodb

Verify that the directory and configuration files are ready:

Ls-l / data/mongo_27117/

Ls-l / etc/mongodb

Cat / etc/mongodb/mongo_27117.conf

The actual operation of this step is as follows:

[root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # mkdir-p / data/mongo_27117/ {db,log Tmp} [root@yq-mapp-otadb248 local] # mkdir-p / etc/mongodb [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # vim / etc/mongodb/mongo_27117.confdbpath=/data/mongo_27117/dblogpath=/data/mongo_27117/log/mongo_27117.logpidfilepath = / data/mongo_27117/tmp/mongo_27117.pidstorageEngine = wiredTigerwiredTigerCacheSizeGB = 2syncdelay = 30wiredTigerCollectionBlockCompressor = zlibport=27117auth = truedirectoryperdb = trueoplogSize=2048logappend=truefork=true#rest=truejournal = truejournalCommitInterval = 50slowms = 200 [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # chown-R mongodb:mongodb / data/mongo_27117/ [root @ yq-mapp-otadb248 local] # chown-R mongodb:mongodb / etc/mongodb [root@yq-mapp-otadb248 local] # ls-l / data/mongo_27117/total 12drwxr-xr-x 2 mongodb mongodb 4096 Oct 19 12:02 dbdrwxr-xr-x 2 mongodb mongodb 4096 Oct 19 12:02 logdrwxr-xr-x 2 mongodb mongodb 4096 Oct 19 12: 02 tmp [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # ls-l / etc/mongodbtotal 4Murray rwkashi Oct-1 mongodb mongodb 392 Oct 19 12:05 mongo_ 27117.confession [root @ yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # cat / etc/mongodb/mongo_27117.confdbpath=/data/mongo_27117/dblogpath=/data/mongo_27117/log/mongo_ 27117.logpidfilepath = / data/mongo_27117/tmp/mongo_27117.pidstorageEngine = wiredTigerwiredTigerCacheSizeGB = 2syncdelay = 30wiredTigerCollectionBlockCompressor = zlibport=27117auth = true directoryperdb = trueoplogSize=2048logappend=truefork=true#rest=truejournal = truejournalCommitInterval = 50slowms = 200

5. Start the mongodb instance and change the administrator password

Start the mongodb service using the following command:

/ usr/local/mongodb/bin/mongod-- config / etc/mongodb/mongo_27117.conf

Confirm the password, the administrator password of mongodb, you can set it according to their own rules:

Echo $MONGODB_ROOT_PASS

Mongodb_020248_Pass

To change the administrator password, note that mongodb 3.2 grants three roles to admin, which is different from the previous version:

/ usr/local/mongodb/bin/mongo-- port=27117

Db.createUser ({user:'useradmin',pwd:'mongodb_020248_Pass',roles: [{"role": "clusterAdmin", "db": "admin"}, {"role": "userAdminAnyDatabase", "db": "admin"}, {"role": "dbAdminAnyDatabase", "db": "admin"}]})

Db.auth ("useradmin", "mongodb_020248_Pass")

Db.system.users.find ()

After generating the password, log in to mongo with the new user and password, and confirm the status:

/ usr/local/mongodb/bin/mongo-- port=27117-u useradmin-p mongodb_020248_Pass-- authenticationDatabase admin

The procedure for this step is as follows

[root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # ps-ef | grep mongoroot 32295 30115 0 12:12 pts/0 00:00:00 grep mongo [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # / usr/local/mongodb/bin/mongod-- config / etc/mongodb/mongo_27117.confabout to fork child process, waiting until server is ready for connections.forked process: 32321child process started successfully Parent exiting [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # ps-ef | grep mongoroot 32321 11 12:12 / 00:00:00 / usr/local/mongodb/bin/mongod-- config / etc/mongodb/mongo_27117.confroot 32359 30115 0 12:13 pts/0 00:00:00 grep mongo [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 Local] # / usr/local/mongodb/bin/mongo-- port=27117MongoDB shell version: 3.2.5-20-g07e21d8connecting to: 127.0.0.1:27117/testWelcome to the MongoDB shell.For interactive help Type "help" .for more comprehensive documentation, see http://docs.mongodb.org/Questions? Try the support group http://groups.google.com/group/mongodb-user>> use admin;switched to db admin > db.system.users.find () Error: error: {"ok": 0, "errmsg": "not authorized on admin to execute command {find:\" system.users\ ", filter: {}}", "code": 13} > > db.createUser ({user:'useradmin',pwd:'mongodb_020248_@JJMatch',roles: [{"role": "clusterAdmin", "db": "admin"}, {"role": "userAdminAnyDatabase" "db": "admin"}, {"role": "dbAdminAnyDatabase", "db": "admin"}]}) Successfully added user: {"user": "useradmin", "roles": [{"role": "clusterAdmin" "db": "admin"}, {"role": "userAdminAnyDatabase", "db": "admin"}, {"role": "dbAdminAnyDatabase" "db": "admin"}] > > db.system.users.find () Error: error: {"ok": 0, "errmsg": "not authorized on admin to execute command {find:\" system.users\ ", filter: {}}", "code": 13} > > db.auth ("useradmin", "mongodb_020248_@JJMatch") 1 > > db.system.users.find () {"_ id": "admin.useradmin", "user": "useradmin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000, "salt": "6hLxUniver d97hStimyfoN47QTmXQ =", "storedKey": "B0PqwVs3GFKIHQyQ6mBp1MA370 =", "serverKey": "xK53AKKAvFCdn5rsEtij5QB9RtU="}}, "roles": [{"role": "clusterAdmin") "db": "admin"}, {"role": "userAdminAnyDatabase", "db": "admin"}, {"role": "dbAdminAnyDatabase" "db": "admin"}} > [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # / usr/local/mongodb/bin/mongo-- port=27117-u useradmin-p mongodb_020248_@JJMatch-- authenticationDatabase adminMongoDB shell version: 3.2.5-20-g07e21d8connecting to: 127.0.0.1:27117/testServer has startup warnings:2016-10-19T12:12:59.096+0800 I CONTROL [initandlisten] 2016-10-19T12: 12WARNING: The server was started without specifying a-- bind_ip2016-10-19T12:12:59.096+0800 I CONTROL [initandlisten] * * and listens for connections on all available network interfaces.2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: You are running this process as the root user Which is not recommended.2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] 2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] 2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2016-10-19T12:12:59 .097 + 0800 I CONTROL [initandlisten] 2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] 2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: soft rlimits too low. Rlimits set to 2048 processes, 8192 files. Number of processes should be at least 4096: 0.5 times number of files.2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] > > use admin;switched to db admin > > db.system.users.find () {"_ id": "admin.useradmin", "user": "useradmin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000, "salt": "6hLxUniver d97hStimyfoN47QTmXQ =", "storedKey": "B0PqwVs3GFKIHQyQ6mBp1MA370 =", "serverKey": "xK53AKKAvFCdn5rsEtij5QB9RtU="}}, "roles": [{"role": "clusterAdmin") "db": "admin"}, {"role": "userAdminAnyDatabase", "db": "admin"}, {"role": "dbAdminAnyDatabase", "db": "admin"} > >

6. Create the business account required for the application

Create an admin / admin user with the permission to create your own user and database, and modify the password business by yourself:

Db.createUser ({user:'admin',pwd:'admin',roles: [{role:'userAdminAnyDatabase',db:'admin'}, {role:'dbAdminAnyDatabase',db:'admin'}]})

Verify the login of the business account:

/ usr/local/mongodb/bin/mongo-- port=27117-u admin-p admin-- authenticationDatabase admin

The actual operation of this step is as follows:

> db.system.users.find () .pretty () {"_ id": "admin.useradmin", "user": "useradmin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000 "salt": "6hLxamp d97hSignoryfoN47QTmXQQ =", "storedKey": "B0PqwVs3GFKIHQyQ6mBp1MA370 =", "serverKey": "xK53AKKAvFCdn5rsEtij5QB9RtU="}}, "roles": [{"role": "clusterAdmin" "db": "admin"}, {"role": "userAdminAnyDatabase", "db": "admin"}, {"role": "dbAdminAnyDatabase" "db": "admin"}} {"_ id": "admin.admin", "user": "admin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000 "salt": "snlJe16a2PX3dSwxnOsfAw==", "storedKey": "VOoX1e7F0tOme6YuR+iyMLuEWK8=", "serverKey": "aSlpI7TzlyJ5Ccbd8GoptNB8khk="}, "roles": [{"role": "userAdminAnyDatabase" "db": "admin"}, {"role": "dbAdminAnyDatabase" "db": "admin"}} > > ^ Cbye [root@yq-mapp-otadb248 local] # [root@yq-mapp-otadb248 local] # / usr/local/mongodb/bin/mongo-- port=27117-u admin-p admin-- authenticationDatabase adminMongoDB shell version: 3.2.5-20-g07e21d8connecting to: 127.0.0.1:27117/test > > show dbsadmin 0.000GBlocal 0.000GB > >

7. Alarm processing at startup

During mongodb startup, warnings are sometimes prompted, and two common types of warnings are handled as follows:

Warning 1:

Tip:

2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: soft rlimits too low. Rlimits set to 2048 processes, 8192 files. Number of processes should be at least 4096: 0.5 times number of files.

Reference: http://blog.csdn.net/kk185800961/article/details/45613267

The way to handle it, according to the prompt, change the processes value from the current 2048 to 4096 or higher.

Ps-ef | grep mongod

Cat / proc/32321/limits

Cat / etc/security/limits.d/90-nproc.conf

Vim / etc/security/limits.d/90-nproc.conf

The actual operation of this step is as follows:

[root@yq-mapp-otadb248 limits.d] # [root@yq-mapp-otadb248 limits.d] # cat / etc/security/limits.d/90-nproc.conf# 20160621 limit??#* soft nproc 51200 * hardnproc 51200 * soft nproc 2048 * hardnproc 16384 * Soft nofile 8192 * hard nofile 8192 * soft stack 8192 * hard stack 8192 * soft memlock unlimited* hard memlock unlimited [root@yq-mapp-otadb248 limits.d] # vim / etc/security/limits.d/90-nproc.conf # 20160621 * soft nproc 51200 * hard nproc 51200 * soft nproc 8192 * hard nproc 16384 [root@yq-mapp-otadb248 ~] # [root@yq-mapp-otadb248 ~] # ulimt-a-bash: ulimt: command not found [root@yq-mapp-otadb248] # ulimit-acore file size (blocks -c) 0data seg size (kbytes,-d) unlimitedscheduling priority (- e) 0file size (blocks,-f) unlimitedpending signals (- I) 30422max locked memory (kbytes,-l) unlimitedmax memory size (kbytes,-m) unlimitedopen files (- n) 8192pipe 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) 8192virtual memory (kbytes,-v) unlimitedfile locks (- x) unlimited

Warning 2:

2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.

2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'

2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten]

2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.

2016-10-19T12:12:59.097+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'

Confirm:

Cat / sys/kernel/mm/transparent_hugepage/enabled

Cat / sys/kernel/mm/transparent_hugepage/defrag

Deal with:

Echo "never" > / sys/kernel/mm/transparent_hugepage/enabled

Echo "never" > / sys/kernel/mm/transparent_hugepage/defrag

The actual operation of this step is as follows:

[root@yq-mapp-otadb248 limits.d] # cat / sys/kernel/mm/transparent_hugepage/ enabled [always] madvise never [root@yq-mapp-otadb248 limits.d] # cat / sys/kernel/mm/transparent_hugepage/ defragility [always] madvise never [root@yq-mapp-otadb248 limits.d] # [root@yq-mapp-otadb248 limits.d] # echo "never" > / sys/kernel/mm/transparent_hugepage/ enabled [root @ yq-mapp-otadb248 limits.d] # echo " Never "> / sys/kernel/mm/transparent_hugepage/ defragmentary [root @ yq-mapp-otadb248 limits.d] # [root@yq-mapp-otadb248 limits.d] # cat / sys/kernel/mm/transparent_hugepage/enabledalways madvise [never] [root@yq-mapp-otadb248 limits.d] # cat / sys/kernel/mm/transparent_hugepage/defragalways madvise [never] [root@yq-mapp-otadb248 limits.d] # [root@yq-mapp-otadb248 limits.d] #

8 create a mongodb instance management script

To facilitate starting and stopping mongodb instances, you can first create a startup script for mongodb, stop the script, and then create a service script in the / etc/init.d/ directory, so that you can use service for instance management.

Script 1: start the script:

Vim / home/mongodb/scripts/mongodb_start.sh

#! / bin/sh# the scripts is used to start mongodb instance with port 27117.# created by zhaofx on 20161019.echo-n "Starting MongoDB port 27117..." / usr/local/mongodb/bin/mongod-- config / etc/mongodb/mongo_27117.conf &

Script 2: stop the script:

Vim / home/mongodb/scripts/mongodb_stop.sh

#! / bin/bash# the scripts is used to stop mongodb instance with port 27117.# created by zhaofx on 20161019.echo-n "Stopping MongoDB port 27117" pid= `ps-o pid,command ax | grep mongod | awk'! / awk/ & &! / grep/ {print $1}'`; if ["${pid}"! = "]; then kill-2 ${pid}; fi

Script 3: service script:

Vim / etc/init.d/mongodb

#! / bin/sh# the scripts is used to mange mongodb service with linux service type.# created by zhaofx on 20161019.PATH=/usr/local/mongodb/bin:/sbin:/bin:/usr/sbin:/usr/binNAME=mongodbstart () {/ home/mongodb/scripts/mongodb_start.sh} stop () {/ home/mongodb/scripts/mongodb_stop.sh} test-x $DAEMON | | exit 0set-ecase "$1" in start) start Stop) stop;; *) N=/etc/init.d/$NAME echo "Usage: $N {start | stop}" > & 2 exit 1;; esacexit 0

Modify the group of the script and add execution permissions:

Chown-R mongodb:mongodb / home/mongodb/scripts/chown mongodb:mongodb / etc/init.d/mongodbchmod + x / home/mongodb/scripts/mongodb_start.shchmod + x / home/mongodb/scripts/mongodb_stop.shchmod + x / etc/init.d/mongodb

Finally, the procedure for executing the service to start and stop the mongodb instance is:

[root@yq-mapp-otadb248 ~] # [root@yq-mapp-otadb248 ~] # service mongodb stopStopping MongoDB port 27117 [root@yq-mapp-otadb248 ~] # [root@yq-mapp-otadb248 ~] # service mongodb startStarting MongoDB port 27117 [root@yq-mapp-otadb248 ~] about to fork child process, waiting until server is ready for connections.forked process: 36088child process started successfully, parent exiting [root@yq-mapp-otadb248 ~] #

Detailed record of mongodb 3.2.5 installation process-END

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