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()