如何安装和配置OrientDB在Ubuntu 14.04

介绍

OrientDB是一个多模型NoSQL数据库,支持图形和文档数据库。 它是一个Java应用程序,可以在任何操作系统上运行。 它还完全符合ACID投诉,支持多主复制。

在本文中,您将学习如何在Ubuntu 14.04服务器上安装和配置最新的Community版本的OrientDB。

先决条件

要遵循本教程,您需要以下内容:

第1步 - 安装Oracle Java

OrientDB是一个Java应用程序,需要Java版本1.6或更高版本。 因为它比Java 6和7快得多,所以强烈推荐使用Java 8。 这是我们将在此步骤中安装的Java版本。

要安装Java JRE,请添加以下个人包封装(PPA):

sudo add-apt-repository ppa:webupd8team/java

更新包数据库:

sudo apt-get update

然后安装Oracle Java。 使用这个特定的软件包安装它不仅安装它,而且使它成为默认的Java JRE。 出现提示时,接受许可协议:

sudo apt-get install oracle-java8-set-default

安装之后,验证它现在是默认的Java JRE:

java -version

预期输出如下(确切版本可能有所不同):

outputjava version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

第2步 - 下载并安装OrientDB

在这一步,我们将下载并安装最新的Community版本的OrientDB。 在本出版物的时候,OrientDB Community 2.1.3是最新版本。 如果已发布较新版本,请更改版本号以匹配:

wget https://orientdb.com/download.php?file=orientdb-community-2.1.3.tar.gz

下载的tarball包含预编译的二进制文件,您需要在系统上运行OrientDB,所以您需要做的是将其解压到合适的目录。 既然/opt是在Linux上的第三方程序的传统位置,让我们解压它有:

sudo tar -xf download.php?file=orientdb-community-2.1.3.tar.gz -C /opt

这些文件被提取到指定目录orientdb-community-2.1.3 为了方便使用,我们重命名它:

sudo mv /opt/orientdb-community-2.1.3 /opt/orientdb

第3步 - 启动服务器

现在二进制文件就位,您可以启动服务器并连接到控制台。 在此之前,导航到安装目录:

cd /opt/orientdb

然后启动服务器:

sudo bin/server.sh

除了生成大量的输出,通过启动首次服务器,系统会提示您指定root用户帐户的密码。 这是一个内部OrientDB帐户,将用于访问服务器。 例如,它是将用于访问OrientDB Studio(用于管理OrientDB的基于Web的界面)的用户名和密码组合。 如果不指定密码,将自动生成一个密码。 但是,最好自己指定一个,在提示时执行。

从启动服务器生成的部分输出将告诉您服务器和OrientDB Studio正在侦听的端口:

Output2015-10-12 11:27:45:095 INFO  Databases directory: /opt/orientdb/databases [OServer]
2015-10-12 11:27:45:263 INFO  Listening binary connections on 0.0.0.0:2424 (protocol v.32, socket=default) [OServerNetworkListener]
2015-10-12 11:27:45:285 INFO  Listening http connections on 0.0.0.0:2480 (protocol v.10, socket=default) [OServerNetworkListener]

...

2015-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连接)。 要确认它正在侦听二进制连接,请执行:

sudo netstat -plunt | grep 2424

输出应该类似

Outputtcp6       0      0 :::2424                 :::*                    LISTEN      1617/java

要确认它正在侦听HTTP连接,请执行:

sudo netstat -plunt | grep 2480

预期输出如下:

Outputtcp6       0      0 :::2480                 :::*                    LISTEN      1617/java

第4步 - 连接到控制台

现在服务器正在运行,可以使用控制台连接到它,也就是命令行界面:

sudo /opt/orientdb/bin/console.sh

您将看到以下内容:

OutputOrientDB console v.2.1.3 (build UNKNOWN@r; 2015-10-04 10:56:30+0000) www.orientdb.com
Type 'help' to display all the supported commands.
Installing extensions for GREMLIN language v.2.6.0

orientdb>

现在,连接到服务器实例。 所需的密码是您在早期首次启动服务器时指定的密码:

connect remote:127.0.0.1 root root-password

如果连接,输出应为:

OutputConnecting to remote Server instance [remote:127.0.0.1] with user 'root'...OK
orientdb {server=remote:127.0.0.1/}>

键入exit退出:

exit

所以你刚刚安装了OrientDB,手动启动它,并连接到它。 这一切都很好。 但是,这也意味着在重新启动服务器时手动启动它。 这不好。 在接下来的步骤中,我们将配置和设置OrientDB以便像服务器上的任何其他守护进程一样运行。

键入CTRL-C与OrientDB仍在运行停止它的终端窗口。

第5步 - 配置OrientDB

此时OrientDB安装在您的系统上,但它只是服务器上的一堆脚本。 在此步骤中,我们将修改配置文件,并将其配置为在系统上作为守护程序运行。 这涉及到修改/opt/orientdb/bin/orientdb.sh脚本和/opt/orientdb/config/orientdb-server-config.xml配置文件。

让我们通过修改启动/opt/orientdb/bin/orientdb.sh脚本告诉OrientDB它应该运行作为用户,并将其指向安装目录。

因此,首先,创建您希望OrientDB作为运行的系统用户。 该命令也将创建orientdb组:

sudo useradd -r orientdb -s /bin/false

将OrientDB目录和文件的所有权授予新创建的OrientDB用户和组:

sudo chown -R orientdb:orientdb /opt/orientdb

现在,让我们给一些改变orientdb.sh脚本。 我们从开始使用:

sudo nano /opt/orientdb/bin/orientdb.sh

