1.加repo:
yum install https://repo.percona.com/centos/7/RPMS/noarch/percona-release-latest.noarch.rpm
2.安装3.6版本:
yum info Percona-Server-MongoDB-36-server
若安装mongodb4.0版本需要执行命令:
#percona-release enable psmdb-40 release
#yum install percona-server-mongodb
3.修改数据目录:
# mkdir -p /data/mongo/
# chown -R mongod:mongod /data/mongo/
# chmod -R 775 /data/mongo/
4.修改配置文件:
# cat /etc/mongod.conf
# mongod.conf, Percona Server for MongoDB
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /data/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
checkpointSizeMB: 1000
statisticsLogDelaySecs: 0
journalCompressor: snappy
directoryForIndexes: false
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
setParameter:
wiredTigerConcurrentReadTransactions: 128
wiredTigerConcurrentWriteTransactions: 128
systemLog:
destination: file
logAppend: true
path: /var/log/mongo/mongod.log
processManagement:
fork: true
pidFilePath: /tmp/mongod.pid
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
注意:
1.bindIp 由127.0.0.1修改为0.0.0.0
2.日志文件socket文件位置的修改。
3.数据存储的默认路径修改:/var/lib/mongodb -->/data/mongo
4.启动:
# systemctl start mongod
设置开机自动启动:
# systemctl enable mongod
5.删除服务:
#systemctl stop mongod
#yum remove percona-server-mongodb*
$ rm -rf /var/lib/mongodb
$ rm -f /etc/mongod.cnf
6.mongodb的关闭和启动:
/usr/bin/mongod -f /etc/mongod.conf
关闭:
1.kill -9 进程
缺点:
数据库直接关闭
数据丢失
数据文件容易损坏(需要进行修复)
2.systemctl stop mongod
3.shutdownServer()的方式:
> use admin
> db.shutdownServer()
4.命令方式:
mongod -f /etc/mongod.conf --shutdown
--附录:安装mongodb官方的版本:
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.6/x86_64/RPMS/mongodb-org-server-3.6.8-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.6/x86_64/RPMS/mongodb-org-mongos-3.6.8-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.6/x86_64/RPMS/mongodb-org-tools-3.6.8-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.6/x86_64/RPMS/mongodb-org-shell-3.6.8-1.el7.x86_64.rpm