Python數據分析及可視化實例之CentOS7.2+MongoDB V3.4 安裝
系列文章總目錄:Python數據分析及可視化實例目錄
我不是程序員,也不是設計師,我只是碰巧有一些想法和一台電腦。
I am not a designer nor a coder. Im just a guy with a point-of-view and a computer.Step1.配置 yum
vim /etc/yum.repos.d/MongoDB-org-3.4.repon
在其中輸入
[mongodb-org-3.4]nname=MongoDB Repositorynbaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/testing/x86_64/ngpgcheck=1nenabled=1 ngpgkey=https://www.mongodb.org/static/pgp/server-3.4.ascn
然後輸入如下命令進行安裝
sudo yum install -y mongodb-orgn
如果想要安裝其他版本的Mongodb可以點開參考鏈接裡面有更詳細的安裝指南。
服務管理
service mongod start #啟動nservice mongod stop #停止nservice mongod restart #重啟n
Step2.配置Mongodb
配置文件路徑: /etc/mongod.conf。
若要自己指定數據存儲位置和日誌的存儲位置,我們可以修改MongoDB的配置文件。
舉個例子:
若要將數據文件存儲在 /home/data/mongo
日誌文件存儲在 /home/data/log/mongodb.log
注意: 這兩個存儲的位置要給MongoDB足夠的許可權來操作,否則會報錯
則將配置文件對應部分修改,其他不變
# where to write logging data.nsystemLog:ndestination: filenlogAppend: truenpath: /home/data/log/mongod.logn# Where and how to store data.nstorage:ndbPath: /home/data/mongonjournal:nenabled: truen
然後,通過指定配置文件啟動MongoDB。
mongod -f /etc/mongod.confn
默認會在後台運行,出現信息
about to fork child process, waiting until server is ready for connections.
forked process: 10286
child process started successfully, parent exiting
如果沒有後台運行,可以檢查配置文件中
# how the process runs
processManagement:
fork: true # 這裡是不是 true
直接使用命令來後台運行MongoDB
mongod –fork –dbpath [dbpath] –logpath [logpath]n
這裡 [dbpath] 是數據文件夾的路徑,[logpath] 是日誌文件的路徑。
例如,還是上面的存儲位置,數據文件存儲在 /home/data/mongo日誌文件存儲在 /home/data/log/mongodb.logmongod –fork –dbpath /home/data/mongo –logpath /home/data/log/mongodb.log關閉後台運行Step3.終端運行
mongonuse adminndb.shutdownServer()n
提示:
啟動服務前,先查看一下埠是否被佔用,若被佔用可以添加 –port 參數來指定埠。
netstat -ap | grep [port]n
關閉後台運行的指定了其他埠的MongoDB,連接資料庫時也要加埠號。
mongo localhost:portn
Step4.消除警告
[root@yeayee.com ~]# mongo
MongoDB shell version v3.4.0
connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.4.0Server has startup warnings: 2016-12-13T15:46:47.201+0800 I STORAGE [initandlisten] 2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] 2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** WARNING: Youare running this process as the root user, which is not recommended.
2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] 2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] 2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is always.2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** We suggest setting it to never2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten] 2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is always.2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten] ** We suggest setting it to never2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten]消除警告
vi /etc/rc.localif test -f /sys/kernel/mm/transparent_hugepage/enabled; thenecho never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag; thenecho never > /sys/kernel/mm/transparent_hugepage/defragfiulimit -u 65535[root@yeayee.com ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@yeayee.com ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag停止服務:> use adminswitched to db admin> db.shutdownServer();server should be down...2016-12-13T16:22:14.996+0800 I NETWORK [main] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed2016-12-13T16:22:14.997+0800 W NETWORK [main] Failed to connect to 127.0.0.1:27017, reason: Connection refused2016-12-13T16:22:14.997+0800 I NETWORK [main] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed膠水語言博大精深,
本主只得一二為新人帶路,
老鳥可去另一專欄:Python中文社區
新手可查閱歷史目錄:
Python數據分析及可視化實例目錄
最後,別只收藏不關注哈
推薦閱讀: