centos7下使用yum安装mongodb
2018-12-07 本文已影响6人
王帅199207
安装之前检查
- 检查系统是多少位主机,以便于添加对应的yum源
- 确保 SELINUX 是disable状态
## 检查系统
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服务(--auth 开启密码验证,设置好用户密码再添加)
mongo #启动mongo shell
# 先创建admin用户,再创建对应db的用户
> use dbname
> db.auth('username','pwd')
mongod --shutdown #关闭mongod服务