安装
cd /etc/yum.repos.d
vim mongodb-org.repo
[mogodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
yum -y install mongodb-org
配置
vim /etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
# 修改ip
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
开机启动脚本
cd /etc/init.d
vim mongod
#! /bin/bash
# chkconfig: 2345 90 91
# description: Start and Stop mongodb
# processname: mongod
EXEC=/usr/bin/mongod
CONF=/etc/mongod.conf
LOCKFILE=/var/lock/subsys/mongod
RETVAL=0
case "$1" in
start)
echo -n $"Starting mongod: "
$EXEC -f $CONF
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
;;
stop)
echo -n $"Stopping mongod: "
$EXEC -f $CONF --shutdown
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
;;
restart)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/mongod {start|stop|restart}" >&2
exit 1
esac
运行权限
chkconfig --add mongod
加入开机启动
systemctl enable mongod
启动
service mongod start
停止
service mongod stop
重启
service mongod restart
卸载
# 停止服务
service mongod stop
# 删除安装的包
yum erase $(rpm -qa | grep mongodb-org)
# 删除数据和日志
rm -rf /var/log/mongodb
rm -rf /var/lib/mongo