单片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/


相关内容

热门资讯

我来教教您“微竞棋牌.有挂吗?... 有 亲,根据资深记者爆料微竞棋牌是可以开挂的,确实有挂(咨询软件无需打开...
最新引进“发财麻将.有没有挂?... 您好:发财麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游戏...
【第一资讯】“上海敲麻.真的有... 网上科普关于“上海敲麻有没有挂”话题很是火热,小编也是针对上海敲麻作*弊开挂的方法以及开挂对应的知识...
今日重大发现“369河南麻将.... 有 亲,根据资深记者爆料369河南麻将是可以开挂的,确实有挂(咨询软件无...
重磅消息“云圈丰城麻将.辅助器... 重磅消息“云圈丰城麻将.辅助器?”太坑了果然有挂您好,云圈丰城麻将这个游戏其实有挂的,确实是有挂的,...
今日重磅消息“德扑之星.究竟有... 网上科普关于“德扑之星有没有挂”话题很是火热,小编也是针对德扑之星作*弊开挂的方法以及开挂对应的知识...
迈向自动驾驶:地平线技术生态大... 时代奔涌,风聚成潮。中国智能驾驶产业在经历了技术验证与场景探索后,正步入以“规模化商用”为核心命题的...
玩家最新攻略“大金牙麻将.有挂... 有 亲,根据资深记者爆料大金牙麻将是可以开挂的,确实有挂(咨询软件无需打...
终于懂了“九酷牛牛.开挂器?”... 终于懂了“九酷牛牛.开挂器?”确实真的有挂您好,九酷牛牛这个游戏其实有挂的,确实是有挂的,需要了解加...
终于懂了“欢乐时光.开挂神器?... 网上科普关于“欢乐时光有没有挂”话题很是火热,小编也是针对欢乐时光作*弊开挂的方法以及开挂对应的知识...