不多说,直接上干货!
前期博客
Ubuntu14.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)(博主推荐)
Ubuntu14.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)
为什么要写这篇博客?
在学习的过程中,考虑到将数据存储到数据库会更加方便查看和测试,所以使用了mongodb存储爬虫结果。在Ubuntu中,对MongoDB的操作都是在命令窗口中进行的,无法以图标的形式直接查看整个数据库的状态和其中的内容。
选择了两个可视化工具,它们分别是:Mongobooster和RoboMongo,由于推荐RoboMongo的人较多,所以选择了它。
1. RoboMongo的安装
(1) 下载RoboMongo至 /usr/local/app/robomongo
选择适合自己系统的版本,这里我的版本是64位的Linux。RoboMongo官网下载链接
当然,大家也可以在线安装。
https://download.robomongo.org/1.0.0/linux/robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz
(2) 解压文件
下载的文件为:
root@zhouls-virtual-machine:/usr/local/app# pwd
/usr/local/app
root@zhouls-virtual-machine:/usr/local/app# ls
jdk jdk1..0_60 neo4j neo4j-community-3.2.
root@zhouls-virtual-machine:/usr/local/app# cp /home/zhouls/Downloads/robomongo-1.0.-linux-x86_64-89f24ea.tar.gz .
root@zhouls-virtual-machine:/usr/local/app# ls
jdk neo4j robomongo-1.0.-linux-x86_64-89f24ea.tar.gz
jdk1..0_60 neo4j-community-3.2.
root@zhouls-virtual-machine:/usr/local/app#
root@zhouls-virtual-machine:/usr/local/app# ls
jdk neo4j robomongo-1.0.-linux-x86_64-89f24ea.tar.gz
jdk1..0_60 neo4j-community-3.2.
root@zhouls-virtual-machine:/usr/local/app# tar -zxvf robomongo-1.0.-linux-x86_64-89f24ea.tar.gz
root@zhouls-virtual-machine:/usr/local/app# ls
jdk neo4j robomongo-1.0.-linux-x86_64-89f24ea
jdk1..0_60 neo4j-community-3.2. robomongo-1.0.-linux-x86_64-89f24ea.tar.gz
root@zhouls-virtual-machine:/usr/local/app# rm robomongo-1.0.-linux-x86_64-89f24ea.tar.gz
root@zhouls-virtual-machine:/usr/local/app# ll
total
drwxr-xr-x root root Jun : ./
drwxr-xr-x root root Jun : ../
lrwxrwxrwx root root Jun : jdk -> jdk1..0_60//
drwxr-xr-x root root Aug jdk1..0_60/
lrwxrwxrwx root root Jun : neo4j -> neo4j-community-3.2.//
drwxr-xr-x root root Jun : neo4j-community-3.2./
drwxr-xr-x root root Jun : robomongo-1.0.-linux-x86_64-89f24ea/
root@zhouls-virtual-machine:/usr/local/app# ln -s robomongo-1.0.-linux-x86_64-89f24ea/ robomongo
root@zhouls-virtual-machine:/usr/local/app# ll
total
drwxr-xr-x root root Jun : ./
drwxr-xr-x root root Jun : ../
lrwxrwxrwx root root Jun : jdk -> jdk1..0_60//
drwxr-xr-x root root Aug jdk1..0_60/
lrwxrwxrwx root root Jun : neo4j -> neo4j-community-3.2.//
drwxr-xr-x root root Jun : neo4j-community-3.2./
lrwxrwxrwx root root Jun : robomongo -> robomongo-1.0.-linux-x86_64-89f24ea//
drwxr-xr-x root root Jun : robomongo-1.0.-linux-x86_64-89f24ea/
root@zhouls-virtual-machine:/usr/local/app#
root@zhouls-virtual-machine:/usr/local/app# cd robomongo
root@zhouls-virtual-machine:/usr/local/app/robomongo# ll
total
drwxr-xr-x root root Jun : ./
drwxr-xr-x root root Jun : ../
drwxr-xr-x root root Jun : bin/
-rw-r--r-- zhouls zhouls Apr : CHANGELOG
-rw-r--r-- zhouls zhouls Apr : COPYRIGHT
-rw-r--r-- zhouls zhouls Apr : DESCRIPTION
drwxr-xr-x root root Jun : lib/
-rw-r--r-- zhouls zhouls Apr : LICENSE
root@zhouls-virtual-machine:/usr/local/app/robomongo#
配置robomongo的环境变量
root@zhouls-virtual-machine:/usr/local/app/robomongo# vim /etc/profile
#robomongo
export ROBOMONGO_HOME=/usr/local/app/robomongo
export PATH=$PATH:$ROBOMONGO_HOME/bin
root@zhouls-virtual-machine:/usr/local/app/robomongo# vim /etc/profile
root@zhouls-virtual-machine:/usr/local/app/robomongo# source /etc/profile
root@zhouls-virtual-machine:/usr/local/app/robomongo# robomongo -version
MongoDB shell version: 3.2.--g9fa2d97
root@zhouls-virtual-machine:/usr/local/app/robomongo#
运行RoboMongo
系统会自动打开RoboMongo。
root@zhouls-virtual-machine:/usr/local/app/robomongo# cd bin/
root@zhouls-virtual-machine:/usr/local/app/robomongo/bin# pwd
/usr/local/app/robomongo/bin
root@zhouls-virtual-machine:/usr/local/app/robomongo/bin# ll
total
drwxr-xr-x root root Jun : ./
drwxr-xr-x root root Jun : ../
-rw-r--r-- zhouls zhouls Apr : qt.conf
-rwxr-xr-x zhouls zhouls Apr : robomongo*
root@zhouls-virtual-machine:/usr/local/app/robomongo/bin# ./robomongo
RoboMongo连接本地数据库
(1) 新建一个数据库链接
File ----> connet ----> create。 连接本地数据库的话,保持默认设置即可。
如果大家,在这一步,遇到如下的问题,则是
Cannot connect to the MongoDB at localhost:. Error:
Failed to execute "listdatabases" command.
选中已有的进行链接即可。我在连接数据库时,报错“连接失败”。
查询相关错误信息,连接失败的原因可能为iptable或服务器未打开。在我的系统中,没有设置开机自启MongoDB服务。考虑到这个问题,我重启了MongDB,重新运行RoboMongo,显示如下信息,并成功打开RoboMongo的本地数据库。
启动和关闭mongodb命令如下:
root@zhouls-virtual-machine:~# service mongodb start
start: Job is already running: mongodb
root@zhouls-virtual-machine:~# service mongodb stop
mongodb stop/waiting
root@zhouls-virtual-machine:~#
默认设置MongoDB是随Ubuntu启动自动启动的。