首先,我们需要将它指向正确的安装目录,然后告诉它应该运行什么用户。 因此,在文件的顶部寻找以下两行:

/opt/orientdb/bin/orientdb.sh# You have to SET the OrientDB installation directory here
ORIENTDB_DIR="YOUR_ORIENTDB_INSTALLATION_PATH"
ORIENTDB_USER="USER_YOU_WANT_ORIENTDB_RUN_WITH"

并将其更改为:

/opt/orientdb/bin/orientdb.sh# You have to SET the OrientDB installation directory here
ORIENTDB_DIR="/opt/orientdb"
ORIENTDB_USER="orientdb"

现在,让我们能够为系统用户使用运行脚本sudo

再往下,脚本的启动功能下,查找以下行,并通过加入其注释掉#在它前面的字符。 它必须如下所示:

/opt/orientdb/bin/orientdb.sh#su -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./server.sh 1>../log/orientdb.log 2>../log/orientdb.err &" - $ORIENTDB_USER

将以下行复制并粘贴到刚刚注释掉的行的后面:

/opt/orientdb/bin/orientdb.shsudo -u $ORIENTDB_USER sh -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./server.sh 1>../log/orientdb.log 2>../log/orientdb.err &"

根据停机功能,查找以下行,并注释掉为好。 它必须如图所示。

/opt/orientdb/bin/orientdb.sh#su -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./shutdown.sh 1>>../log/orientdb.log 2>>../log/orientdb.err &" - $ORIENTDB_USER

将以下行复制并粘贴到刚刚注释掉的行的后面:

/opt/orientdb/bin/orientdb.shsudo -u $ORIENTDB_USER sh -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./shutdown.sh 1>>../log/orientdb.log 2>>../log/orientdb.err &"

保存并关闭文件。

接下来,打开配置文件:

sudo nano /opt/orientdb/config/orientdb-server-config.xml

我们要修改存储器的标签和可选,其他用户添加到用户的标签。 因此,滚动到存储器元素,使其看起来就像以下修改。 用户名密码是你登录凭证,就是那些你用来登录到你的服务器:

/opt/orientdb/config/orientdb-server-config.xml<storages>
        <storage path="memory:temp" name="temp" userName="username" userPassword="password" loaded-at-startup="true" />
</storages>

如果您滚动到用户标签,你应该看到,当你第一次启动OrientDB服务器在第3步中还列出了将来宾帐户指定的root用户的用户名和密码。 您不必添加任何其他用户,但如果您想要,您可以添加您用于登录您的DigitalOcean服务器的用户名和密码。 下面是如何添加用户标签内用户的例子:

/opt/orientdb/config/orientdb-server-config.xml<user name="username" password="password" resources="*"/>

保存并关闭文件。

最后,修改文件的权限,以防止未经授权的用户阅读它:

sudo chmod 640 /opt/orientdb/config/orientdb-server-config.xml

第6步 - 安装启动脚本

现在已经配置了脚本,现在可以将它们复制到各自的系统目录。 对于负责运行控制台脚本,将它复制到/usr/bin的目录:

sudo cp /opt/orientdb/bin/console.sh /usr/bin/orientdb

然后复制负责启动和停止服务或守护程序的脚本/etc/init.d目录:

sudo cp /opt/orientdb/bin/orientdb.sh /etc/init.d/orientdb

更改为/etc/init.d的目录:

cd /etc/init.d

然后更新rc.d以便系统知道该新脚本的目录,并会启动它在引导就像其他系统守护进程。

sudo update-rc.d orientdb defaults

您应该得到以下输出:

Outputupdate-rc.d: warning: /etc/init.d/orientdb missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/orientdb ...
   /etc/rc0.d/K20orientdb -> ../init.d/orientdb
   /etc/rc1.d/K20orientdb -> ../init.d/orientdb
   /etc/rc6.d/K20orientdb -> ../init.d/orientdb
   /etc/rc2.d/S20orientdb -> ../init.d/orientdb
   /etc/rc3.d/S20orientdb -> ../init.d/orientdb
   /etc/rc4.d/S20orientdb -> ../init.d/orientdb
   /etc/rc5.d/S20orientdb -> ../init.d/orientdb

第7步 - 启动OrientDB

一切就绪后,您现在可以启动服务:

sudo service orientdb start

验证它真的开始:

sudo service orientdb status

您也可以使用netstat命令,从第3步,以验证服务器在端口上侦听。 如果服务器不启动,检查在错误日志文件线索/opt/orientdb/log目录。

第8步 - 连接到OrientDB Studio

OrientDB Studio是用于管理OrientDB的Web界面。 默认情况下,它正在侦听端口2480.要连接到它,请打开浏览器并在地址栏中键入以下内容:

http://server-ip-address:2480

如果加载页面,您应该会看到登录屏幕。 您应该能够登录为root ,你之前设置的密码。

如果页面未加载,则可能是因为它被防火墙阻止。 因此,您必须向防火墙添加规则,以允许端口2480上的OrientDB流量。为此,请打开IPv4流量的IPTables防火墙规则文件:

sudo /etc/iptables/rules.v4

INPUT链中,添加以下规则:

/etc/iptables/rules.v4-A INPUT -p tcp --dport 2480 -j ACCEPT

重启iptables:

sudo service iptables-persistent reload

这应该用于连接到OrientDB Studio。

结论

恭喜! 您刚在您的服务器上安装了社区版OrientDB。 要了解更多信息,请参阅如何备份您的OrientDB数据库在Ubuntu 14.04如何导入和导出在Ubuntu 14.04的OrientDB数据库的文章。

更多信息和官方OrientDB文档链接上可以找到orientdb.com

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