单片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
--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/class="lazy" data-src/mongodb-class="lazy" data-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/class="lazy" data-src/mongodb-class="lazy" data-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/
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341