CentOS6.5安装MongoDB
1.先准备好mongodb-linux-x86_64-3.4.6.tgz,
可以起去官网下载,也可以直接下载我我从官网下载下来的3.4.6版本.下载链接地址:http://pan.baidu.com/s/1dFgWb0t
2.开始安装:
首先现在/usr/local/目录下创建mongodb目录:
mkdir /usr/local/mongodb
将准备好的tgz文件移动到上面创建的mongodb目录下:
mv mongodb-linux-x86_64-3.4.6.tgz /usr/local/mongodb/
解压:
tar -xvzf mongodb-linux-x86_64-3.4.6.tgz
删除压缩包:
rm mongodb-linux-x86_64-3.4.6.tgz
创建mongodb默认存放数据的目录:(在绝对路径下创建/data/db)
mkdir -p /data/db
开放27017访问端口权限
-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
重启防火墙
service iptables restart
3.运行MongoDB服务器,进入bin目录下,执行:
./mongod
在终端将会打印以下信息:
[[email protected] bin]# ./mongod
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] MongoDB starting : pid=1827 port=27017 dbpath=/data/db 64-bit host=centos-server-yzr
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] db version v3.4.6
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] allocator: tcmalloc
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] modules: none
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] build environment:
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] distarch: x86_64
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-07-18T18:16:33.918+0800 I CONTROL [initandlisten] options: {}
2017-07-18T18:16:33.948+0800 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten]
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1396M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.345+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-07-18T18:16:34.346+0800 I NETWORK [thread1] waiting for connections on port 27017
4.开启另外一个终端,进入mongodb下的bin目录下,执行:
./mongo
在终端会打印如下信息:
[[email protected] bin]# ./mongo
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.6
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:
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten]
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-07-18T18:16:33.949+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-07-18T18:16:34.342+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten]
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-07-18T18:16:34.343+0800 I CONTROL [initandlisten]
> show dbs
admin 0.000GB
local 0.000GB
> db.version()
3.4.6
> use post
switched to db post
> show dbs
admin 0.000GB
local 0.000GB
testdb 0.000GB
> use testdb
switched to db testdb
> db.createCollection("mycoll")
{ "ok" : 1 }
> db.mycoll.insert({"name":"ZYR"})
WriteResult({ "nInserted" : 1 })
> show collections
mycoll
>
5.在windows中使用MongoVUE连接MongoDB服务器
其中,Name属性可以随意填写,启动时在没有配置密码验证的配置,所以不要求登录账号密码就可以直接连接了.