下载
下载路径:https://www.mongodb.com/try/download/community
安装
我选择把下载好的压缩包放在/usr/local目录下,首先解压当前mongodb压缩包
[root@harvei1 local]# tar -zxvf mongodb-linux-x86_64-3.6.21.tgz
重命名mongodb文件包
[root@harvei1 local]# mv mongodb-linux-x86_64-3.6.21 mongodb
配置环境变量
[root@harvei1 local]# vim /etc/profile
在profile文件里添加 export PATH=/usr/local/mongodb/bin:$PATH
[root@harvei1 local]# source /etc/profile
创建存储目录与日志目录
[root@harvei1 mongodb]# mkdir data
[root@harvei1 mongodb]# mkdir logs
[root@harvei1 mongodb]# touch logs/mongodb.log
[root@harvei1 mongodb]# sudo chown -R 777 /usr/local/mongodb
创建mongodb配置文件
[root@harvei1 bin]# vim /usr/local/mongodb/bin/mongodb.conf
systemLog: # 日志 quiet: false path: /usr/local/mongodb/logs/mongod.log #日志输出文件 logAppend: false destination: file processManagement: # fork: true # true 后台运行 false 当前运行 pidFilePath: /usr/local/mongodb/data/mongod.pid # pid 文件路径 net: bindIp: 0.0.0.0 # 绑定IP 设置IP可以访问的限制,如127.0.0.1只能本机连接,0.0.0.0 局域内通过内网IP连接 port: 3717 # 启动端口 默认是27017 maxIncomingConnections: 65536 wireObjectCheck: true ipv6: false storage: dbPath: /usr/local/mongodb/data #存储路径 indexBuildRetry: true journal: enabled: true directoryPerDB: false engine: mmapv1 syncPeriodSecs: 60 mmapv1: quota: enforced: false maxFilesPerDB: 8 smallFiles: true journal: commitIntervalMs: 100 wiredTiger: engineConfig: cacheSizeGB: 8 journalCompressor: snappy directoryForIndexes: false collectionConfig: blockCompressor: snappy indexConfig: prefixCompression: true operationProfiling: slowOpThresholdMs: 100 mode: off
创建一个启动脚本
[root@harvei1 bin]# vim start-mongodb.sh
nohup /usr/local/mongodb/bin/mongod -f mongodb.conf &
启动MongoDB
[root@harvei1 ~]# sh /usr/local/mongodb/bin/start-mongodb.sh
本机连接MongoDB
[root@harvei1 /]# /usr/local/mongodb/bin/mongo --port 3717
MongoDB shell version v3.6.21
connecting to: mongodb://127.0.0.1:3717/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“2881e723-96d2-4e0c-b29a-982dfee11232”) }
MongoDB server version: 3.6.21
Server has startup warnings:
2020-11-27T13:30:22.817+0000 I STORAGE [initandlisten]
2020-11-27T13:30:22.817+0000 I STORAGE [initandlisten] ** WARNING: Readahead for /usr/local/mongodb/data is set to 4096KB
2020-11-27T13:30:22.817+0000 I STORAGE [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less
2020-11-27T13:30:22.817+0000 I STORAGE [initandlisten] ** http://dochub.mongodb.org/core/readahead
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten]
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten]
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten]
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten]
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-11-27T13:30:22.867+0000 I CONTROL [initandlisten]
到此MongoDB安装完毕!
验证本地是否能够连接上,打开常用的Navicat Premium工具,创建MongoDB连接:
通过工具在本地也能连接上,证明MongoDB正确安装成功!