千家信息网

单片mongoDB

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,MongoDB:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-linux/#install-mongodb-community
千家信息网最后更新 2026年11月02日单片mongoDB

MongoDB:

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-linux/#install-mongodb-community-edition


一、下载安装

# curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.9.tgz

或

# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.9.tgz

# tar -xf mongodb-linux-x86_64-rhel62-3.2.9.tgz -C /opt/

# ln -s /opt/mongodb-linux-x86_64-rhel62-3.2.9/ /opt/mongodb

# cat >>/etc/profile <

PATH=$PATH:/opt/mongodb/bin

HERE

# source /etc/profile

# mkdir -p /opt/mongodb/{log,db,conf}


二;启动

# mongod --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /opt/mongodb/mongod.pid --dbpath /opt/mongodb/db --logpath /opt/mongodb/log/mongod.log --logappend --logRotate rename --timeStampFormat ctime

/** 可以加入/etc/rc.d/rc.local,以随操作系统重启时自启动 **/


/** 部分参数解释 **/

--fork #后台daemon运行

--bind_ip #监听IP地址列表,以逗号分隔

--port #监听端口,默认27017

--setParameter enableLocalhostAuthBypass=0 #所有接口都需要认证

--pidfilepath #pid文件

--dbpath #db存放路径

--logpath #日志文件

--config #配置文件

--auth #启用认证

--httpinterface #启用web接口

--rest #rest api

--jsonp #json api

/** 如果闲命令参数太多,可以指定配置文件 **/

WARNING

Ensure that the HTTP status interface, the REST API, and the JSON API are all disabled in production environments to prevent potential data exposure and vulnerability to attackers

root@master:~#netstat -tunlp|grep mongod

tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN 11896/mongod

tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 11896/mongod

默认监听端口,db端口为27017, web端口为28017

# vi /etc/sysconfig/iptables

-A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 28017 -j ACCEPT


三、关闭

# mongod --shutdown --dbpath /opt/mongod/db

还可以

命令行模式执行shutdown

# use admin

db.shutdownServer()

或

mongo admin --port 27017 --eval "db.shutdownServer()"


四、配置文件

默认的二进制包没有配置文件模板,可以从源码包内提取

# cp -rp /usr/local/src/mongodb-src-r3.2.9/rpm/mongod.conf /opt/mongodb/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

logRotate: rename

timeStampFormat: ctime

path: /opt/mongodb/log/mongod.log


# Where and how to store data.

storage:

dbPath: /opt/mongodb/db

journal:

enabled: true

# engine:

# mmapv1:

# wiredTiger:

# how the process runs

processManagement:

fork: true # fork and run in background

pidFilePath: /opt/mongodb/mongod.pid # location of pidfile


# network interfaces

net:

port: 27017

#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

http:

enabled: true

JSONPEnabled: true

RESTInterfaceEnabled: true

setParameter:

enableLocalhostAuthBypass: false


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

更多参数和解释请参看官方文档


五、 init管控启动脚本

# useradd -s /sbin/nologin -r mongod

# chown -R mongod: /opt/mongodb-linux-x86_64-rhel62-3.2.9

# cp -rp/usr/local/src/mongodb-src-r3.2.9/rpm/init.d-mongod /etc/init.d/mongod

 /** 模板仍可以从 源码包里面取 **/

# chmod +x /etc/init.d/mongod

# sed -i '/CONFIGFILE=/i MONGOD="/opt/mongodb/bin/mongod"' /etc/init.d/mongod

# sed -i '/CONFIGFILE=/s:/etc/mongod.conf:/opt/mongodb/conf/mongod.conf:g' /etc/init.d/mongod




六、修改内核参数

# cat >>/etc/rc.d/rc.local <

# echo never > /sys/kernel/mm/transparent_hugepage/enabled

# echo never > /sys/kernel/mm/transparent_hugepage/defrag

# HERE


七,重启服务访问;

# service mongod restart

http://IP:28017/


文件 参数 配置 端口 命令 监听 接口 模板 源码 解释 认证 操作系统 二进制 内核 后台 地址 官方 文档 日志 更多 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技工作委员会副主任毛军 互联网金融 科技金融 华宇互联网科技 广西拼得多互联网科技有限公司 科技赋能互联网健康 央行互联网金融科技公司 团飞科技与伯堂互联网服务平台 常德市电业局互联网科技部 栖莱科技互联网股份有限公司 厦门比较好的科技互联网公司 黑科技闪耀互联网之光 互联网科技公司实习生 西安小鹰速贷互联网科技有限公司 玉溪新华互联网科技好不好 朱啸虎曾投资哪些互联网科技企业 南博望互联网科技有限公司 中国互联网有什么科技 广州梦谷互联网科技有限公司领导 优雇互联网科技有限公司 科技美学互联网 艺术 盈实互联网科技 互联网金融 科技 互联网高科技企业 盛创互联网科技有限公司 互联网科技股午盘股票涨跌 西藏七维空间互联网科技有限公司 湖南一路畅行互联网科技 美国互联网科技实力 世界互联网科技成果奖 承德科技产业互联网平台
0