0
点赞
收藏
分享

微信扫一扫

【MongoDB】在 CentOS 7.5 安装 MongoDB 4.2

火热如冰 2023-08-31 阅读 73

[root@node01 ~]# vim /etc/yum.repos.d/mongodb-org-4.2.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

[root@node01 ~]# yum install -y mongodb-org

[root@node01 ~]# rpm -qa | grep mongodb-org
mongodb-org-shell-4.2.24-1.el7.x86_64
mongodb-org-mongos-4.2.24-1.el7.x86_64
mongodb-org-server-4.2.24-1.el7.x86_64
mongodb-org-tools-4.2.24-1.el7.x86_64
mongodb-org-4.2.24-1.el7.x86_64

[root@node01 ~]# vim /etc/mongod.conf
net:
  port: 27017
  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

[root@node01 ~]# vim /usr/lib/systemd/system/mongod.service
ExecStartPre=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled"
ExecStartPre=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"

[root@node01 ~]# systemctl daemon-reload
[root@node01 ~]# systemctl start mongod 
[root@node01 ~]# systemctl status mongod

[root@node01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@node01 ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]

[root@node01 ~]# mongo
MongoDB shell version v4.2.24
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0e3041c6-5d7a-40fa-8189-81abf1113b43") }
MongoDB server version: 4.2.24
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
Server has startup warnings: 
2023-08-31T13:22:02.639+0800 I  CONTROL  [initandlisten] 
2023-08-31T13:22:02.639+0800 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2023-08-31T13:22:02.639+0800 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2023-08-31T13:22:02.639+0800 I  CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> db.disableFreeMonitoring()
> use admin
switched to db admin
> db.createUser({user:"root",pwd:"abcd.1234",roles:[{role:"root",db:"admin"}]})

[root@node01 ~]# vim /etc/mongod.conf
security:
  authorization: enabled
  
[root@node01 ~]# systemctl restart mongod  
[root@node01 ~]# mongo -u "root" -p "abcd.1234" --authenticationDatabase "admin"
MongoDB shell version v4.2.24
connecting to: mongodb://127.0.0.1:27017/?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("701aff9d-7832-40df-a39d-a7056f3c3a3a") }
MongoDB server version: 4.2.24
> db.version()
4.2.24
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB

举报

相关推荐

0 条评论