Linux下Mongodb的安装
[root@localhost usr]# cd /usr
//创建Mongodb目录 用于存放Mongodb的程序
[root@localhost usr]# mkdir mongodb
[root@localhost usr]# cd /usr/mongodb
[root@localhost usr]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
--2017-06-01 15:15:04-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
正在解析主机 fastdl.mongodb.org (fastdl.mongodb.org)... 52.84.167.193, 52.84.167.70, 52.84.167.13, ...
正在连接 fastdl.mongodb.org (fastdl.mongodb.org)|52.84.167.193|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:40282490 (38M) [application/x-gzip]
正在保存至: “mongodb-linux-x86_64-3.0.6.tgz”
100%[=====================================================================================================================================================>] 40,282,490 3.72MB/s 用时 13s
2017-06-01 15:15:19 (2.87 MB/s) - 已保存 “mongodb-linux-x86_64-3.0.6.tgz” [40282490/40282490])
[root@localhost usr]# tar -xzf mongodb-linux-x86_64-3.0.6.tgz
//数据文件存放位置
[root@localhost usr]# mkdir -p /data/db
[root@localhost usr]# mkdir -p /usr/mongodb/logs
//日志位置
[root@localhost usr]# touch /usr/mongodb/logs/mongodb.log
//创建配置文件
[root@localhost etc]# touch /etc/mongodb.conf
//注:fork 是否后台Daemon运行
[root@localhost etc]# vi /etc/mongodb.conf
dbpath=/data/db/
logpath=//usr/mongodb/logs/mongodb.log
fork=true
port=27017
[root@localhost mongodb]# cd /usr/mongodb/mongodb-linux-x86_64-3.0.6/bin
//启动服务
[root@localhost bin]# ./mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 4125
child process started successfully, parent exiting
//进入客户端测试
[root@localhost bin]# ./mongo
MongoDB shell version: 3.0.6
connecting to: test
Server has startup warnings:
2017-06-01T15:46:57.573+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-06-01T15:46:57.573+0800 I CONTROL [initandlisten]
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten]
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten]
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-06-01T15:46:57.574+0800 I CONTROL [initandlisten]
> 1+1
2
//离开客户端
> exit
bye
//可以使用kill关闭服务
[root@localhost bin]# ps aux | grep mongodb
root 4125 0.4 1.7 463104 51812 ? Sl 15:46 0:01 ./mongod -f /etc/mongodb.conf
root 4198 0.0 0.0 112660 984 pts/1 S+ 15:52 0:00 grep --color=auto mongodb
[root@localhost bin]# kill -2 4125