《整理关于linux搭建mongodb服务供大家参考》要点:
本文介绍了整理关于linux搭建mongodb服务供大家参考,希望对您有用。如果有疑问,可以联系我们。
相关主题:非关系型数据库
Mongo DB是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式,备受当前IT从业人员的青睐.Mongo DB很好的实现了面向对象的思想,在Mongo DB中,每一条记录都是一个Document对象.Mongo DB最大的优势在于所有的数据持久操作都无需开发人员手动编写SQL语句,直接调用办法就可以轻松的实现CRUD操作.在这里介绍一下mongodb的安装办法
1.在/usr/local目录下面下载mongodb
[root@localhost ~]# cd /usr/local/[root@localhost ~]# cd /usr/local/wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
2.解压并创立数据库的存储及日志目录
[root@localhost local]# tar -zxvf mongodb-linux-x86_64-rhel62-3.0.7.tgz [root@localhost local]# mkdir -p mogodb/{data,logs}[root@localhost local]# cd mogodb/[root@localhost mogodb]# ls bin data GNU-AGPL-3.0 logs README THIRD-PARTY-NOTICES[root@localhost mogodb]# cd logs/[root@localhost logs]# touch mongodb.log
3.建立mongodb.conf配置文件,然后添加下面的内容指定db和log路径,设定端口号并保留退出
[root@localhost mogodb]# vi /usr/local/mongodb/bin/mongodb.confdbpath=/usr/local/mongodb/datalogpath=/usr/local/mongodb/logs/mongodb.logport=27017fork=truenohttpinterface=true
4.启动MongoDB
[root@localhost mongodb]# /usr/local/mongodb/bin/mongod --config /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
5.设置开机自启动MongoDB
[root@localhost mongodb]# echo "/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf" >> /etc/rc.local/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
6.进入Mongodb的shell模式
[root@localhost ~]# /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]
7.查看数据库列表,退出按ctrl+c
> show dbs local 0.078GB
8.关闭数据库(1)
[root@localhost 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
9.关闭数据库(2)
[root@localhost ~]# ps -ef |grep mongoroot 1505 1 0 18:37 ? 00:00:03 /usr/local/mongodb/bin/mongod --bind_ip localhost -f /usr/local/mongodb/bin/mongodb.confroot 1544 1324 0 18:45 pts/2 00:00:00 grep mongo[root@localhost ~]# kill 1505
请大家多多存眷我的头条号,谢谢大家了.
欢迎参与《整理关于linux搭建mongodb服务供大家参考》讨论,分享您的想法,维易PHP学院为您提供专业教程。
转载请注明本页网址:
http://www.vephp.com/jiaocheng/9595.html