侧边栏壁纸
博主头像
DJ's Blog博主等级

行动起来,活在当下

  • 累计撰写 133 篇文章
  • 累计创建 51 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

【MongoDB】安装和配置

Administrator
2022-03-08 / 0 评论 / 0 点赞 / 56 阅读 / 2651 字

【MongoDB】安装和配置

安装

tar -zxvf mongodb-linux-x86_64-rhel70-4.4.3.tgz
mv mongodb-linux-x86_64-rhel70-4.4.3 /usr/local/mongodb

配置

  • 创建db目录和日志文件
cd /usr/local/mongodb/
mkdir -p ./data/db
mkdir -p ./logs
  • 创建mongodb.conf文件
vim mongodb.conf
systemLog:
  # MongoDB发送所有日志输出的目标指定为文件
  destination: file
  path: "/usr/local/mongodb/logs/mongodb.log"
  logAppend: true
storage:
  # mongod实例存储其数据的目录
  dbPath: "/usr/local/mongodb/data/db"
  journal:
    # 启用或禁用持久性日志以确保数据文件保持有效和可恢复。
    enabled: true
processManagement:
   # 启用在后台运行mongos或mongod进程的守护进程模式。
   fork: true
net:
   # 服务实例绑定的IP,默认是localhost,允许远程IP连接
   bindIp: 0.0.0.0
   port: 27017
  • 启动测试
./bin/mongod --config mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 20032
child process started successfully, parent exiting
  • 配置mongodb服务开机启动
vim /lib/systemd/system/mongodb.service
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongodb.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  • 启动mongodb服务
systemctl start mongodb
  • 重新加载配置
systemctl daemon-reload
  • 添加开机自启动
systemctl enable mongodb
  • 添加环境变量
vim /etc/profile
export MONGODB_HOME=/usr/local/mongodb
export PATH=$MONGODB_HOME/bin:$PATH
source /etc/profile
0

评论区