欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mongodb 3.2.5安装详细过程

程序员文章站 2022-06-23 19:26:36
1. 准备安装介质 安装介质下载: mongodb的安装方式,我通常使用二进制包的方式,内网不能配置连接外网的yum源; 官方建议的mongodb下载地址为: dow...

1. 准备安装介质

安装介质下载:

mongodb的安装方式,我通常使用二进制包的方式,内网不能配置连接外网的yum源;

官方建议的mongodb下载地址为: downloads.mongodb.org

但实际上,这个地址,很难找到下载表,正常下载,通常可以用下面的下载地址选择下载:

我这里下载的是: 3.2.5 版本对应的 mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz

如果将整个mongodb安装过程已经编写了脚本,可以获取安装脚本,用脚本执行安装;

如果手动安装,则可跳过此步;

手工安装mongodb的脚步的执行过程,一般如下:

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. 添加mongodb用户和环境变量,修改系统设置

添加用户:

groupadd mongodb 
useradd -g mongodb mongodb

创建mongodb脚本目录

mkdir -p /home/mongodb/scripts/

修改目录权限:

chown -r mongodb:mongodb /home/mongodb/scripts/

在 /etc/profile 中添加 mongodb 用户的环境变量:

# mongodb environment variables
export path=$path:$home/bin:/usr/local/mongodb/bin:/home/mongodb/scripts/

是上面的变量生效:

source /etc/profile

实际操作过程如下:

[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要求hugepage设置为禁用,soft limit设置足够大,可以在一开始修改,也可以到后面修改;

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

修改这个文件中下列的值

* soft nproc 2048

确保: soft nproc 的值至少是 soft nofile 值的一半;

修改后,退出当前用户,重新进入一下,设置就可以生效了;

禁用 hugepage 的值:

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

备注:上面两个警告,现在不修改也不影响安装过程,后面会提示。

3. 安装mongodb软件

上传并解压软件:

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

修改文件权限:

chown -r mongodb:mongodb mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8
chown -r mongodb:mongodb /usr/local/mongodb

实际操作过程如下:

[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. 创建mongodb实例所需的目录和配置文件

创建mongodb实例所需目录:

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

创建mongodb实例配置文件所需目录和文件:

mkdir -p /etc/mongodb
touch /etc/mongodb/mongo_27117.conf

根据需要配置mongodb的启动参数,我的启动参数配置内容如下:

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

修改目录、文件的权限和属组:

chown -r mongodb:mongodb /data/mongo_27117/
chown -r mongodb:mongodb /etc/mongodb

确认目录和配置文件都已经准备完毕:

ls -l /data/mongo_27117/
ls -l /etc/mongodb
cat /etc/mongodb/mongo_27117.conf

该步骤实际操作过程如下:

[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. 启动mongodb实例,修改管理员密码

使用下面的命令启动mongodb服务:

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

确认密码,mongodb的管理员密码,可以根据各自的规则设置:

echo $mongodb_root_pass
mongodb_020248_pass

修改管理员密码,注意 mongodb 3.2要对admin授予三个角色,这点与之前的版本不同:

/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();

生成密码后,使用新用户和密码登陆mongo,确认状态:

/usr/local/mongodb/bin/mongo --port=27117 -u useradmin -p mongodb_020248_pass --authenticationdatabase admin

该步骤操作过程如下;

[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. 为应用创建业务账号

创建一个 admin / admin 用户,具有可以自行创建用户和数据库的权限,密码业务自己再修改:

db.createuser({user:'admin',pwd:'admin',roles:[{role:'useradminanydatabase',db:'admin'},{role:'dbadminanydatabase',db:'admin'}]})

验证业务账号登陆:

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

该步骤,实际操作过程如下:

> 
> 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. 实例启动时的报警处理

在mongodb启动过程中,有时会提示一些警告,其中常见的两类警告处理过程如下:

警告1:

提示:

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.

处理方式,根据提示,将 processes 值,由现在的 2048,修改为4096,甚至更高的值。

ps -ef|grep mongod
cat /proc/32321/limits
cat /etc/security/limits.d/90-nproc.conf 
vim /etc/security/limits.d/90-nproc.conf

该步骤实际操作过程如下:

[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

警告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'

确认:

cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag

处理:

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

该步骤,实际操作过程如下:

[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. 创建mongodb实例服务管理脚本

为了方便对mongodb实例的启动和停止,可以先创建mongodb的启动脚本,停止脚本,然后在 /etc/init.d/ 目录下创建一个服务脚本,这样就可以用 service 进行实例管理了。

脚本1:启动脚本:

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 &

脚本二:停止脚本:

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

脚本三:服务脚本:

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

修改脚本的属组,添加执行权限:

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

最后服务启动和停止mongodb实例的过程为:

[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 ~]#

以上所述是小编给大家介绍的mongodb 3.2.5安装过程详细记录,希望对大家有所帮助