Chuyện của sys

DevOps Blog

Hazelcast IMDG In-Memory Data Grid November 4, 2017


1> Đôi nét về Hazelcast.

  •  Hazelcast là một mạng lưu trữ dữ liệu trên bộ nhớ Ram (in-memory data grid). Hazelcast đưa ra cài đặt của các interface trong Java như: Map, Queue, Excecutor Service, Lock… Nó được thiết kế rất nhẹ và dễ sử dụng.
  • Hazelcast được cài đặt bằng ngôn ngữ Java, client hỗ trợ các ngôn ngữ Java, C/C++, C# , Python…
  • Hazelcast cũng có thể được xem như một giao thức lưu đệm (memcache protocol).
  • Hazelcast sử dụng cơ chế mạng ngang hàng, không có master và slave. Tất cả các node lưu số lượng dữ liệu như nhau, và xử lý bằng nhau.
  • Hazelcast lưu trữ mọi thứ trên Ram (in-memory). Nó được thiết kế để thực thi rất nhanh các thao tác đọc và cập nhật (read/update) dữ liệu.
  • Hazelcast lưu các bản sao (backup) của mỗi mảnh dữ liệu trên các node khác nhau. Khi một node bị lỗi, dự liệu trên node đó sẽ được khôi phục lại từ bản sao (bản backup) và cụm Hazelcast vẫn hoạt động bình thường, không có thời gian ngừng hoạt động (downtime = 0).
  •  Sharding(các mảnh dữ liệu) trong Hazelcast được gọi là các Partition. Mặc định Hazelcast có 271 partition. Các partition được phân tán trên tất cả các node của cụm. Hazelcast cũng tạo bản backup của các partition và phân tán chúng trên các node.

2> Một số Use Case Hazelcast.

  • Application scaling
  • Cache-as-a-service
  • Cross-JVM communication and shared storage
  • Distributed cache, often in front of a database
  • In-memory processing and Analytics
  • In-memory computing
  • Internet of Things infrastructure
  • Key-value database
  • Memcached alternative with a protocol compatible interface[4]
  • Microservices infrastructure
  • NoSQL data store
  • Spring Cache
  • Web Session clustering

3> Kiến trúc Client-Server  Hazelcast.

  • Hazelcast cung cấp một kiến trúc phân mảnh & phân tán dữ liệu qua  cluster node.

+ Hazelcast IMDG  có những đặc điểm sau:

  • Dữ liệu được lưu trữ trên RAM.
  • Nhiều bản sao được lưu trữ trên nhiều node để auto-recovery dữ liệu  trong trường hợp một hoặc nhiều node fail.
  • Mô hình dữ liệu hướng đối tượng và là kiểu dữ liệu không quan hệ(non-relational).
  • Resource có thể được tự động thêm hoặc gỡ bỏ để tăng lượng CPU và RAM.
  • Dữ liệu có thể được duy trí từ một hazelcast node  đến một cơ sở dữ liệu quan hệ hoặc NoSQL.
  • Một Java API Map có thể truy xuất vào kho dữ liệu phân tán key-value.

HAZELCAST EMBEDDED ARCHITECTURE

HAZELCAST CLIENT-SERVER ARCHITECTURE

4> Setup Hazelcast Cluster.
Mô hình 3 node:

  • Node 01: IP 192.168.175.128
  • Node 02: IP 192.168.175.129
  • Management: IP 192.168.175.130

Step 1: Download Hazelcast 3.9

Link: https://hazelcast.org/download/archives/

Step 2: Install hazelcast-3.9

$  unzip hazelcast-3.9.zip

$ cp -R hazelcast-3.9 /build

Step 3: Configuration, Start & Stop Node01 (192.168.175.128)

$ cd /build/hazelcast-3.9

$ vim hazelcast.xml

– update management-center data
– update multicast data
– update tcp-ip data
<group>
<name>sandbox</name>
<password>abcd@#1234</password>
</group>
<management-center enabled=”true”>http://192.168.175.130:8080/mancenter</management-center>
<network>
<port auto-increment=”true” port-count=”100″>5701</port>
<outbound-ports>
<!–
Allowed port range when connecting to other nodes.
0 or * means use system provided port.
–>
<ports>0</ports>
</outbound-ports>
<join>
<multicast enabled=”false”>
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<tcp-ip enabled=”true”>
<interface>192.168.175.128</interface>
<member-list>
<member>192.168.175.128</member>
<member>192.168.175.129</member>
</member-list>
</tcp-ip>
<aws enabled=”false”>

$ cd /build/hazelcast-3.9/bin

$ chmod +x *.sh

$ ./start.sh => check port default 5701 is listen and join cluster (member list)

Step 4: Configuration, Start & Stop Node02 (192.168.175.129)

$ cd /build/hazelcast-3.9

$ vim hazelcast.xml

– update management-center data
– update multicast data
– update tcp-ip data
<group>
<name>sandbox</name>
<password>abcd@#1234</password>
</group>
<management-center enabled=”true”>http://192.168.175.130:8080/mancenter</management-center>
<network>
<port auto-increment=”true” port-count=”100″>5701</port>
<outbound-ports>
<!–
Allowed port range when connecting to other nodes.
0 or * means use system provided port.
–>
<ports>0</ports>
</outbound-ports>
<join>
<multicast enabled=”false”>
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<tcp-ip enabled=”true”>
<interface>192.168.175.129</interface>
<member-list>
<member>192.168.175.128</member>
<member>192.168.175.129</member>
</member-list>
</tcp-ip>
<aws enabled=”false”>

$ cd /build/hazelcast-3.9/bin

$ chmod +x *.sh

$ ./start.sh => check port default 5701 is listen and join cluster (member list)

Step 5:  Start & Stop Node Management (192.168.175.130)

$ wget https://download.hazelcast.com/management-center/management-center-3.9.zip

$ unzip management-center-3.9.zip

$ cp -R management-center-3.9 /build

$ cd /build/management-center-3.9/bin/

$ chmod +x startManCenter.sh

$ ./startManCenter.sh ( listen port default is 8080)

Acess link Web UI: http://IP:8080/mancenter

5> Một số link tham khảo

https://hazelcast.com/resources/benchmark-redis-vs-hazelcast-original/

http://www.tothenew.com/blog/caching-what-why-and-how-with-hazelcast/

https://hazelcast.org/download/archives/

 

Categories: Tài liệu

Leave a Reply

Your email address will not be published. Required fields are marked *