Apache geode
可在廣泛分布的雲架構中提供對數據密集型應用程序的實時,一致的訪問。
Geode還是一個內存數據管理系統,可提供可靠的異步事件通知和有保證的消息傳遞。
任務: 跟redis一樣的,先在linux搭建一個單機,再java寫一個客戶端,消費端,測試一下。
geode下載
linux 安裝,解壓即可 (jdk要1.8以上)
新建一個/work目錄專門安裝軟件和上傳軟件包
cd / mkdir work tar -zxvf apache-geode-1.12.0.tgz mv apache-geode-1.12.0 geode
編輯/etc/profile 添加環境變量,就可以直接使用gfsh命令。但是一般本機賬戶沒有權限,要root才行,所以我們可以使用sudo命令
sudo vim /etc/profile
在配置最下面添加:
export PATH=$PATH:/work/geode/bin
source /etc/profile
啟動locator
(它告訴一個新連接的成員其它正在運行的成員的位置,並為服務器提供負載均衡。用於監測和管理geode集群)
gfsh start locator --name=locator1
啟動基於瀏覽器的pulse監控工具
start pulse
Running desktop applications is not supported on Linux.
這個命令啟動pulse並自動連接到locator的JMX管理器,
在pulse的登錄頁面 http://192.168.1.141:7070/pulse
默認賬戶:admin 密碼:admin。

后台運行語法(了解即可):
gfsh
如要直接在命令行上運行多個命令,請使用-e選項,然后gfsh在引號內加上命令。例如:
gfsh -e "start locator --name=locator1" -e "start server --name=server1 --server-port=40411"
啟動/停止緩存服務器Server
start server --name=server1 --server-port=40411 stop server --name=server1
創建分區,策略REPLICATE_PERSISTENT
create region --name=regionA --type=REPLICATE_PERSISTENT
bug:在server1上創建分區后,在pluse上提示server1崩潰退出
Member Departed server1 has crashed = false
查看server1.log:
The disk volume . for disk store DEFAULT has exceeded the critical usage threshold and is 64% full
磁盤卷。對於磁盤存儲,默認值已超過臨界使用閾值,並且已滿64%
geode.cache.DiskAccessException: For DiskStore: DEFAULT: Critical disk usage threshold exceeded for volume
/home/appadmin/server1/.: the file system only has 765480960 bytes free which is below the minimum of 1094713344.
對於DiskStore:DEFAULT:超過volume/home/appadmin/server1/的關鍵磁盤使用閾值:文件系統只有765480960個可用字節,低於最小值1094713344。(1044MB)
居然在home文件下啟動geode並默認在/home下存儲數據了。
在/work目錄下,我的空間比較大, 需要指定server 和 locator啟動的初始化目錄就可以
解決辦法:
cd /work/
[user@flxxxxx work]$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_root-lv_work 216G 296M 216G 1% /work
排查了一波,/work磁盤有整整216G
切換到 /work/geode 下執行gfsh,再啟動locator 和 server,啟動成功,此目錄下空間充足,server 不會因為空間不足而自動停止了。
用gfsh命令來查看集群中的區域
gfsh> list regions
列出集群上的成員,你開啟的locator和緩存服務器出現在列表中
gfsh> list members
查看區域說明
gfsh> describe region --name=regionA
注意事項:在新的終端窗口 啟動gfsh時,你必須使用connect命令connect其指向正在運行的定位器,以便你可以找到regionA等;
(只要使用了新的shell,重新建立了連接,就需要執行此步驟,以便於找到屬於你的locator)
(或者當使用 quit 退出了gfsh命令窗口,想再次重連已經啟動的locator時也要使用下面的命令方式)
gfsh> connect --locator=localhost[10334]
============分割線=============
JAVA API DEMO 鏈接
依賴
<dependencies> <dependency> <groupId>org.apache.geode</groupId> <artifactId>geode-core</artifactId> <version>1.12.0</version> </dependency> </dependencies>
關於發布jar包到geode (凡是自定義的實體類對象要存到geode, 就要實現DataSerializable 接口,並打成jar包 發布到geode上)
部署位於指定目錄下的所有jar文件到所有的成員:
gfsh> deploy --dir=/work/geode/deploy
卸載分布式系統中所有之前部署的jar文件:
gfsh> undeploy
為啥要發布到geode里呢?
因為我們用UserBean的序列化和反序列化作為表結構,因此deode查詢時需要UserBean.class,我們發布hellogeode-0.0.1-SNAPSHOT.jar到geode,主要是為了把UserBean.class導入到geode里;
gfsh> deploy --jar=/work/geode/deploy/spring-geode-demo-1.0-SNAPSHOT.jar
若是我們對UserBean有修改的話,需要先卸載jar,然后再重新發布
gfsh> undeploy --jar=hellogeode-0.0.1-SNAPSHOT.jar

查看發布的jar包情況
gfsh>list deployed
OQL查詢BUG
gfsh>query --query="select * from /regionA where age>9999"
Result : false
Message : A ClassNotFoundException was thrown while trying to deserialize cached value.
報錯因為沒有deploy實體類的 jar包,發布后就可以了

IDEA直接運行BUG
WARN org.apache.geode.cache.client.internal.ConnectionFactoryImpl - Could not connect to: flixxxx.xxxx.com.cn:40411
java.net.UnknownHostException: flixxxx.xxxx.com.cn
解決辦法,因為 flixxxx.xxxx.com.cn 是linux 上面的 /etc/hosts 配置的,但是在本地的windows不認識:
修改windows的 host文件,: your linux hostname flixxxx.xxxx.com.cn
然后,報了新的BUG
執行遠程查詢時異常,無法找到regionAu,怎么會是 regionAu
org.apache.geode.cache.client.ServerOperationException: remote server on LAPTOP-CRM8M3CD(44864:loner):63450:15ba472c: While performing a remote query
Caused by: org.apache.geode.cache.query.RegionNotFoundException: Region not found: /regionAu

解決, 原因是代碼中 OQL 語法拼接有問題,才注意到 u 前面少了個空格,改成如下即可
select * from /"+regionName+" u where u.age>15

