mongodb 3.2.5 Installation details
- 2020-06-07 05:29:48
- OfStack
1. Prepare installation media
Installation media Download:
mongodb installation, I usually use base 2 package, the inner network can not be configured to connect to the external network yum source;
The official recommended download address for mongodb is: ES10en.mongodb.org
But in fact, this address, it is difficult to find the download table, normal download, usually can use the following download address select download:
https://www.mongodb.org/dl/linux/x86_64
I here to download: corresponding mongodb 3.2.5 version - linux - x86_64 - rhel62-3.2.5-20 - g07e21d8. tgz
If the entire mongodb installation process has been scripted, the installation script can be obtained and used to execute the installation;
If installed manually, you can skip this step;
Manually install the steps of mongodb 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 Settings
Add user:
groupadd mongodb
useradd -g mongodb mongodb
Create the mongodb script directory
mkdir -p /home/mongodb/scripts/
Modify directory permissions:
chown -R mongodb:mongodb /home/mongodb/scripts/
Add the mongodb user's environment variable in /etc/profile:
# MongoDB Environment Variables
export PATH=$PATH:$HOME/bin:/usr/local/mongodb/bin:/home/mongodb/scripts/
Is the above variable in effect:
source /etc/profile
The actual operation process is as follows:
[root@yq-mapp-otadb248 etc]# id mongodb
id: mongodb: No such user
[root@yq-mapp-otadb248 etc]#
[root@yq-mapp-otadb248 etc]#
[root@yq-mapp-otadb248 etc]# groupadd mongodb
useradd -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 mongodb
uid=801(mongodb) gid=801(mongodb) groups=801(mongodb)
[root@yq-mapp-otadb248 etc]#
mongodb requires hugepage to be disabled and soft limit to be large enough to start at 1 or go to the end;
cat /etc/security/limits.d/90-nproc.conf
Modify the following values in this file
* soft nproc 2048
Ensure that the value of soft nproc is at least half of the value of soft nofile;
After modification, exit the current user, re-enter 1, the Settings can be effective;
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. They will be prompted later.
3. Install mongodb
Upload and decompress 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:
groupadd mongodb
useradd -g mongodb mongodb
0
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...
100% 66999 KB 16749 KB/sec 00:00:04 0 Errors
[root@yq-mapp-otadb248 src]# ll
total 277792
-rw-r--r-- 1 root root 68607629 Oct 19 11:53 mongodb-linux-x86_64-rhel62-3.2.5.tar.gz
-rw-r--r-- 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]# 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/mongooplog
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongod
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongo
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongofiles
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/bsondump
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongorestore
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongos
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongoexport
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongodump
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongoimport
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongotop
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongostat
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/bin/mongoperf
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/GNU-AGPL-3.0
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/MPL-2
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/README
mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/THIRD-PARTY-NOTICES
[root@yq-mapp-otadb248 src]#
[root@yq-mapp-otadb248 src]# ll
total 277796
drwxr-xr-x 3 root root 4096 Oct 19 11:54 mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8
-rw-r--r-- 1 root root 68607629 Oct 19 11:53 mongodb-linux-x86_64-rhel62-3.2.5.tar.gz
-rw-r--r-- 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-20-g07e21d8'
[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]# ll
total 52
drwxr-xr-x. 2 root root 4096 Apr 24 2014 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 3 root root 4096 Apr 25 2014 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
lrwxrwxrwx 1 root root 25 Mar 6 2015 logstash -> /usr/local/logstash-1.4.2
drwxrwxr-x 8 logstash logstash 4096 Jun 24 2014 logstash-1.4.2
lrwxrwxrwx 1 mongodb mongodb 45 Oct 19 11:59 mongodb -> mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8
drwxr-xr-x 3 mongodb mongodb 4096 Oct 19 11:54 mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8
lrwxrwxrwx 1 root root 39 Apr 23 2014 mysql -> /usr/local/mysql-5.5.19-linux2.6-x86_64
drwxr-xr-x 12 root mysql 4096 Apr 23 2014 mysql-5.5.19-linux2.6-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 6 root root 4096 Apr 25 2014 share
drwxr-xr-x. 2 root root 4096 Oct 19 11:54 src
[root@yq-mapp-otadb248 local]#
4. The directories and configuration files required to create an instance of mongodb
Directories required to create mongodb instances:
mkdir -p /data/mongo_27117/{db,log,tmp}
Directories and files required to create the mongodb instance profile:
groupadd mongodb
useradd -g mongodb mongodb
3
The startup parameters of mongodb are configured as required. My startup parameters are configured as follows:
vim /etc/mongodb/mongo_27117.conf
groupadd mongodb
useradd -g mongodb mongodb
4
Modify the permissions and groups of directories, files:
groupadd mongodb
useradd -g mongodb mongodb
5
Verify that the directory and configuration file are ready:
groupadd mongodb
useradd -g mongodb mongodb
6
The actual operation procedure 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.conf
dbpath=/data/mongo_27117/db
logpath=/data/mongo_27117/log/mongo_27117.log
pidfilepath = /data/mongo_27117/tmp/mongo_27117.pid
storageEngine = wiredTiger
wiredTigerCacheSizeGB = 2
syncdelay = 30
wiredTigerCollectionBlockCompressor = zlib
port=27117
auth = true
directoryperdb = true
oplogSize=2048
logappend=true
fork=true
#rest=true
journal = true
journalCommitInterval = 50
slowms = 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 12
drwxr-xr-x 2 mongodb mongodb 4096 Oct 19 12:02 db
drwxr-xr-x 2 mongodb mongodb 4096 Oct 19 12:02 log
drwxr-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/mongodb
total 4
-rw-r--r-- 1 mongodb mongodb 392 Oct 19 12:05 mongo_27117.conf
[root@yq-mapp-otadb248 local]#
[root@yq-mapp-otadb248 local]# cat /etc/mongodb/mongo_27117.conf
dbpath=/data/mongo_27117/db
logpath=/data/mongo_27117/log/mongo_27117.log
pidfilepath = /data/mongo_27117/tmp/mongo_27117.pid
storageEngine = wiredTiger
wiredTigerCacheSizeGB = 2
syncdelay = 30
wiredTigerCollectionBlockCompressor = zlib
port=27117
auth = true
directoryperdb = true
oplogSize=2048
logappend=true
fork=true
#rest=true
journal = true
journalCommitInterval = 50
slowms = 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 password, mongodb administrator password, can be set according to the respective rules:
groupadd mongodb
useradd -g mongodb mongodb
9
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 the password is generated, login mongo using the new user and password to confirm the status:
/usr/local/mongodb/bin/mongo --port=27117 -u useradmin -p mongodb_020248_Pass --authenticationDatabase admin
The operation procedure of this step is as follows;
[root@yq-mapp-otadb248 local]#
[root@yq-mapp-otadb248 local]# ps -ef|grep mongo
root 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.conf
about to fork child process, waiting until server is ready for connections.
forked process: 32321
child process started successfully, parent exiting
[root@yq-mapp-otadb248 local]#
[root@yq-mapp-otadb248 local]# ps -ef|grep mongo
root 32321 1 1 12:12 ? 00:00:00 /usr/local/mongodb/bin/mongod --config /etc/mongodb/mongo_27117.conf
root 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=27117
MongoDB shell version: 3.2.5-20-g07e21d8
connecting to: 127.0.0.1:27117/test
Welcome 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" : "6hLx/d97hS+yfoN47QTmXQ==", "storedKey" : "B0PqwVs3GFKIHQyyQ6mBp1MA370=", "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 admin
MongoDB shell version: 3.2.5-20-g07e21d8
connecting to: 127.0.0.1:27117/test
Server has startup warnings:
2016-10-19T12:12:59.096+0800 I CONTROL [initandlisten]
2016-10-19T12:12:59.096+0800 I CONTROL [initandlisten] ** WARNING: The server was started without specifying a --bind_ip
2016-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" : "6hLx/d97hS+yfoN47QTmXQ==", "storedKey" : "B0PqwVs3GFKIHQyyQ6mBp1MA370=", "serverKey" : "xK53AKKAvFCdn5rsEtij5QB9RtU=" } }, "roles" : [ { "role" : "clusterAdmin", "db" : "admin" }, { "role" : "userAdminAnyDatabase", "db" : "admin" }, { "role" : "dbAdminAnyDatabase", "db" : "admin" } ]
>
>
6. Create a business account for the application
Create 1 admin/admin user, with permission to create users and database by yourself, and then modify the password service by yourself:
db.createUser({user:'admin',pwd:'admin',roles:[{role:'userAdminAnyDatabase',db:'admin'},{role:'dbAdminAnyDatabase',db:'admin'}]})
Verify business account login:
/usr/local/mongodb/bin/mongo --port=27117 -u admin -p admin --authenticationDatabase admin
The actual operation process 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" : "6hLx/d97hS+yfoN47QTmXQ==",
"storedKey" : "B0PqwVs3GFKIHQyyQ6mBp1MA370=",
"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"
}
]
}
>
> ^C
bye
[root@yq-mapp-otadb248 local]#
[root@yq-mapp-otadb248 local]#
[root@yq-mapp-otadb248 local]#
[root@yq-mapp-otadb248 local]# /usr/local/mongodb/bin/mongo --port=27117 -u admin -p admin --authenticationDatabase admin
MongoDB shell version: 3.2.5-20-g07e21d8
connecting to: 127.0.0.1:27117/test
>
> show dbs
admin 0.000GB
local 0.000GB
>
>
7. Alarm handling when the instance is started
During the startup of mongodb, 1 warning is sometimes prompted. Two common types of warning processing are 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.
According to the prompts, change the processes value from the current 2048 to 4096 or even 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 procedure 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
#* hard nproc 51200
* soft nproc 2048
* hard nproc 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 -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 30422
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 8192
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 8192
virtual memory (kbytes, -v) unlimited
file 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'
Confirmation:
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag
Processing:
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
The actual operation process 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/defrag
[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/defrag
[root@yq-mapp-otadb248 limits.d]#
[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/defrag
always madvise [never]
[root@yq-mapp-otadb248 limits.d]#
[root@yq-mapp-otadb248 limits.d]#
8. Create the mongodb instance service management script
For the convenience of the start and stop of mongodb instance, can create mongodb startup scripts, first stop scripts, and then in the/etc/init d scripts/directory to create a service, so that you can use service for instance management.
Script 1: Startup 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 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
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/bin
NAME=mongodb
start(){
/home/mongodb/scripts/mongodb_start.sh
}
stop(){
/home/mongodb/scripts/mongodb_stop.sh
}
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
start
;;
stop)
stop
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop}" >&2
exit 1
;;
esac
exit 0
Modify the group of the script to add execution permission:
chown -R mongodb:mongodb /home/mongodb/scripts/
chown mongodb:mongodb /etc/init.d/mongodb
chmod +x /home/mongodb/scripts/mongodb_start.sh
chmod +x /home/mongodb/scripts/mongodb_stop.sh
chmod +x /etc/init.d/mongodb
The final procedure for starting and stopping the mongodb instance is:
[root@yq-mapp-otadb248 ~]#
[root@yq-mapp-otadb248 ~]# service mongodb stop
Stopping MongoDB port 27117
[root@yq-mapp-otadb248 ~]#
[root@yq-mapp-otadb248 ~]#
[root@yq-mapp-otadb248 ~]#
[root@yq-mapp-otadb248 ~]# service mongodb start
Starting MongoDB port 27117 ... [root@yq-mapp-otadb248 ~]
about to fork child process, waiting until server is ready for connections.
forked process: 36088
child process started successfully, parent exiting
[root@yq-mapp-otadb248 ~]#