前段時間做了數據分析,在Windows上配置了MongoDB沒有一點問題,結果在linux上配了下出了一些問題,現在就總結一波吧!
1、下載
下載網址
2、安裝過程
在下載保存的目錄下運行
#-C後面跟的是要解壓的路徑,記得先創建目錄
tar -zxvf mongodb-linux-x86_64-4.0.5.tgz -C /usr/local/mongoDB
#進入到解壓目錄
cd /usr/local/mongoDB
#重命名文件,隨便你命不命,只是重命名了方便一點
mv mongodb-linux-x86_64-4.0.5 mongodbserver
#進入安裝目錄
cd mongodbserver/
#創建各種配置目錄
[root@localhost mongodbserver]# mkdir data
[root@localhost mongodbserver]# mkdir logs
[root@localhost mongodbserver]# mkdir etc
#給logs與data文件配置權限,不然會報錯
[root@localhost mongodbserver]# chmod -R 777 data
[root@localhost mongodbserver]# chmod -R 777 logs
#在etc下創建配置文件mongodb.conf
[root@localhost mongodbserver]# cd etc
[root@localhost etc]# vim mongodb.conf
#在文件中插入以下內容,從英文意思來看這些配置的意義很明顯
#路徑一定要寫對,不然會報錯!
dbpath=/usr/local/mongoDB/mongodbserver/data
logpath=/usr/local/mongoDB/mongodbserver/logs/mongodb.log
port=27017
#以守護程序的方式啓用,即在後臺運行
fork=true
journal=false
storageEngine=mmapv1
#退出後配置系統文件profile
sudo vi /etc/profile
#在後面插入
export MONGODB_HOME=/usr/local/mongoDB/mongodbserver
export PATH=$PATH:$MONGODB_HOME/bin
#立即生效
source /etc/profile
#啓動服務
[root@localhost bin]# ./mongod --config /usr/local/mongoDB/mongodbserver/etc/mongodb.conf
#連接數據庫
[root@localhost bin]# ./mongo
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("19a53a4e-503e-44af-aee7-99953e527dfc") }
MongoDB server version: 4.0.5
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:
2019-01-24T10:46:36.934+0800 I STORAGE [initandlisten]
2019-01-24T10:46:36.934+0800 I STORAGE [initandlisten] ** WARNING: Support for MMAPV1 storage engine has been deprecated and will be
2019-01-24T10:46:36.934+0800 I STORAGE [initandlisten] ** removed in version 4.2. Please plan to migrate to the wiredTiger
2019-01-24T10:46:36.934+0800 I STORAGE [initandlisten] ** storage engine.
2019-01-24T10:46:36.934+0800 I STORAGE [initandlisten]
2019-01-24T10:46:36.944+0800 I STORAGE [initandlisten]
2019-01-24T10:46:36.944+0800 I STORAGE [initandlisten] ** WARNING: Readahead for /usr/local/mongoDB/mongodbserver/data is set to 4096KB
2019-01-24T10:46:36.944+0800 I STORAGE [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less
2019-01-24T10:46:36.944+0800 I STORAGE [initandlisten] ** http://dochub.mongodb.org/core/readahead
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten]
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten]
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten]
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten]
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-24T10:46:37.013+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-24T10:46:37.014+0800 I CONTROL [initandlisten]
2019-01-24T10:46:37.014+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-24T10:46:37.014+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-24T10:46:37.014+0800 I CONTROL [initandlisten]
> ^C
bye
服務啓動後會可能會出現各種錯誤,解決方案有人總結的很好,給個傳送門
注意事項:有可能其他的人的命名跟配置跟我的不一樣,所以要深刻理解這些參數配置的意思,比如我的data有的人可能命名爲dbs,都是用來存數據庫數據的。