注意事項(xiàng)
mongodb5.0以上(包含5.0)需要服務(wù)器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執(zhí)行安裝
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服務(wù)配置
vi /usr/lib/systemd/system/mongod.service
相關(guān)配置如下
[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]
修改服務(wù)生效
systemctl daemon-reload
啟動mongodb
systemctl enable mongod
systemctl start mongod
創(chuàng)建mongodb管理員root賬戶
mongo
use admin
db.createUser({user:"root",pwd:"123456",roles:["root"]})
修改mognodb服務(wù)/etc/mongod.conf開啟權(quán)限驗(yàn)證
[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:
重啟服務(wù)生效
systemctl restart mongod
導(dǎo)入數(shù)據(jù)庫
mongorestore -d mydb --dir /home/my_user/mydb