centos7.8 部署mongodb
1. 下载包
直接下载
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.28.tgz
官网下载
https://www.mongodb.com/try/download/community-kubernetes-operator
2. 解压包
tar xvf mongodb-linux-x86_64-rhel70-4.0.28.tgz -C /usr/local/
3. 重命名
cd /usr/local
mv mongodb-linux-x86_64 mongodb
4. 添加环境变量
cat /etc/profile
主要修改数据目录和日志目录,fork修改为true表示后台,认证先改为disabled
export PATH=$PATH:/usr/local/mongodb/bin
5. 编辑配置文件
cat /usr/local/mongodb/mongodb.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where and how to store data.
storage:
dbPath: /usr/local/mongodb/data/
journal:
enabled: true
directoryPerDB: false
# where to write logging data.
systemLog:
destination: file
quiet: false
logAppend: true
logRotate: reopen
path: /usr/local/mongodb/logs/mongodb.log
verbosity: 0
# network interfaces
net:
port: 27017
unixDomainSocket:
enabled: true
pathPrefix: /usr/local/mongodb/tmp
ipv6: false
bindIpAll: true
bindIp: 0.0.0.0
# replica set options
#replication:
#replSetName: replicaset
#enableMajorityReadConcern: true
# process management options
processManagement:
fork: true
pidFilePath: /usr/local/mongodb/tmp/mongodb.pid
# set parameter options
setParameter:
enableLocalhostAuthBypass: true
# security options
security:
authorization: disabled
#keyFile: replace_me
6. 创建普通用户
useradd mongodb
7. 创建目录
mkdir /usr/local/mongodb/data
mkdir /usr/local/mongodb/logs
mkdir /usr/local/mongodb/tmp
8. 赋予mongodb用户权限
chown -R mongodb. /usr/local/mongodb
9. 切换mongodb用户启动
su - mongodb
cd /usr/local/mongodb
mongod -f mongodb.conf
10. 设置密码
进入数据库设置密码
mongo命令
---
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()
---
>
创建账号
> use admin
> db.createUser({ user:'root',pwd:'Ictsoft+123',roles:[ { role:'root', db: 'admin'}]});
Successfully added user: {
"user" : "root",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
退出数据库修改配置文件
security:
authorization: enabled
#keyFile: replace_me
重启mongodb