Centos6.5下搭建Mongodb服务
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Centos6.5下搭建Mongodb服务,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3288字,纯文字阅读大概需要5分钟。
内容图文
![Centos6.5下搭建Mongodb服务](/upload/InfoBanner/zyjiaocheng/1120/aebd6047792a4d66a6cdfec7f6d50413.jpg)
1.系统版本
[root@test2 ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m
2.下载MongoDB 到/usr/loca/
[root@test2 ~]# cd /usr/local/cd /usr/local/ [root@test2 ~]# cd /usr/local/wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
3.解压并创建数据库的存储及日志目录:
[root@test2 local]# tar -zxvf mongodb-linux-x86_64-rhel62-3.0.7.tgz [root@test2 local]# mkdir -p mogodb/{data,logs} [root@test2 local]# cd mogodb/ [root@test2 mogodb]# ls bin data GNU-AGPL-3.0 logs README THIRD-PARTY-NOTICES [root@test2 mogodb]# cd logs/ [root@test2 logs]# touch mongodb.log
4.建立配置文件
[root@test2 mogodb]# vi /usr/local/mongodb/bin/mongodb.conf dbpath=/usr/local/mongodb/data logpath=/usr/local/mongodb/logs/mongodb.log port=27017 fork=true nohttpinterface=true
5.启动MongoDB
[root@test2 mongodb]# /usr/local/mongodb/bin/mongod --bind_ip localhost -f /usr/local/mongodb/bin/mongodb.conf about to fork child process, waiting until server is ready for connections. forked process: 1449 child process started successfully, parent exiting
6.设置开机自启动MongoDB
[root@test2 mongodb]# echo "/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf" /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
7.测试:
(1)进入Mongodb的shell模式:
[root@test2 ~]# /usr/local/mongodb/bin/mongo MongoDB shell version: 3.0.7 connecting to: test Server has startup warnings: 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always‘. 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never‘ 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always‘. 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never‘ 2015-11-11T18:26:02.022+0800 I CONTROL [initandlisten] >
(2)查看数据库列表
> show dbsshow dbs local 0.078GB
(3)查看数据库版本
> db.version();db.version(); 3.0.7
(4)关闭数据库
[root@test2 bin]# /usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/bin/mongodb.conf 2015-11-11T18:36:01.404+0800 I CONTROL log file "/usr/local/mongodb/logs/mongodb.log" exists; moved to "/usr/local/mongodb/logs/mongodb.log.2015-11-11T10-36-01". killing process with pid: 1449
或使用kill
[root@test2 ~]# ps -ef |grep mongo root 1505 1 0 18:37 ? 00:00:03 /usr/local/mongodb/bin/mongod --bind_ip localhost -f /usr/local/mongodb/bin/mongodb.conf root 1544 1324 0 18:45 pts/2 00:00:00 grep mongo [root@test2 ~]# kill 1505
注意:这个地方不能使用kill -9 pid,这样会导致数据丢失,同时mongodb还可能会报错。
如果使用kill -9 pid的方式关闭mongodb,并且mongodb不能正常启动,则需删除mongod.lock文件
[root@test2 bin]# kill rm -rf /usr/local/mongodb/data/mongod.lock
[ root@test2 bin]# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
本文借鉴 “doiido” 博客, http://doiido.blog.51cto.com/5503054/1562541
本文出自 “Mr-G运维知识库” 博客,请务必保留此出处http://xpstack.blog.51cto.com/2973026/1718925
原文:http://xpstack.blog.51cto.com/2973026/1718925
内容总结
以上是互联网集市为您收集整理的Centos6.5下搭建Mongodb服务全部内容,希望文章能够帮你解决Centos6.5下搭建Mongodb服务所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。