一、簡介
Ambry 是一個分布式對象存儲,支持存儲數萬億個不可變對象(50K -100K)以及數十億個大型對象。它專為在網絡公司中存儲和服務媒體對象而設計。但是,它可以用作通用存儲系統來存儲數據庫備份、搜索索引或業務報告。系統具有以下特征:
- 高度可用且水平可擴展
- 低延遲和高吞吐量
- 針對小型和大型對象進行了優化
- 經濟高效
- 易于使用
二、部署
1、基礎環境及架構
image.png
前端ip | port | 服務端ip | port |
---|---|---|---|
192.168.4.39 | 1174 | 192.168.4.39 | 6667 |
192.168.4.40 | 6667 | ||
192.168.4.41 | 6667 |
注意:至少需要 JDK 1.8
# yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
2、安裝
# git clone https://github.com/linkedin/ambry.git
# cd ambry
# ./gradlew allJar
# 會生成target文件夾并編譯生成jar包
3、服務端部署
# 新建目錄(三臺服務器操作相同)
# mkdir -p /data/ambry/{data,config,logs}
# 把所需配置文件移動到目錄
# cp config/{frontend.properties,HardwareLayout.json,log4j.properties,PartitionLayout.json,server.properties,server.ssl.properties} /data/ambry/config/
# jar包
# cp target/ambry.jar /data/ambry/
3.1、配置文件
3.1.1、集群硬件配置
# egrep -v "^$|*#" HardwareLayout.json
{
"clusterName": "my_ambry_cluster", #自定義名字
"version": 99,
"datacenters": [
{
"dataNodes": [
{
"disks": [
{
"capacityInBytes": 21474836480,
"hardwareState": "AVAILABLE",
"mountPath": "/app_server/ambry/data"
}
],
"hardwareState": "AVAILABLE",
"hostname": "192.168.4.39",
"port": 6667
},
{
"disks": [
{
"capacityInBytes": 21474836480,
"hardwareState": "AVAILABLE",
"mountPath": "/app_server/ambry/data"
}
],
"hardwareState": "AVAILABLE",
"hostname": "192.168.4.40",
"port": 6667
},
{
"disks": [
{
"capacityInBytes": 21474836480,
"hardwareState": "AVAILABLE",
"mountPath": "/app_server/ambry/data"
}
],
"hardwareState": "AVAILABLE",
"hostname": "192.168.4.41",
"port": 6667
}
],
"name": "Datacenter",
"id" : "1"
}
]
}
3.1.2、集群邏輯分片配置
# egrep -v "^$|*#" PartitionLayout.json
{
"clusterName": "my_ambry_cluster", #自定義名字
"version": 88,
"partitions": [
{
"id": 0,
"partitionClass": "max-replicas-all-datacenters",
"partitionState": "READ_WRITE",
"replicaCapacityInBytes": 10737418240,
"replicas": [
{
"hostname": "192.168.4.39",
"mountPath": "/app_server/ambry/data",
"port": 6667
},
{
"hostname": "192.168.4.40",
"mountPath": "/app_server/ambry/data",
"port": 6667
},
{
"hostname": "192.168.4.41",
"mountPath": "/app_server/ambry/data",
"port": 6667
}
]
}
]
}
3.1.3、集群日志配置
egrep -v "^$|*#" log4j.properties
注意:不做修改,使用原來的。
3.1.4、集群服務端配置
# egrep -v "^$|*#" server.properties
host.name=192.168.4.39 #本機ip
clustermap.cluster.name=Ambry_Dev
clustermap.datacenter.name=Datacenter
clustermap.host.name=192.168.4.39 #本機ip
3.1.5、 數字證書集群配置
由于 集群配置必須要SSL連接 ,需要在每臺服務器上生成數字證書
使用用Java自帶的keystore生成數字證書。 Keytool是一個Java數據證書的管理工具。Keytool將密鑰(key)和證書(certificates)存在一個稱為keystore的文件中在keystore里
注意:需要記住文件位置以及密碼(三臺服務器操作相同)
# cd /data/ambry/config
# 輸入完密碼后,其他都可默認回車
# keytool -genkeypair -alias certificatekey -validity 7000 -keystore keystore.jks
# keytool -export -alias certificatekey -keystore keystore.jks -rfc -file selfsignedcert.cer
# keytool -import -alias certificatekey -file selfsignedcert.cer -keystore truststore.jks
# egrep -v "^$|*#" server.ssl.properties
host.name=192.168.4.39 #本機ip
clustermap.cluster.name=Ambry_Dev
clustermap.datacenter.name=Datacenter
clustermap.host.name=192.168.4.39 #本機ip
ssl.context.protocol=TLS
ssl.context.provider=SunJSSE
ssl.enabled.protocols=TLSv1.2
ssl.endpoint.identification.algorithm=HTTPS
ssl.client.authentication=required
ssl.keystore.type=PKCS12
ssl.keystore.path=/data/ambry/config/keystore.jks #證書路徑
ssl.keystore.password=gicloud
ssl.key.password=gicloud
ssl.truststore.path=/data/ambry/config/truststore.jks #證書路徑
ssl.truststore.password=gicloud
ssl.cipher.suites=
4、前端部署
4.1、前端配置文件
# egrep -v "^$|*#" frontend.properties
rest.server.blob.storage.service.factory=com.github.ambry.frontend.AmbryBlobStorageServiceFactory
router.hostname=192.168.4.39 #本機ip
router.datacenter.name=Datacenter
router.put.success.target=1
router.delete.success.target=1
clustermap.cluster.name=Ambry_Dev
clustermap.datacenter.name=Datacenter
clustermap.host.name=192.168.4.39 #本機ip
kms.default.container.key=B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF
5、啟動
通過編寫腳本的形式啟動
# 服務端
# egrep -v "^$|*#" server.sh
#!/bin/bash
case $1 in
start)
nohup java -Dlog4j.configuration=file:./config/log4j.properties -jar ambry.jar --serverPropsFilePath ./config/server.ssl.properties --hardwareLayoutFilePath ./config/HardwareLayout.json --partitionLayoutFilePath ./config/PartitionLayout.json 1>> logs/server.log 2>> logs/server-error.log &
;;
stop)
pid=`ps -ef|grep ambry|grep -v grep |awk '{print $2}'`
kill -9 $pid
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "usage:$0 {start | stop | restart}"
;;
esac
# 前端
# egrep -v "^$|*#" frontend.sh
#!/bin/bash
case $1 in
start)
nohup java -Dlog4j.configuration=file:./config/log4j.properties -cp "*" com.github.ambry.frontend.AmbryFrontendMain --serverPropsFilePath ./config/frontend.properties --hardwareLayoutFilePath ./config/HardwareLayout.json --partitionLayoutFilePath ./config/PartitionLayout.json 1>> logs/frontend.log 2>> logs/frontend-error.log &
;;
stop)
pid=`ps -ef|grep frontend|grep -v grep |awk '{print $2}'`
kill -9 $pid
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "usage:$0 {start | stop | restart}"
;;
esac
6、測試
6.1、確保前端可以接受請求
# curl http://localhost:1174/healthCheck
GOOD
6.2、上傳
# curl -i -H "x-ambry-blob-size : `wc -c demo.gif | xargs | cut -d" " -f1`" -H "x-ambry-service-id : CUrlUpload" -H "x-ambry-owner-id : `whoami`" -H "x-ambry-content-type : image/gif" -H "x-ambry-um-description : Demonstration Image" http://localhost:1174/ --data-binary @demo.gif
HTTP/1.1 201 Created
Location: AmbryID
Content-Length: 0
curl命令創建一個請求,其中包含 demo.gif 中的二進制數據。與文件數據一起,我們提供充當 blob 屬性的標頭。其中包括 Blob 的大小、服務 ID、所有者 ID 和內容類型。
除了這些屬性之外,Ambry 還提供了任意用戶定義的元數據。我們提供用戶元數據。Ambry 不解釋此數據,它純粹是用于用戶注釋。響應中的標頭是我們剛剛上載的 Blob 的 blob ID。
6.3、驗證
# curl -i http://localhost:1174/AmbryID/BlobInfo
HTTP/1.1 200 OK
x-ambry-blob-size: {Blob size}
x-ambry-service-id: CUrlUpload
x-ambry-creation-time: {Creation time}
x-ambry-private: false
x-ambry-content-type: image/gif
x-ambry-owner-id: {username}
x-ambry-um-desc: Demonstration Image
Content-Length: 0
6.4、獲取
# curl http://localhost:1174/AmbryID > demo-downloaded.gif
# diff demo.gif demo-downloaded.gif
6.5、刪除
Ambry 是一個不可變存儲,無法更新 Blob,但可以刪除它們,以便使其不可恢復 。
# curl -i -X DELETE http://localhost:1174/AmbryID
HTTP/1.1 202 Accepted
Content-Length: 0