1. 官方链接:
https://docs.mongodb.com/v4.4/tutorial/install-mongodb-enterprise-on-red-hat/
1、配置存储库。
创建一个/etc/yum.repos.d/mongodb-enterprise-4.4.repo
文件,以便您可以使用yum
以下命令直接安装 MongoDB 企业版:
[mongodb-enterprise-4.4] name=MongoDB Enterprise Repository baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.4/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
2、安装 MongoDB 企业包
sudo yum install -y mongodb-enterprise-4.4.10 mongodb-enterprise-server-4.4.10 mongodb-enterprise-shell-4.4.10 mongodb-enterprise-mongos-4.4.10 mongodb-enterprise-tools-4.4.10
2.2
启动: sudo systemctl start mongod
查看状态:sudo systemctl status mongod
开机启动: sudo systemctl enable mongod
关闭数据库:
mongo -> use admin -> db.shutdownServer()
pkill mongod
shell: mongo
[mongo@redhatB data]$ mongod --shutdown --dbpath /database/mongodb/data/
killing process with pid: 17747
备注:mongod 命令的 shutdown 选项能干净的关闭 MongoDB 服务。
3、数据和日志文件位置
/var/lib/mongo
/var/log/mongodb
4. 绑定地址设置:
配置文件位置: /etc/mongod.conf
配置项:
https://docs.mongodb.com/v4.4/reference/configuration-options/#mongodb-setting-net.bindIp
net.bindIp 来设置绑定ip
replication:
replSetName: "rs0"
要绑定到所有 IPv4 地址,请输入0.0.0.0
。
或执行命令: mongod --bind_ip_all
5. 副本集配置
https://docs.mongodb.com/v4.4/tutorial/deploy-replica-set/
统一副本集名称:
mongod --replSet rs0
绑定所有ip : mongod --replSet "rs0" --bind_ip 0.0.0.0
添加配置:
>rs.initiate( { _id : "rs0", members: [ { _id: 0, host: "192.168.59.196:27017" }, { _id: 1, host: "192.168.59.210:27017" }, { _id: 2, host: "192.168.59.102:27017" } ] })
6. 启动报错
ERROR: child process failed, exited with 14
参考:https://stackoverflow.com/questions/30476447/mongodb-error-child-process-failed-exited-with-error-number-14
with me I remove file: /tmp/mongodb-27017.sock then restart mongod