MongoDB 安装与配置

安装 MongoDB: ```bash [root@localhost ~]$ cat /etc/yum.repos.d/mongodb-3.4.repo [mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc ``` ```bash [root@localhost ~]$ yum install -y mongodb-org ```
配置 MongoDB: ```bash [root@localhost ~]$ cat /etc/mongod.conf systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # 日志存放目录 storage: dbPath: /data/mongodb # 数据存放目录 journal: enabled: true processManagement: fork: true pidFilePath: /var/run/mongodb/mongod.pid # pid文件路径 net: port: 27017 # 监听端口,默认是27017 bindIp: 127.0.0.1 # 定义可以远程连接MongoDB的IP地址 ``` ```bash [root@localhost ~]$ mkdir -p /data/mongodb # 创建数据存放目录 ```
启动并连接 MongoDB: ```bash [root@localhost ~]$ systemctl start mongod # 启动 MongoDB [root@localhost ~]$ mongo --host 127.0.0.1 --port 27017 # 连接 MongoDB ```




posted @ 2019-03-03 18:47  孔雀东南飞  阅读(103)  评论(0编辑  收藏  举报