1. 程式人生 > 實用技巧 >【MongoDB Database】install mongodb 4.0 on centos 7.5

【MongoDB Database】install mongodb 4.0 on centos 7.5

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

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

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

[root@wallet01 ~]# vim /etc/mongod.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
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@king01 ~]# cat >> /etc/security/limits.conf <<EOF
mongod          soft   nofile         64000
mongod          hard   nofile         64000
mongod          soft   nproc          64000
mongod          hard   nproc          64000
EOF

[root@wallet01 ~]# systemctl start mongod
[root@wallet01 ~]# systemctl status mongod

[root@wallet01 ~]# netstat -tunlp | grep mongod
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      26575/mongod

[root@wallet01 ~]# mongo
MongoDB shell version v4.0.21
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5ba67546-7fd7-4393-83e5-694242fad3d6") }
MongoDB server version: 4.0.21
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] 
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] 
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] 
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] 
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-12-14T13:44:59.381+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-12-14T13:44:59.381+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()
> exit
bye
關閉THP [root@wallet01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never [root@wallet01 ~]# cat /sys/kernel/mm/transparent_hugepage/defrag [always] madvise never [root@wallet01 ~]# vim /etc/systemd/system/disable-thp.service [Unit] Description=Disable Transparent Huge Pages (THP) [Service] Type=simple ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag" [Install] WantedBy=multi-user.target [root@wallet01 ~]# systemctl daemon-reload [root@wallet01 ~]# systemctl start disable-thp [root@wallet01 ~]# systemctl enable disable-thp [root@wallet01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never] [root@wallet01 ~]# cat /sys/kernel/mm/transparent_hugepage/defrag always madvise [never] [root@wallet01 ~]# systemctl restart mongod
建立超級使用者 [root@wallet ~]# mongo MongoDB shell version v4.0.21 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("6ba59cf2-09ac-4719-9efd-e203f10bb448") } MongoDB server version: 4.0.21 Server has startup warnings: 2020-12-14T13:50:12.445+0800 I CONTROL [initandlisten] 2020-12-14T13:50:12.446+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2020-12-14T13:50:12.446+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2020-12-14T13:50:12.446+0800 I CONTROL [initandlisten] > use admin switched to db admin > db.createUser ({ user: "root", pwd: "abcd@1234",roles: ["root"] }) Successfully added user: { "user" : "root", "roles" : [ "root" ] } > exit bye 啟用身份驗證 [root@wallet01 ~]# vim /etc/mongod.conf security: authorization: enabled [root@wallet01 ~]# systemctl restart mongod [root@wallet01 ~]# mongo -u "root" -p "abcd@1234" --authenticationDatabase "admin" MongoDB shell version v4.0.21 connecting to: mongodb://127.0.0.1:27017/?authSource=admin&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("fe1b32c4-1d8d-42dc-b486-a2bcbc48c5c6") } MongoDB server version: 4.0.21 >