Centos怎么設(shè)置mongodb自啟動(dòng)

小晨
490
2021-07-06 08:30:25
欄目: 云計(jì)算

Centos設(shè)置mongodb自啟動(dòng)的方法:1、打開Centos終端;2、安裝好mongodb;3、在Centos上新增一個(gè)sh腳本并放在mongodb根目錄下面的mongod_start.sh中;4、輸入“chmod 777 mongod_start.sh”命令為其設(shè)置777權(quán)限;5、輸入“vim /etc/rc.d/rc.local”命令打開/etc/rc.d/rc.local配置文件;6、最后在/etc/rc.d/rc.local配置文件中添加“chmod +x /etc/rc.d/rc.local”開機(jī)自啟動(dòng)代碼并保存修改即可。

Centos怎么設(shè)置mongodb自啟動(dòng)

具體操作步驟:

1、安裝MONGOD

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

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

mv mongodb-linux-x86_64-rhel70-4.2.5/ /usr/local/mongodb


mkdir -p /usr/local/mongodb/data

mkdir -p /usr/local/mongodb/logs


ln -s /usr/local/mongodb/bin/mongod mongod

ln -s /usr/local/mongodb/bin/mongo mongo

2、設(shè)置開機(jī)自動(dòng)啟動(dòng)

(1)新增sh腳本

新增sh腳本放在根目錄的shell下面mongod_start.sh

#!/bin/bash

# pkill -9 mongod;

/usr/local/mongodb/bin/mongod --shutdown --dbpath /usr/local/mongodb/data/;

nohup /usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/log.txt > /shell/mongod.log 2>&1 &

設(shè)置權(quán)限777

chmod 777 mongod_start.sh

2、添加腳本到開機(jī)自啟動(dòng)

vim /etc/rc.d/rc.local

文件后面追加

sh /shell/mongod_start.sh

chmod +x /etc/rc.d/rc.local

0