溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

linux服務(wù)之mongodb

發(fā)布時(shí)間:2020-06-28 05:00:06 來源:網(wǎng)絡(luò) 閱讀:801 作者:devops_ 欄目:MongoDB數(shù)據(jù)庫



系統(tǒng)環(huán)境:

[root@mongodb ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@mongodb ~]# uname -a
Linux mongodb 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

開始安裝

[root@mongodb ~]# yum -y install openssl openssl-devel
[root@mongodb ~]# mkdir soft
[root@mongodb ~]# mkdir -p /opt/mongodb/data/
[root@mongodb ~]# mkdir -p /opt/mongodb/logs/
[root@mongodb ~]# cd soft/
[root@mongodb soft]# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz
[root@mongodb soft]# cd /usr/local/
[root@mongodb local]# mkdir mongodb
[root@mongodb local]# cd mongodb/
[root@mongodb mongodb]# mv /root/soft/mongodb-linux-x86_64-2.4.9.tgz .
[root@mongodb mongodb]# ls
mongodb-linux-x86_64-2.4.9.tgz
[root@mongodb mongodb]# tar xf mongodb-linux-x86_64-2.4.9.tgz
[root@mongodb mongodb]# mv mongodb-linux-x86_64-2.4.9/* .
[root@mongodb mongodb]# rm mongodb-linux-x86_64-2.4.9.tgz mongodb-linux-x86_64-2.4.9/ -rf
[root@mongodb mongodb]# ls
bin  GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES
[root@mongodb mongodb]# vim /etc/mongodb.cnf         mongodb配置文件
#configuration Options for MongoDB
#
# For More Information, Consider:
# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters
# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration
dbpath = /opt/mongodb/data/
logpath = /opt/mongodb/logs/mongodb.log
logappend = true
#bind_ip = 127.0.0.1
#port = 27017
fork = true
#auth = true
noauth = true
directoryperdb = true
journal = true
rest = false
[root@mongodb mongodb]# /usr/local/mongodb/bin/mongod --config /etc/mongodb.cnf            啟動(dòng)mongodb
warning: remove or comment out this line by starting it with '#', skipping now : rest = false
about to fork child process, waiting until server is ready for connections.
forked process: 5970
all output going to: /opt/mongodb/logs/mongodb.log
[root@mongodb ~]# tail -f /opt/mongodb/logs/mongodb.log  查看mongodb啟動(dòng)日志
Fri Apr  4 21:30:45.634 [websvr] admin web console waiting for connections on port 28017
Fri Apr  4 21:30:45.635 [initandlisten] waiting for connections on port 27017            啟動(dòng)成功
[root@mongodb ~]# netstat -tulnpan |grep mon                                             查詢監(jiān)聽端口
tcp        0      0 0.0.0.0:28017               0.0.0.0:*                   LISTEN      5970/mongod      
tcp        0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      5970/mongod  
[root@mongodb ~]# ps aux |grep mongod
root      5970  6.9  3.6 465848 37504 ?        Sl   21:29   0:17 /usr/local/mongodb/bin/mongod --config /etc/mongodb.cnf
root      5974  0.1  0.0 100944   576 pts/1    S+   21:29   0:00 tail -f /opt/mongodb/logs/mongodb.log
root      6007  0.0  0.0 103252   820 pts/2    S+   21:33   0:00 grep mongod
[root@mongodb ~]# kill -2 5970                                                          停止服務(wù)

我們來把mongodb封裝成一個(gè)啟動(dòng)腳本讓

[root@mongodb ~]# vim /etc/init.d/mongodb
#!/bin/bash
# chkconfig: 2345 97 15
# description: mongodb init script for Linux.
. /etc/init.d/functions
source /etc/bashrc
source /etc/profile
mongodb_HOME=/usr/local/mongodb/bin
export mongodb_HOME
start() {
/usr/local/mongodb/bin/mongod --config /etc/mongodb.cnf >> /dev/null
echo "start"
}
stop() {
echo "stop"
kill -2 `ps -C mongod -f | grep mongod |tr -s ' ' | cut -d ' ' -f 2`
sleep 5
}
case "$1" in
  start)
    start
        ;;
  stop)
    stop
        ;;
  restart)
    stop
    start
        ;;
  version)
        exec $mongodb_HOME/mongod --version
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|version}"
        exit 1
esac
[root@mongodb ~]# chmod +x /etc/init.d/mongodb
[root@mongodb ~]# /etc/init.d/mongodb start
[root@mongodb ~]# cd /usr/local/mongodb/bin/
[root@mongodb bin]# ./mongo
MongoDB shell version: 2.4.9
connecting to: test
>
已經(jīng)成功連進(jìn)來了
[root@mongodb ~]# /etc/init.d/mongodb version
db version v2.4.9
Fri Apr  4 21:35:44.926 git version: 52fe0d21959e32a5bdbecdc62057db386e4e029c
[root@mongodb ~]#  netstat -tulnpan |grep mon
tcp        0      0 0.0.0.0:28017               0.0.0.0:*                   LISTEN      6024/mongod      
tcp        0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      6024/mongod 
[root@mongodb ~]# /etc/init.d/mongodb stop
stop
[root@mongodb ~]# netstat -tulnpan |grep mon
[root@mongodb ~]# chkconfig mongodb on

開機(jī)自己啟動(dòng)


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI