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
在終端將會列印以下資訊:
[root@centos-server-yzr 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
在終端會列印如下資訊:
[root@centos-server-yzr 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屬性可以隨意填寫,啟動時在沒有配置密碼驗證的配置,所以不要求登入帳號密碼就可以直接連接了.