安裝之前檢查
- 檢查系統(tǒng)是多少位主機揩慕,以便于添加對應(yīng)的yum源
- 確保 SELINUX 是disable狀態(tài)
## 檢查系統(tǒng)
root@VM_0_9_centos $ uname -a
Linux VM_0_9_centos 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
## 禁止 selinux
root@VM_0_9_centos $ cat /etc/selinux/config |grep -v '#' |grep -i selinux
SELINUX=disabled
SELINUXTYPE=targeted
## 如果沒有則需要修改配置篙骡,并且重啟
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
添加yum源
vim /etc/yum.repos.d/mongodb-4.0.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
gpgcheck=0 #*** 這里可以修改 gpgcheck=0, 省去gpg驗證 ***
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
安裝mongodb
yum update
yum -y install mongodb-org mongodb-org-server
配置,啟動和使用 mongodb
配置:
mkdir /data/logs
mkdir /data/db
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: /data/logs
# Where and how to store data.
storage:
dbPath: /data/db
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.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
啟動和停止:
mongod --auth -f /etc/mongod.conf #啟動mongod服務(wù)(--auth 開啟密碼驗證啦逆,設(shè)置好用戶密碼再添加)
mongo #啟動mongo shell
# 先創(chuàng)建admin用戶,再創(chuàng)建對應(yīng)db的用戶
> use dbname
> db.auth('username','pwd')
mongod --shutdown #關(guān)閉mongod服務(wù)