单片mongoDB
admin
2023-01-26 20:05:14
0

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/


相关内容

热门资讯

白宫发布《科学:新的黄金时代》... 据白宫7月21日消息,白宫科技政策办公室、管理与预算办公室联合发布《科学:新的黄金时代》报告。本次备...
民营商业火箭首次从长三角东海海... 北京时间7月22日10时54分,我国太原卫星发射中心在上海东部海域使用引力一号遥四运载火箭,将搭载的...
美威胁袭伊基础设施,伊朗军方:... △当地时间21日,船只在霍尔木兹海峡航行伊朗武装部队哈塔姆安比亚中央总部当地时间22日发布声明称,美...
扑翼机器人问世:像潜水鸟一样在... 潜鸟、海鸥、海鹦和海燕,是自然界中约100种既能飞行又能游泳的鸟类。这些潜水鸟能够俯冲入水追逐猎物,...
当科学家走进西部脑谷:这里有望... 7月22日,2026天府科学家创新发展大会暨成都科产融合对接活动锦江经开区脑机接口专场在锦江区成功举...
女子身份证丢失后名下出现“吸毒... 四川籍的庞女士定居浙江宁波多年,她怎么也没想到,因丢失身份证一事,竟让她陷入长达7年“自证清白”的困...
省农科院成功研发我省首个高粱全... 近日,记者从省农科院获悉,该院作物资源研究所、农业生物技术研究所联合石家庄博瑞迪生物,成功研制出省内...
消息称AMD与Anthropi... IT之家 7 月 22 日消息,据华尔街日报消息,AMD 与 Anthropic 达成了一项价值数百...
独家!苹果iPhone18系列... 7月22日,中国证券报记者从产业链人士处独家获悉,进入7月,苹果iPhone 18系列手机已在量产,...
29岁的党鑫蕊倒在广西泥泞山路... 7月11日晚一通叮嘱,成了父子最后的对话;几天后父亲在殡仪馆见到一身泥的儿子,才知道“他走得有多难。...