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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章