標籤:echo shadow 成功 comm isa x86_64 server linux 安裝
安裝配置MongoDB資料庫
實驗環境:
系統內容:rhel6 x64 selinux and iptables disabled
一、安裝MongoDB
:
https://www.mongodb.com/download-center#community
[[email protected] ~]# ls
mongodb-linux-x86_64-rhel62-4.0.0
[[email protected] ~]# mv mongodb-linux-x86_64-rhel62-4.0.0/ /usr/local/mongodb #移動解壓檔案夾到MongoDB安裝目錄
[[email protected] ~]# mkdir -p /home/data/mongodb/mongodb_data #建立MongoDB資料庫存放路徑
[[email protected] ~]# mkdir -p /home/data/mongodb/mongodb_log #建立MongoDB資料庫日誌存放路徑
#啟動MongoDB
[[email protected] ~]# /usr/local/mongodb/bin/mongod --port 27017 --fork --dbpath=/home/data/mongodb/mongodb_data/ --logpath=/home/data/mongodb/mongodb_log/mongodb.log --logappend
查看連接埠
[[email protected] ~]# netstat -antlp #查看MongoDB是否啟動
[[email protected] ~]# cd /usr/local/mongodb/bin/
[[email protected] bin]# ./mongo #進入MongoDB資料庫控制台
> 2+3
5
> 2*3
6
>
> use admin #進入admin資料庫
switched to db admin
> db.shutdownServer() #關閉MongoDB資料庫
server should be down...
2018-07-22T21:25:17.131+0800 I NETWORK [js] trying reconnect to 127.0.0.1:27017 failed
2018-07-22T21:25:17.131+0800 I NETWORK [js] reconnect 127.0.0.1:27017 failed failed
> exit #退出
bye
[[email protected] bin]# netstat -antlp | grep :27017 已經關閉
[[email protected] bin]#
再次進入MongoDB資料庫控制台時如下報錯:
[[email protected] bin]# ./mongo
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-22T22:07:54.310+0800 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
[email protected]/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed
解決途徑:
(1) cd /usr/local/mongodb/bin
(2) ./mongod --dbpath=/home/data/mongodb/mongodb_data/
(3) 上一步路徑設定成功,但是不要關閉這個介面,需要重新開啟一個新的視窗來啟動mongo
(4)在另一個終端:cd /usr/local/mongodb/
./bin/mongo
做下面時,先關閉MongoDB資料庫
二、設定MongoDB資料庫
[[email protected] bin]# cd /usr/local/mongodb/ #進入MongoDB安裝目錄
[[email protected] mongodb]# vim mongodb.conf #編寫設定檔
port=27017 #連接埠號碼
dbpath=/home/data/mongodb/mongodb_data/ #資料庫路徑
logpath=/home/data/mongodb/mongodb_log/mongodb.log #日誌輸出檔案路徑
logappend=true #日誌輸出方式
[[email protected] ~]# cd /usr/local/mongodb/
[[email protected] bin]# pwd
/usr/local/mongodb/bin
[[email protected] bin]# ./mongod -f mongodb.conf
查看連接埠:
三、Linux下註冊mongodb服務
進入 /etc/init.d/ 目錄
[[email protected] bin]# cd /etc/init.d/
建立mongodb檔案
[[email protected] init.d]# vim mongodb
#!/bin/sh
#
# ### BEGIN INIT INFO
# Short-Description: mongodb
# Description: mongo db server
### END INIT INFO
PROGRAM=/usr/local/mongodb/bin/mongod
MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'`
test -x $PROGRAM || exit 0
case "$1" in
start)
ulimit -n 3000
echo "Starting MongoDB server"
$PROGRAM --fork --quiet -f /usr/local/mongodb/mongodb.conf
echo "Started MongoDB server"
;;
stop)
echo "Stopping MongoDB server"
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
echo "Stopped MongoDB server"
;;
status)
;;
*)
echo "Usage: mongodb {start|stop|status}"
exit 1
esac
exit 0
儲存完畢,在執行以下幾條命令即可:
[[email protected] init.d]# chmod +x mongodb
測試:
[[email protected] init.d]# /etc/init.d/mongodb start
[[email protected] init.d]# netstat -antlp | grep :27017
安裝配置MongoDB資料庫