介绍
OrientDB是一个多模型的NoSQL数据库,支持图形和文档数据库,它是一个Java应用程序,可以在任何操作系统上运行。
在本文中,您将学习如何在 Ubuntu 14.04 服务器上安装和配置 OrientDB 的最新社区版本。
前提条件
要遵循本教程,您将需要以下内容:
- Ubuntu 14.04 Droplet
- 具有 sudo 特权的非根用户(Initial Server Setup with Ubuntu 14.04解释了如何设置此功能)。
第1步:安装Oracle Java
OrientDB 是一个 Java 应用程序,需要 Java 版本 1.6 或更高版本. 因为它比 Java 6 和 7 更快,所以强烈建议 Java 8。
要安装Java JRE,请添加以下个人包档案(PPA):
1sudo add-apt-repository ppa:webupd8team/java
更新包数据库:
1sudo apt-get update
然后安装 Oracle Java. 使用此特定包来安装它不仅会安装它,而且还会使它成为默认的Java JRE。
1sudo apt-get install oracle-java8-set-default
安装后,请验证它现在是默认的Java JRE:
1java -version
预期输出如下(准确版本可能有所不同):
1[secondary_label output]
2java version "1.8.0_60"
3Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
4Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
步骤 2 – 下载和安装 OrientDB
在此步骤中,我们将下载并安装 OrientDB 的最新社区版本. 在此发布时,OrientDB Community 2.1.3 是最新版本. 如果发布了更新的版本,请更改版本号以匹配:
1wget https://orientdb.com/download.php?file=orientdb-community-2.1.3.tar.gz
下载的 tarball 包含预编译的二进制文件,您需要在您的系统上运行 OrientDB,所以您所需要做的就是将其解析到适当的目录中。
1sudo tar -xf download.php?file=orientdb-community-2.1.3.tar.gz -C /opt
这些文件被提取到名为orientdb-community-2.1.3
的目录中。
1sudo mv /opt/orientdb-community-2.1.3 /opt/orientdb
步骤 3 – 启动服务器
现在二进制已经在位,您可以启动服务器并连接到控制台。
1cd /opt/orientdb
然后启动服务器:
1sudo bin/server.sh
除了生成一堆输出之外,在第一次启动服务器时,您将被要求为 root 用户帐户指定密码. 这是一个内部的OrientDB帐户,将用于访问服务器。 例如,它是用户名和密码组合,将用于访问OrientDB Studio,用于管理OrientDB的基于Web的界面。
从启动服务器生成的输出部分告诉您服务器和OrientDB Studio正在收听哪些端口:
1[secondary_label Output]
22015-10-12 11:27:45:095 INFO Databases directory: /opt/orientdb/databases [OServer]
32015-10-12 11:27:45:263 INFO Listening binary connections on 0.0.0.0:2424 (protocol v.32, socket=default) [OServerNetworkListener]
42015-10-12 11:27:45:285 INFO Listening http connections on 0.0.0.0:2480 (protocol v.10, socket=default) [OServerNetworkListener]
5
6...
7
82015-10-12 11:27:45:954 INFO OrientDB Server v2.1.3 (build UNKNOWN@r; 2015-10-04 10:56:30+0000) is active. [OServer]
由于OrientDB现在在您的终端窗口中运行,在同一Droplet的第二终端窗口中,确认服务器正在收听端口2424(对二进制连接)和2480(对HTTP连接)。
1sudo netstat -plunt | grep 2424
产量应该类似于
1[secondary_label Output]
2tcp6 0 0 :::2424 :::* LISTEN 1617/java
要确认它正在收听 HTTP 连接,执行:
1sudo netstat -plunt | grep 2480
预计产量如下:
1[secondary_label Output]
2tcp6 0 0 :::2480 :::* LISTEN 1617/java
步骤 4 – 连接到控制台
现在服务器正在运行,您可以使用控制台连接到它,即命令行界面:
1sudo /opt/orientdb/bin/console.sh
你会看到以下:
1[secondary_label Output]
2OrientDB console v.2.1.3 (build UNKNOWN@r; 2015-10-04 10:56:30+0000) www.orientdb.com
3Type 'help' to display all the supported commands.
4Installing extensions for GREMLIN language v.2.6.0
5
6orientdb>
现在,连接到服务器实例. 所需的密码是您在先前启动服务器时指定的密码:
1connect remote:127.0.0.1 root root-password
如果连接,输出应该是:
1[secondary_label Output]
2Connecting to remote Server instance [remote:127.0.0.1] with user 'root'...OK
3orientdb {server=remote:127.0.0.1/}>
退出
类型:
1exit
所以你刚刚安装了OrientDB,手动启动了它,并连接到它,这很好,但是,这也意味着每次重新启动服务器时手动启动它,这并不好。
在仍在运行 OrientDB 的终端窗口中键入CTRL-C
,以阻止它。
步骤 5 – 配置 OrientDB
在此时,OrientDB已安装在您的系统上,但它只是服务器上的一大堆脚本. 在此步骤中,我们将修改配置文件,并将其配置为在系统上运行作为一个戴蒙。这涉及修改/opt/dborient/bin/orientdb.sh
脚本和/opt/orientdb/config/orientdb-server-config.xml
配置文件。
让我们开始修改‘/opt/orientdb/bin/orientdb.sh’脚本,告诉 OrientDB用户它应该运行为,并将其指向安装目录。
因此,首先创建您想要运行 OrientDB 的系统用户,该命令还会创建 orientdb 组:
1sudo useradd -r orientdb -s /bin/false
向新创建的 OrientDB 用户和组授予 OrientDB 目录和文件的所有权:
1sudo chown -R orientdb:orientdb /opt/orientdb
现在让我们对orientdb.sh
脚本做一些更改,我们开始使用:
1sudo nano /opt/orientdb/bin/orientdb.sh
首先,我们需要将其指向正确的安装目录,然后告诉它应该作为哪个用户运行它,所以在文件顶部寻找以下两行:
1[secondary_label /opt/orientdb/bin/orientdb.sh]
2# You have to SET the OrientDB installation directory here
3ORIENTDB_DIR="YOUR_ORIENTDB_INSTALLATION_PATH"
4ORIENTDB_USER="USER_YOU_WANT_ORIENTDB_RUN_WITH"
將其改為:
1[secondary_label /opt/orientdb/bin/orientdb.sh]
2# You have to SET the OrientDB installation directory here
3ORIENTDB_DIR="/opt/orientdb"
4ORIENTDB_USER="orientdb"
现在,让我们让系统用户能够使用sudo
来运行脚本。
下面,在脚本的 start 函数下,寻找下面的行,并通过在其前面添加#
字符来评论它。
1[secondary_label /opt/orientdb/bin/orientdb.sh]
2#su -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./server.sh 1>../log/orientdb.log 2>../log/orientdb.err &" - $ORIENTDB_USER
复制并粘贴下面的行,就在你刚刚评论的后面:
1[secondary_label /opt/orientdb/bin/orientdb.sh]
2sudo -u $ORIENTDB_USER sh -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./server.sh 1>../log/orientdb.log 2>../log/orientdb.err &"
在 stop 函数下,搜索下面的行,并评论它,它必须显示如图所示。
1[secondary_label /opt/orientdb/bin/orientdb.sh]
2#su -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./shutdown.sh 1>>../log/orientdb.log 2>>../log/orientdb.err &" - $ORIENTDB_USER
复制并粘贴下面的行,就在你刚刚评论的后面:
1[secondary_label /opt/orientdb/bin/orientdb.sh]
2sudo -u $ORIENTDB_USER sh -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./shutdown.sh 1>>../log/orientdb.log 2>>../log/orientdb.err &"
保存并关闭文件。
接下来,打开配置文件:
1sudo nano /opt/orientdb/config/orientdb-server-config.xml
我们将更改存储
标签,并可选地将另一个用户添加到用户
标签中,然后滚动到存储
元素,并修改它以便读取如下内容。
1[secondary_label /opt/orientdb/config/orientdb-server-config.xml]
2<storages>
3 <storage path="memory:temp" name="temp" userName="username" userPassword="password" loaded-at-startup="true" />
4</storages>
如果您滚动到 users 标签,您应该看到您在步骤 3 中首次启动 OrientDB 服务器时指定的 root 用户的用户名和密码,也将列出一个客人帐户。您不需要添加任何其他用户,但如果您想要,您可以添加您登录您的 DigitalOcean 服务器时使用的用户名和密码。
1[secondary_label /opt/orientdb/config/orientdb-server-config.xml]
2<user name="username" password="password" resources="*"/>
保存并关闭文件。
最后,修改文件的权限,以防止未经授权的用户阅读它:
1sudo chmod 640 /opt/orientdb/config/orientdb-server-config.xml
步骤6:安装启动脚本
现在,脚本已经配置了,您现在可以将其复制到各自的系统目录. 对于负责运行控制台的脚本,请将其复制到 /usr/bin
目录:
1sudo cp /opt/orientdb/bin/console.sh /usr/bin/orientdb
然后将负责启动和停止服务或 DAEMON 的脚本复制到 /etc/init.d
目录:
1sudo cp /opt/orientdb/bin/orientdb.sh /etc/init.d/orientdb
更改到 /etc/init.d
目录:
1cd /etc/init.d
然后更新rc.d
目录,以便系统知道新的脚本,并像其他系统魔鬼一样启动它。
1sudo update-rc.d orientdb defaults
你应该得到以下的输出:
1[secondary_label Output]
2update-rc.d: warning: /etc/init.d/orientdb missing LSB information
3update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
4 Adding system startup for /etc/init.d/orientdb ...
5 /etc/rc0.d/K20orientdb -> ../init.d/orientdb
6 /etc/rc1.d/K20orientdb -> ../init.d/orientdb
7 /etc/rc6.d/K20orientdb -> ../init.d/orientdb
8 /etc/rc2.d/S20orientdb -> ../init.d/orientdb
9 /etc/rc3.d/S20orientdb -> ../init.d/orientdb
10 /etc/rc4.d/S20orientdb -> ../init.d/orientdb
11 /etc/rc5.d/S20orientdb -> ../init.d/orientdb
步骤 7 – 启动 OrientDB
有了这一切,你现在可以开始服务:
1sudo service orientdb start
看看它是否真的开始了:
1sudo service orientdb status
您还可以使用步骤 3 中的 netstat
命令来验证服务器是否正在收听端口. 如果服务器无法启动,请检查 /opt/orientdb/log
目录中的错误日志文件中的线索。
步骤 8 — 连接到 OrientDB Studio
OrientDB Studio 是管理 OrientDB 的 Web 接口. 默认情况下,它是在端口 2480 上收听。 要连接到它,请打开浏览器并在地址栏中输入以下内容:
1http://server-ip-address:2480
如果页面加载,你应该看到登录屏幕. 你应该能够登录为根
和您之前设置的密码。
如果页面不加载,可能是因为它被防火墙阻止了,所以你需要将规则添加到防火墙中,以便在端口2480上允许OrientDB流量。
1sudo /etc/iptables/rules.v4
在 INPUT 链中,添加以下规则:
1[secondary_label /etc/iptables/rules.v4]
2-A INPUT -p tcp --dport 2480 -j ACCEPT
重新启动 iptables:
1sudo service iptables-persistent reload
这应该是为了连接到OrientDB Studio。
结论
恭喜您!您刚刚在您的服务器上安装了 OrientDB 社区版本。 有关更多信息,请参阅 如何在 Ubuntu 14.04 上备份您的 OrientDB 数据库 和 如何在 Ubuntu 14.04 上导入和导出一个 OrientDB 数据库 文章。
更多信息和官方 OrientDB 文档链接可在 orientdb.com找到。