mongodb的安装:
1.MongoDB 源码下载地址:https://www.mongodb.com/download-center#community
2.vim /etc/profile修改环境变量:末尾添加
export PATH=$PATH:/home/no4/mongodb/bin
3.source /etc/profile
避免每次都要使用source /etc/profile使环境变量文件生效的方法:
sudo su vim ~/.bashrc
末尾添加source /etc/profile
4.新建配置文件mongod.conf
systemLog: destination: file path: "/home/no4/mongodata/log/mongod.log" logAppend: true storage: dbPath: "/home/no4/mongodata/db" journal: enabled: true processManagement: fork: true net: bindIp: localhost port: 27017
5.在配置文件所指定的位置建立对应的文件夹
6.mongod -f /home/no4/mongodb/mongod.conf命令启动mongodb服务器,正常输出如下:
root@no4-Default-string:/home/no4# mongod -f ./mongodb/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 11330 child process started successfully, parent exiting
如果是这样:
root@no4-Default-string:/home/no4# mongod -f ./mongodb/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 11306 ERROR: child process failed, exited with 48 To see additional information in this output, start without the "--fork" option.
一般是因为之前已经启动过了mongodb,使用ps -ef|grep mongod查找mongod相关进程,然后杀掉后再重试。
7.输入mongo连接服务器,再输入show dbs查看数据库,正常输出如下:
> show dbs admin 0.000GB config 0.000GB local 0.000GB