mongodb安装及开启oplog

tar xzvf mongodb-linux-x86_64-rhel70-4.4.13.tgz
tar xzvf mongodb-database-tools-rhel70-x86_64-100.7.3.tgz
mv mongodb-linux-x86_64-rhel70-4.4.13 /app/mongodb
mv mongodb-database-tools-rhel70-x86_64-100.7.3/bin/* /app/mongodb/bin/

vi /etc/profile

添加

export MONGODB_HOME=/app/MongoDB
export PATH=$PATH:$MONGODB_HOME/bin

source /etc/profile

cd /app/mongodb
mkdir data
mkdir data/db
mkdir etc
mkdir logs
cd etc
vi mongod.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
  path: /app/mongodb/logs/mongodb.log
# Where and how to store data.
storage:
#  dbPath: /var/lib/mongo
  dbPath: /app/mongodb/data/db
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo
  fork: true
  pidFilePath: /app/mongodb/master.pid
# network interfaces
net:
  port: 27117
  bindIp: 0.0.0.0


#security:
security:
  authorization: enabled
  keyFile: /app/mongodb/etc/mongodb-keyfile
  clusterAuthMode: keyFile
#operationProfiling:

#replication:
replication:
  replSetName: "rs1"
  oplogSizeMB: 100
#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

vi /etc/profile
export MONGODB_HOME=/app/mongodb
export PATH=$PATH:$MONGODB_HOME/bin

source /etc/profile

mongo生产ssl秘钥

openssl rand -base64 32 > mongodb-keyfile

chmod 400 mongodb-keyfile #不修改权限,启动会报错"errmsg":"permissions on /app/MongoDB/etc/mongodb-keyfile are too open"

启动mongo

/app/mongodb/bin/mongod -f /app/mongodb/etc/mongod.conf

登录

mongo --port 27117

配置节点信息

config = { _id: "rs1", members: [ {_id:0,host:"127.0.0.1:27117"} ] }
rs.initiate(config)

创建用户

db.createUser({user:"root",pwd:"123456",roles:["root"]})

    db.auth("root","123456")
show users;
show dbs
查看节点信息
 rs.status()

查看当前库的集合
show collections

 查看节点同步信息
 rs.printReplicationInfo()

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值