centos下安裝mongodb


1.進入linux 服務器

2.進入/usr/local/下創建mongodb 文件

3.centos7下載mongodb文件

 wget  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.9.tgz

 

 

4.解壓文件

  tar -zxvf mongodb-linux-x86_64-rhel70-4.0.9.tgz

5.將文件拷貝到指定目錄

 mv mongodb-linux-x86_64-rhel70-4.0.9/*  /usr/local/mongodb

6.在mongodb 下創建logs,data,conf 文件夾

7.在logs下創建mongodb.log

touch mongodb.conf

8.在conf下創建mongodb.conf,配置文檔目錄

9.添加環境變量

進入bin/etc/中 添加環境變量(如果編輯profile是吧,可以打開 ls -a 查看隱藏文件,刪除.profile.swp這樣的文件)

10.需要設置生效

11.啟動mongodb服務

12.鏈接mongodb數據庫

13.關閉 db.shutdownServer(),或者killall mongod

14.mongodb 

cd  /etc/init.d

MongoDB設置為系統服務並且設置開機啟動

#!/bin/sh
#
#chkconfig: 2345 80 90
#description: mongodb

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf
}

stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf --shutdown
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

將代碼放入mongod中

chmod –R a+x mongod 設置執行權限

chkconfig --add mongod #加入系統服務

chkconfig mongodb on #開機啟動

 

shutdown -r重啟服務器

啟動mongodb service mongod start

service mongod stop 關閉

驗證是否啟動 lsof -i :28001

報錯:

    停止mongodb 運行重新運行

 

 

     systemctl daemon-reload

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM