不多说,直接上干货!
前期博客
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.8.0_60 neo4j neo4j-community-3.2.0 root@zhouls-virtual-machine:/usr/local/app# cp /home/zhouls/Downloads/robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz . root@zhouls-virtual-machine:/usr/local/app# ls jdk neo4j robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz jdk1.8.0_60 neo4j-community-3.2.0 root@zhouls-virtual-machine:/usr/local/app#
root@zhouls-virtual-machine:/usr/local/app# ls jdk neo4j robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz jdk1.8.0_60 neo4j-community-3.2.0 root@zhouls-virtual-machine:/usr/local/app# tar -zxvf robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz
root@zhouls-virtual-machine:/usr/local/app# ls jdk neo4j robomongo-1.0.0-linux-x86_64-89f24ea jdk1.8.0_60 neo4j-community-3.2.0 robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz root@zhouls-virtual-machine:/usr/local/app# rm robomongo-1.0.0-linux-x86_64-89f24ea.tar.gz root@zhouls-virtual-machine:/usr/local/app# ll total 20 drwxr-xr-x 5 root root 4096 Jun 2 23:39 ./ drwxr-xr-x 11 root root 4096 Jun 2 14:53 ../ lrwxrwxrwx 1 root root 12 Jun 2 14:55 jdk -> jdk1.8.0_60// drwxr-xr-x 8 root root 4096 Aug 5 2015 jdk1.8.0_60/ lrwxrwxrwx 1 root root 22 Jun 2 15:39 neo4j -> neo4j-community-3.2.0// drwxr-xr-x 11 root root 4096 Jun 2 16:24 neo4j-community-3.2.0/ drwxr-xr-x 4 root root 4096 Jun 2 23:39 robomongo-1.0.0-linux-x86_64-89f24ea/ root@zhouls-virtual-machine:/usr/local/app# ln -s robomongo-1.0.0-linux-x86_64-89f24ea/ robomongo root@zhouls-virtual-machine:/usr/local/app# ll total 20 drwxr-xr-x 5 root root 4096 Jun 2 23:39 ./ drwxr-xr-x 11 root root 4096 Jun 2 14:53 ../ lrwxrwxrwx 1 root root 12 Jun 2 14:55 jdk -> jdk1.8.0_60// drwxr-xr-x 8 root root 4096 Aug 5 2015 jdk1.8.0_60/ lrwxrwxrwx 1 root root 22 Jun 2 15:39 neo4j -> neo4j-community-3.2.0// drwxr-xr-x 11 root root 4096 Jun 2 16:24 neo4j-community-3.2.0/ lrwxrwxrwx 1 root root 37 Jun 2 23:39 robomongo -> robomongo-1.0.0-linux-x86_64-89f24ea// drwxr-xr-x 4 root root 4096 Jun 2 23:39 robomongo-1.0.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 84 drwxr-xr-x 4 root root 4096 Jun 2 23:39 ./ drwxr-xr-x 5 root root 4096 Jun 2 23:39 ../ drwxr-xr-x 2 root root 4096 Jun 2 23:39 bin/ -rw-r--r-- 1 zhouls zhouls 23891 Apr 21 14:20 CHANGELOG -rw-r--r-- 1 zhouls zhouls 337 Apr 21 14:20 COPYRIGHT -rw-r--r-- 1 zhouls zhouls 177 Apr 21 14:20 DESCRIPTION drwxr-xr-x 4 root root 4096 Jun 2 23:39 lib/ -rw-r--r-- 1 zhouls zhouls 35147 Apr 21 14:20 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.0-34-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 18908 drwxr-xr-x 2 root root 4096 Jun 2 23:39 ./ drwxr-xr-x 4 root root 4096 Jun 2 23:39 ../ -rw-r--r-- 1 zhouls zhouls 25 Apr 21 14:20 qt.conf -rwxr-xr-x 1 zhouls zhouls 19346400 Apr 21 14:25 robomongo* root@zhouls-virtual-machine:/usr/local/app/robomongo/bin# ./robomongo
RoboMongo连接本地数据库
(1) 新建一个数据库链接
File ----> connet ----> create。 连接本地数据库的话,保持默认设置即可。
如果大家,在这一步,遇到如下的问题,则是
Cannot connect to the MongoDB at localhost:27017.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启动自动启动的。