mongodb 3.2.5安装详细过程
1.准备安装介质
安装介质下载:
mongodb的安装方式,我通常使用二进制包的方式,内网不能配置连接外网的yum源;
官方建议的mongodb下载地址为:Downloads.mongodb.org
但实际上,这个地址,很难找到下载表,正常下载,通常可以用下面的下载地址选择下载:
https://www.mongodb.org/dl/linux/x86_64
我这里下载的是:3.2.5版本对应的mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz
如果将整个mongodb安装过程已经编写了脚本,可以获取安装脚本,用脚本执行安装;
如果手动安装,则可跳过此步;
手工安装mongodb的脚步的执行过程,一般如下:
mkdir-p/root/{software,scripts} wget-qhttp://ptmaster.test.cn/files/init/mongodb_install.sh-O/root/scripts/mongodb_install.sh cd/root/scripts ./mongodb_install.sh-p27117
2.添加mongodb用户和环境变量,修改系统设置
添加用户:
groupaddmongodb useradd-gmongodbmongodb
创建mongodb脚本目录
mkdir-p/home/mongodb/scripts/
修改目录权限:
chown-Rmongodb:mongodb/home/mongodb/scripts/
在/etc/profile中添加mongodb用户的环境变量:
#MongoDBEnvironmentVariables exportPATH=$PATH:$HOME/bin:/usr/local/mongodb/bin:/home/mongodb/scripts/
是上面的变量生效:
source/etc/profile
实际操作过程如下:
[root@yq-mapp-otadb248etc]#idmongodb id:mongodb:Nosuchuser [root@yq-mapp-otadb248etc]# [root@yq-mapp-otadb248etc]# [root@yq-mapp-otadb248etc]#groupaddmongodb useradd-gmongodbmongodb[root@yq-mapp-otadb248etc]#useradd-gmongodbmongodb [root@yq-mapp-otadb248etc]# [root@yq-mapp-otadb248etc]# [root@yq-mapp-otadb248etc]#idmongodb uid=801(mongodb)gid=801(mongodb)groups=801(mongodb) [root@yq-mapp-otadb248etc]#
mongodb要求hugepage设置为禁用,softlimit设置足够大,可以在一开始修改,也可以到后面修改;
cat/etc/security/limits.d/90-nproc.conf
修改这个文件中下列的值
*softnproc2048
确保:softnproc的值至少是softnofile值的一半;
修改后,退出当前用户,重新进入一下,设置就可以生效了;
禁用hugepage的值:
#echo"never">/sys/kernel/mm/transparent_hugepage/enabled #echo"never">/sys/kernel/mm/transparent_hugepage/defrag
备注:上面两个警告,现在不修改也不影响安装过程,后面会提示。
3.安装mongodb软件
上传并解压软件:
cd/usr/local rzmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz tar-zxvfmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8.tgz ln-svmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8/usr/local/mongodb
修改文件权限:
chown-Rmongodb:mongodbmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 chown-Rmongodb:mongodb/usr/local/mongodb
实际操作过程如下:
[root@yq-mapp-otadb248src]#rz rzwaitingtoreceive. Startingzmodemtransfer.PressCtrl+Ctocancel. Transferringmongodb-linux-x86_64-rhel62-3.2.5.tar.gz... 100%66999KB16749KB/sec00:00:040Errors [root@yq-mapp-otadb248src]#ll total277792 -rw-r--r--1rootroot68607629Oct1911:53mongodb-linux-x86_64-rhel62-3.2.5.tar.gz -rw-r--r--1rootroot215848960Apr192016mongodb-linux-x86_64-rhel62-v3.2-latest [root@yq-mapp-otadb248src]# [root@yq-mapp-otadb248src]#tar-zxvfmongodb-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-otadb248src]# [root@yq-mapp-otadb248src]#ll total277796 drwxr-xr-x3rootroot4096Oct1911:54mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 -rw-r--r--1rootroot68607629Oct1911:53mongodb-linux-x86_64-rhel62-3.2.5.tar.gz -rw-r--r--1rootroot215848960Apr192016mongodb-linux-x86_64-rhel62-v3.2-latest [root@yq-mapp-otadb248src]# [root@yq-mapp-otadb248src]#mvmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8../ [root@yq-mapp-otadb248src]#cd.. [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#ln-svmongodb-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-otadb248local]# [root@yq-mapp-otadb248local]#chown-Rmongodb:mongodbmongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 [root@yq-mapp-otadb248local]#chown-Rmongodb:mongodb/usr/local/mongodb [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#ll total52 drwxr-xr-x.2rootroot4096Apr242014bin drwxr-xr-x.2rootroot4096Sep232011etc drwxr-xr-x.2rootroot4096Sep232011games drwxr-xr-x.2rootroot4096Sep232011include drwxr-xr-x.2rootroot4096Sep232011lib drwxr-xr-x.3rootroot4096Apr252014lib64 drwxr-xr-x.2rootroot4096Sep232011libexec lrwxrwxrwx1rootroot25Mar62015logstash->/usr/local/logstash-1.4.2 drwxrwxr-x8logstashlogstash4096Jun242014logstash-1.4.2 lrwxrwxrwx1mongodbmongodb45Oct1911:59mongodb->mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 drwxr-xr-x3mongodbmongodb4096Oct1911:54mongodb-linux-x86_64-rhel62-3.2.5-20-g07e21d8 lrwxrwxrwx1rootroot39Apr232014mysql->/usr/local/mysql-5.5.19-linux2.6-x86_64 drwxr-xr-x12rootmysql4096Apr232014mysql-5.5.19-linux2.6-x86_64 drwxr-xr-x.2rootroot4096Sep232011sbin drwxr-xr-x.6rootroot4096Apr252014share drwxr-xr-x.2rootroot4096Oct1911:54src [root@yq-mapp-otadb248local]#
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-Rmongodb:mongodb/data/mongo_27117/ chown-Rmongodb:mongodb/etc/mongodb
确认目录和配置文件都已经准备完毕:
ls-l/data/mongo_27117/ ls-l/etc/mongodb cat/etc/mongodb/mongo_27117.conf
该步骤实际操作过程如下:
[root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#mkdir-p/data/mongo_27117/{db,log,tmp} [root@yq-mapp-otadb248local]#mkdir-p/etc/mongodb [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#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-otadb248local]# [root@yq-mapp-otadb248local]#chown-Rmongodb:mongodb/data/mongo_27117/ [root@yq-mapp-otadb248local]#chown-Rmongodb:mongodb/etc/mongodb [root@yq-mapp-otadb248local]#ls-l/data/mongo_27117/ total12 drwxr-xr-x2mongodbmongodb4096Oct1912:02db drwxr-xr-x2mongodbmongodb4096Oct1912:02log drwxr-xr-x2mongodbmongodb4096Oct1912:02tmp [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#ls-l/etc/mongodb total4 -rw-r--r--1mongodbmongodb392Oct1912:05mongo_27117.conf [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#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
修改管理员密码,注意mongodb3.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-uuseradmin-pmongodb_020248_Pass--authenticationDatabaseadmin
该步骤操作过程如下;
[root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#ps-ef|grepmongo root3229530115012:12pts/000:00:00grepmongo [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#/usr/local/mongodb/bin/mongod--config/etc/mongodb/mongo_27117.conf abouttoforkchildprocess,waitinguntilserverisreadyforconnections. forkedprocess:32321 childprocessstartedsuccessfully,parentexiting [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#ps-ef|grepmongo root323211112:12?00:00:00/usr/local/mongodb/bin/mongod--config/etc/mongodb/mongo_27117.conf root3235930115012:13pts/000:00:00grepmongo [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#/usr/local/mongodb/bin/mongo--port=27117 MongoDBshellversion:3.2.5-20-g07e21d8 connectingto:127.0.0.1:27117/test WelcometotheMongoDBshell. Forinteractivehelp,type"help". Formorecomprehensivedocumentation,see http://docs.mongodb.org/ Questions?Trythesupportgroup http://groups.google.com/group/mongodb-user > >useadmin; switchedtodbadmin >db.system.users.find(); Error:error:{ "ok":0, "errmsg":"notauthorizedonadmintoexecutecommand{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"}]}) Successfullyaddeduser:{ "user":"useradmin", "roles":[ { "role":"clusterAdmin", "db":"admin" }, { "role":"userAdminAnyDatabase", "db":"admin" }, { "role":"dbAdminAnyDatabase", "db":"admin" } ] } > >db.system.users.find(); Error:error:{ "ok":0, "errmsg":"notauthorizedonadmintoexecutecommand{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-otadb248local]# [root@yq-mapp-otadb248local]#/usr/local/mongodb/bin/mongo--port=27117-uuseradmin-pmongodb_020248_@JJMatch--authenticationDatabaseadmin MongoDBshellversion:3.2.5-20-g07e21d8 connectingto:127.0.0.1:27117/test Serverhasstartupwarnings: 2016-10-19T12:12:59.096+0800ICONTROL[initandlisten] 2016-10-19T12:12:59.096+0800ICONTROL[initandlisten]**WARNING:Theserverwasstartedwithoutspecifyinga--bind_ip 2016-10-19T12:12:59.096+0800ICONTROL[initandlisten]**andlistensforconnectionsonallavailablenetworkinterfaces. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:Youarerunningthisprocessastherootuser,whichisnotrecommended. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten] 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten] 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/enabledis'always'. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never' 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten] 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/defragis'always'. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never' 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten] 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:softrlimitstoolow.rlimitssetto2048processes,8192files.Numberofprocessesshouldbeatleast4096:0.5timesnumberoffiles. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten] > >useadmin; switchedtodbadmin > >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-uadmin-padmin--authenticationDatabaseadmin
该步骤,实际操作过程如下:
> >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-otadb248local]# [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]# [root@yq-mapp-otadb248local]#/usr/local/mongodb/bin/mongo--port=27117-uadmin-padmin--authenticationDatabaseadmin MongoDBshellversion:3.2.5-20-g07e21d8 connectingto:127.0.0.1:27117/test > >showdbs admin0.000GB local0.000GB > >
7.实例启动时的报警处理
在mongodb启动过程中,有时会提示一些警告,其中常见的两类警告处理过程如下:
警告1:
提示:
2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:softrlimitstoolow.rlimitssetto2048processes,8192files.Numberofprocessesshouldbeatleast4096:0.5timesnumberoffiles.
处理方式,根据提示,将processes值,由现在的2048,修改为4096,甚至更高的值。
ps-ef|grepmongod cat/proc/32321/limits cat/etc/security/limits.d/90-nproc.conf vim/etc/security/limits.d/90-nproc.conf
该步骤实际操作过程如下:
[root@yq-mapp-otadb248limits.d]# [root@yq-mapp-otadb248limits.d]#cat/etc/security/limits.d/90-nproc.conf #20160621limit?? #*softnproc51200 #*hardnproc51200 *softnproc2048 *hardnproc16384 *softnofile8192 *hardnofile8192 *softstack8192 *hardstack8192 *softmemlockunlimited *hardmemlockunlimited [root@yq-mapp-otadb248limits.d]#vim/etc/security/limits.d/90-nproc.conf #20160621 #*softnproc51200 #*hardnproc51200 *softnproc8192 *hardnproc16384 [root@yq-mapp-otadb248~]# [root@yq-mapp-otadb248~]#ulimt-a -bash:ulimt:commandnotfound [root@yq-mapp-otadb248~]#ulimit-a corefilesize(blocks,-c)0 datasegsize(kbytes,-d)unlimited schedulingpriority(-e)0 filesize(blocks,-f)unlimited pendingsignals(-i)30422 maxlockedmemory(kbytes,-l)unlimited maxmemorysize(kbytes,-m)unlimited openfiles(-n)8192 pipesize(512bytes,-p)8 POSIXmessagequeues(bytes,-q)819200 real-timepriority(-r)0 stacksize(kbytes,-s)8192 cputime(seconds,-t)unlimited maxuserprocesses(-u)8192 virtualmemory(kbytes,-v)unlimited filelocks(-x)unlimited
警告2:
2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/enabledis'always'. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never' 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten] 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/defragis'always'. 2016-10-19T12:12:59.097+0800ICONTROL[initandlisten]**Wesuggestsettingitto'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-otadb248limits.d]#cat/sys/kernel/mm/transparent_hugepage/enabled [always]madvisenever [root@yq-mapp-otadb248limits.d]#cat/sys/kernel/mm/transparent_hugepage/defrag [always]madvisenever [root@yq-mapp-otadb248limits.d]# [root@yq-mapp-otadb248limits.d]#echo"never">/sys/kernel/mm/transparent_hugepage/enabled [root@yq-mapp-otadb248limits.d]#echo"never">/sys/kernel/mm/transparent_hugepage/defrag [root@yq-mapp-otadb248limits.d]# [root@yq-mapp-otadb248limits.d]#cat/sys/kernel/mm/transparent_hugepage/enabled alwaysmadvise[never] [root@yq-mapp-otadb248limits.d]#cat/sys/kernel/mm/transparent_hugepage/defrag alwaysmadvise[never] [root@yq-mapp-otadb248limits.d]# [root@yq-mapp-otadb248limits.d]#
8.创建mongodb实例服务管理脚本
为了方便对mongodb实例的启动和停止,可以先创建mongodb的启动脚本,停止脚本,然后在/etc/init.d/目录下创建一个服务脚本,这样就可以用service进行实例管理了。
脚本1:启动脚本:
vim/home/mongodb/scripts/mongodb_start.sh
#!/bin/sh #thescriptsisusedtostartmongodbinstancewithport27117. #createdbyzhaofxon20161019. echo-n"StartingMongoDBport27117..." /usr/local/mongodb/bin/mongod--config/etc/mongodb/mongo_27117.conf&
脚本二:停止脚本:
vim/home/mongodb/scripts/mongodb_stop.sh
#!/bin/bash #thescriptsisusedtostopmongodbinstancewithport27117. #createdbyzhaofxon20161019. echo-n"StoppingMongoDBport27117" pid=`ps-opid,commandax|grepmongod|awk'!/awk/&&!/grep/{print$1}'`; if["${pid}"!=""];then kill-2${pid}; fi
脚本三:服务脚本:
vim/etc/init.d/mongodb
vim/etc/init.d/mongodb #!/bin/sh #thescriptsisusedtomangemongodbservicewithlinuxservicetype. #createdbyzhaofxon20161019. 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||exit0 set-e case"$1"in start) start ;; stop) stop ;; *) N=/etc/init.d/$NAME echo"Usage:$N{start|stop}">&2 exit1 ;; esac exit0
修改脚本的属组,添加执行权限:
chown-Rmongodb:mongodb/home/mongodb/scripts/ chownmongodb: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~]#servicemongodbstop StoppingMongoDBport27117 [root@yq-mapp-otadb248~]# [root@yq-mapp-otadb248~]# [root@yq-mapp-otadb248~]# [root@yq-mapp-otadb248~]#servicemongodbstart StartingMongoDBport27117...[root@yq-mapp-otadb248~] abouttoforkchildprocess,waitinguntilserverisreadyforconnections. forkedprocess:36088 childprocessstartedsuccessfully,parentexiting [root@yq-mapp-otadb248~]#
以上所述是小编给大家介绍的mongodb3.2.5安装过程详细记录,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!