下载地址https://www.mongodb.com/download-center#community
tar -xvf mongodb-linux-x86_64-rhel70-4.0.0.tgz
mv mongodb-linux-x86_64-rhel70-4.0.0 /usr/local/mongodb
MongoDB 的可执行文件位于 bin 目录下,所以可以将其添加到 PATH 路径中:
export PATH=/usr/local/mongodb/bin:$PATH
创建数据库目录
MongoDB的数据存储在data目录的db目录下,但是这个目录在安装过程不会自动创建,所以你需要手动创建data目录,并在data目录中创建db目录。
以下实例中我们将data目录创建于根目录下(/)。注意:/data/db 是 MongoDB 默认的启动的数据库路径(--dbpath)。
mkdir -p /data/db
命令行中运行 MongoDB 服务
你可以再命令行中执行mongo安装目录中的bin目录执行mongod命令来启动mongdb服务。
注意:如果你的数据库目录不是/data/db,可以通过 --dbpath 来指定。
mongod
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten]
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten]
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten]
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten]
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-07-19T14:24:49.259+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-07-19T14:24:49.450+0800 I NETWORK [initandlisten] waiting for connections on port 27017
连接
mongo
> db
test
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB