温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

单片mongoDB

发布时间:2020-09-03 11:55:13 来源:网络 阅读:555 作者:蓝宫卫 栏目: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 <<HERE

 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 <<HERE

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

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

# HERE


七,重启服务访问;

# service mongod restart

http://IP:28017/


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI