CentOS安装mongodb

2021/12/17 19:50:21

本文主要是介绍CentOS安装mongodb,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

安装参考:https://www.cnblogs.com/pfnie/articles/6759105.html

mkdir /data1/mongo/log -p

tar -zxvf /data1/software/mongodb-linux-x86_64-3.4.2.tgz /usr/local/

mv /usr/local/mongodb-linux-x86_64-3.4.2 /usr/local/mongodb

mkdir /usr/local/mongodb/etc

vi /usr/local/mongodb/etc/mongodb.conf,内容如下:

dbpath=/data1/mongodb
logpath=/data1/mongodb/log/mongodb.log
logappend=true
port=27017
fork=true
auth=true
pidfilepath=/usr/local/mongodb/mongo.pid
replSet=dsj_dbtest01
#keyFile=/usr/local/mongodb/etc/mongo.pass

ln /usr/local/mongodb/bin/mongod /usr/bin/mongod

启动mongodb:mongod -f /usr/local/mongodb/etc/mongodb.conf

验证:访问 http://mongodb_ip:27017/ 可以打开则表示成功

 添加开机启动项:

vim /etc/init.d/mongod,内容如下:

ulimit -SHn 655350
#!/bin/sh
# chkconfig: - 64 36
# description:mongod
case $1 in
start)
/usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/etc/mongodb.conf
;;

stop)
/usr/local/mongodb/bin/mongod  --config /usr/local/mongodb/etc/mongodb.conf  --shutdown
;;
status)
/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.stats()"
;;
restart)

/usr/local/mongodb/bin/mongod  --config /usr/local/mongodb/etc/mongodb.conf  --shutdown


/usr/local/mongodb/bin/mongod --maxConns 20000  --config /usr/local/mongodb/etc/mongodb.conf

;;
esac

chmod +x /etc/init.d/mongod

chkconfig mongod on

service mongod start

 



这篇关于CentOS安装mongodb的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程