mongodb 二进制安装方法



MongoD单节点环境安装(Linux)

安装包

下载地址: (https://www.mongodb.com/download-center)

用户权限/目录
1.创建 dbuser用户
  useradd mongod

2.部署目录
mkdir -p /opt/local
chown -R mongod.root /opt/local
cd /opt/local

3.解压安装包
tar -xzvf mongodb-linux-x86_64-enterprise-SUSE11-3.2.7.tgz
mv mongodb-linux-x86_64-enterprise-suse11-3.2.7 mongodb
cd mongodb
mkdir conf data log


conf 作为配置文件目录 data 作为数据文件目录 log 作为日志文件目录

配置文件

# 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
  path: /mongo/data/mongod.log

# Where and how to store data.
storage:
  dbPath: /mongo/data
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /mongo/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27017
  bindIp: 172.16.6.65  # Listen to local interface only, comment to listen on all interfaces.


#security:

#operationProfiling:

replication:
  replSetName: rs0


#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:



其中启动端口为27017,将http管理界面关闭; slowOpThredsholdMs是慢操作检测的阈值,可以根据需要调整;

环境变量 vi /etc /profile
export MONGODB_HOME=/usr/local/mongodb
export PATH=$PATH:$MONGODB_HOME/bin


初始化
1.启动mongod,缺省状态下可匿名访问
mongod -f conf/mongodb.conf

2.连接 mongo
mongo --port 27017

3.初始化管理员
use admin
db.createUser({user:'admin',pwd:'admin@2016',roles:[{role:'clusterAdmin',db:'admin'},{role:'userAdminAnyDatabase',db:'admin'}]})

use appdb
db.createUser({user:'appuser',pwd:'appuser@2016',roles:[{role:'dbOwner',db:'appdb'}]})


分别创建了管理员用户和应用账户,之后将
4.重启 mongo,启用鉴权
pkill mongod
mongod -f conf/mongodb.conf -auth


此后连接mongo 则需要提供身份鉴权

常用命令

启动命令
mongod -f conf/mongodb.conf


停止命令
kill -2 `cat mongod.pid`
rm mongod.pid


检测端口
netstat -nlp |grep 27071


查看日志
tail -n200 -f log/mongodb.log


连接端口
./bin/mongo --port 10001  -u admin -p admin@2016 --authenticationDatabase=admin


监控命令
./bin/mongostat --port 27071  -u admin -p admin@2016 --authenticationDatabase=admin --discover -n 30 3



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值