yum安装mongoDB-4.4.2
安装mongodb的方法有很多,今天主要分享的是配置yum源,直接使用yum安装的方法。过程是参考官方的教程。
创建yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim mongodb-org-4.4.repo
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
yum安装
[root@localhost yum.repos.d]# yum install -y mongodb-org
启动服务
[root@localhost ~]# systemctl start mongod
如果报 Failed to start mogond.service: Unit not found.
那么就执行:
[root@localhost ~]# systemctl daemon-reload
#检查端口
[root@localhost ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 984/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1139/master
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 1683/mongod
tcp6 0 0 :::22 :::* LISTEN 984/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1139/master
进入mongodb
[root@localhost ~]# mongo
MongoDB shell version v4.4.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("488c70a0-9b56-429e-a6ee-72968b845b2c") }
MongoDB server version: 4.4.2
---
The server generated these startup warnings when booting:
2020-12-07T10:21:55.297+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2020-12-07T10:21:55.298+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2020-12-07T10:21:55.298+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
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
test
#默认处于test下
查看配置文件的内容
[root@localhost ~]# vim /etc/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: /var/log/mongodb/mongod.log
# Where and how to store data. #数据目录
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# 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 #端口配置和绑定IP
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
以上就是以yum的方式安装mongodb。