美文网首页
centos7.9下mongodb6.04安装使用

centos7.9下mongodb6.04安装使用

作者: xun2019 | 来源:发表于2023-03-05 11:20 被阅读0次

注意事项

mongodb5.0以上(包含5.0)需要服务器cpu支持avx,否则mongodb无法启动

下载安装包

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/6.0/x86_64/RPMS/mongodb-org-server-6.0.4-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/6.0/x86_64/RPMS/mongodb-org-mongos-6.0.4-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-shell-4.4.19-1.el7.x86_64.rpm
##工具包下载地址https://www.mongodb.com/try/download/bi-connector
wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel70-x86_64-100.7.0.tgz

使用yum执行安装

yum -y localinstall mongodb-org-mongos-6.0.4-1.el7.x86_64.rpm mongodb-org-server-6.0.4-1.el7.x86_64.rpm mongodb-org-shell-4.4.19-1.el7.x86_64.rpm

查看修改mongod服务配置

vi /usr/lib/systemd/system/mongod.service

相关配置如下

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /home/mongodb/data
ExecStartPre=/usr/bin/chown mongod:mongod /home/mongodb/data
ExecStartPre=/usr/bin/chmod 0755 /home/mongodb/data
PermissionsStartOnly=true
PIDFile=/home/mongodb/data/mongod.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings

[Install]

修改服务生效

systemctl daemon-reload

启动mongodb

systemctl enable mongod 
systemctl start mongod 

创建mongodb管理员root账户

mongo
use admin 
db.createUser({user:"root",pwd:"123456",roles:["root"]})

修改mognodb服务/etc/mongod.conf开启权限验证

[root@localhost]# cat /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: /home/mongodb/log/mongod.log

# Where and how to store data.
storage:
  dbPath: /home/mongodb/data
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  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.


security:
  authorization: enabled
#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

重启服务生效

systemctl restart mongod

导入数据库

mongorestore -d mydb --dir /home/my_user/mydb

相关文章

网友评论

      本文标题:centos7.9下mongodb6.04安装使用

      本文链接:https://www.haomeiwen.com/subject/fpmuldtx.html