云服务器环境安装与配置:mongodb

版权声明: https://blog.csdn.net/maoyuanming0806/article/details/83247616

本文详细介绍单机mongodb安装

环境

  • Centos7

安装

1、下载MongoDB(64位)

wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz

2、安装MongoDB

安装到/usr/local

  • 解压tar -zvxf mongodb-linux-x86_64-2.4.9.tgz
  • 重命名mv mongodb-linux-x86_64-2.4.9 /usr/local/mongodb
  • 手动创建数据存储文件夹
[root@mym local]# cd mongodb
[root@mym mongodb]# mkdir db
[root@mym mongodb]# mkdir logs
  • 配置

vi mongodb.conf


dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/logs/mongodb.log
port=27017
fork=true
nohttpinterface=true

配置说明:

  • dbpath:mongod进程存储数据目录,此配置仅对mongod> 进程有效。默认值为:/data/db
  • logpath:日志目录
  • port:mongod侦听端口,默认值为27017
  • fork:后台方式运行mongodb
  • nohttpinterface:关闭http接口

3、重新绑定mongodb的配置文件地址和IP

/usr/local/mongodb/bin/mongod --bind_ip 192.168.31.201 -f /usr/local/mongodb/bin/mongodb.conf

注意上面是一条命令

4、加入开机启动mongodb

vi /etc/rc.d/rc.local
把第3步的命令加到该文件中即可

5、连接进入mongodb

[root@mym bin]# /usr/local/mongodb/bin/mongo 192.168.31.201
MongoDB shell version: 2.4.9
connecting to: 192.168.31.201/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
Server has startup warnings: 
Mon Oct 22 01:04:43.077 [initandlisten] 
Mon Oct 22 01:04:43.077 [initandlisten] ** WARNING: Readahead for /usr/local/mongodb/db is set to 4096KB
Mon Oct 22 01:04:43.077 [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less
Mon Oct 22 01:04:43.077 [initandlisten] **          http://dochub.mongodb.org/core/readahead
> show dbs  # 查看库
local   0.078125GB
> db.version() # 查看版本
2.4.9

6、客户端连接测试

使用Robomongo进行连接测试
下载地址:https://robomongo.org/

猜你喜欢

转载自blog.csdn.net/maoyuanming0806/article/details/83247616