Mongodb 安装
-
测试环境
操作系统:CentOS 7.2 最小化安装
IP地址:192.168.197.20
Mongodb版本:mongodb-linux-x86_64-3.4.10.tgz
-
上传mongodb包到/software目录下,然后解压缩该包
[root@localhost software]# tar -zxvf mongodb-linux-x86_64-3.4.10.tgz
-
移动解压缩之后的文件至/usr/local/mongodb目录
[root@localhost software]# mv mongodb-linux-x86_64-3.4.10 /usr/local/mongodb
-
在mongodb下面创建data目录和logs目录,用于存放data和logs
[root@localhost local]# mkdir -p /usr/local/mongodb/data
[root@localhost local]# mkdir -p /usr/local/mongodb/logs
-
增加环境变量,并使环境变量生效
[root@localhost data]# vi /etc/profile
export PATH=$PATH:/usr/local/mongodb/bin
[root@localhost data]# source /etc/profile
-
创建mongodb.conf文件并写入一下内容
[root@localhost data]# touch /usr/local/mongodb/bin/mongodb.conf
[root@localhost data]# vi /usr/local/mongodb/bin/mongodb.conf
port=27017 #端口
dbpath= /usr/local/mongodb/data #数据库存文件存放目录
logpath= /usr/local/mongodb/logs/log.log #日志文件存放路径
logappend=true #使用追加的方式写日志
fork=true #不以守护程序的方式启用,即不在后台运行
maxConns=100 #最大同时连接数
noauth=true #不启用验证
journal=true #每次写入会记录一条操作日志(通过journal可以重新构造出写入的数据)。
#即使宕机,启动时wiredtiger会先将数据恢复到最近一次的checkpoint点,然后重放后续的journal日志来恢复。
storageEngine=wiredTiger #存储引擎有mmapv1、wiretiger、mongorocks
bind_ip = 0.0.0.0 #这样就可外部访问了,例如从win10中去连虚拟机中的MongoDB
-
使用配置文件启动启动mongod服务
[root@localhost logs]# mongod --config /usr/local/mongodb/bin/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2544
child process started successfully, parent exiting
-
启动mongodb客户端验证
[root@localhost bin]# ./mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2019-01-25T03:44:56.233-0500 I CONTROL [initandlisten]
2019-01-25T03:44:56.234-0500 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-25T03:44:56.234-0500 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-25T03:44:56.234-0500 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-01-25T03:44:56.234-0500 I CONTROL [initandlisten]
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten]
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten]
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-01-25T03:44:56.235-0500 I CONTROL [initandlisten]
>
-
列出数据库
> show dbs
admin 0.000GB
local 0.000GB