1、安装
我使用的是二进制开箱即用版本,下载地址:https://ignite.apache.org/download.cgi#binaries,版本为最新的2.8.0,上传服务器、解压,如图:

1.1 配置
进入config目录,拷贝一份default-config.xml
为config.xml
,修改配置:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
Alter configuration below as needed.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="workDirectory" value="/app/ignite/work/"/>
<!-- server listener -->
<property name="clientConnectorConfiguration">
<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
<property name="host" value="0.0.0.0"/>
<property name="port" value="8811"/>
<property name="portRange" value="30"/>
</bean>
</property>
</bean>
</beans>
目前主要配置两个地方:工作目录和服务监听端口。
关于监听端口的配置问题,中间折腾了一番。刚开始,按照官方的入门配置只有工作目录部分,服务启动监听端口默认在客户端连接例子也是默认连接服务端口,因网络策略原因无法连接成功,此时知道默认端口为10800。
为了能够自己配置端口,找到xml配置文件指示的类org.apache.ignite.configuration
,发现其中的属性:org.apache.ignite.configuration.ClientConnectorConfiguration
,从中找到了如下属性:
/** Default port. */
public static final int DFLT_PORT = 10800;
/** Default port range. */
public static final int DFLT_PORT_RANGE = 100;
/** Default socket send and receive buffer size. */
public static final int DFLT_SOCK_BUF_SIZE = 0;
/** Default value for {@code TCP_NODELAY} socket option (value is <tt>true</tt>). */
public static final boolean DFLT_TCP_NO_DELAY = true;
/** Default max number of open cursors per connection. */
public static final int DFLT_MAX_OPEN_CURSORS_PER_CONN = 128;
/** Default size of thread pool. */
public static final int DFLT_THREAD_POOL_SIZE = IgniteConfiguration.DFLT_PUBLIC_THREAD_CNT;
/** Default handshake timeout. */
public static final int DFLT_HANDSHAKE_TIMEOUT = 10_000;
/** Default idle timeout. */
public static final int DFLT_IDLE_TIMEOUT = 0;
/** Default value of whether to use Ignite SSL context factory. */
public static final boolean DFLT_USE_IGNITE_SSL_CTX_FACTORY = true;
从而得知默认服务监听端口是10800。接下来就是修改配置文件,将ClientConnectorConfiguration
当做bean配置即可,因为配置文件xml的校验完全使用的Spring beans的xsd校验(http://www.springframework.org/schema/beans/spring-beans.xsd)。属性直接对照ClientConnectorConfiguration
成员变量配置即可,比如服务监听端口port
,从而改变默认的监听端口。
1.2 Ignite REST
讲libs/optional/ignite-rest-http/
目录下的jar包拷贝到libs目录,开启REST操作Ignite的能力。

在浏览器输入测试:http://127.0.0.1:8080/ignite?cmd=version

2 sqlline
使用bin目录下的sqlline可以作为客户端连接Ignite:./sqlline.sh --verbose=true -u jdbc:ignite:thin://127.0.0.1:8811/
。如果有用户名密码配置,使用:./sqlline.sh --verbose=true -u "jdbc:ignite:thin://127.0.0.1:8811;user=ignite;password=ignite"

2.1 查询表

2.2 新建表
建表语句:
--student学生信息表
CREATE TABLE IF NOT EXISTS PUBLIC.STUDENT (
STUDID INTEGER,
NAME VARCHAR,
EMAIL VARCHAR,
dob Date,
PRIMARY KEY (STUDID))
WITH "template=replicated,atomicity=ATOMIC,cache_name=student";
-- 索引
CREATE INDEX IF NOT EXISTS STUDENT_NE_INDEX ON PUBLIC.STUDENT (NAME, EMAIL);
-- grade成绩表
CREATE TABLE IF NOT EXISTS PUBLIC.GRADE (
STUDID INTEGER,
grade DOUBLE,
PRIMARY KEY (STUDID))
WITH "template=replicated,atomicity=ATOMIC,cache_name=grade";


2.3 查看表结构
使用columns 加指定表即可:!columns student

2.4 执行sql脚本
准备如下插入数据sql:
-- student
INSERT INTO student (studid, name, email, dob) VALUES (1, 'student_1', 'student_1gmail.com', '2017-09-28');
INSERT INTO student (studid, name, email, dob) VALUES (2, 'student_2', 'student_2gmail.com', '2017-09-28');
--grade
INSERT INTO grade (studid, grade) VALUES (1, 3);
INSERT INTO grade (studid, grade) VALUES (2, 64);
直接加载将数据插入:

查询之前插入的记录:

网友评论