dist. system
Zookeeper를 이용한 분산 시스템 공용 데이터 관리
식피두
2020. 11. 3. 11:48
이미지 검색 시스템이 있고, 시스템 자체가 여러 대의 클러스터로 구성되어 있다.
특정 인물의 처리를 무시하기 위해서 PASS_LIST를 두어 공용으로 관리하고 싶은데
무겁게 DB까지는 쓸 필요가 없이,
주키퍼를 이용해서 노드를 만들어 놓고 데이터를 저장/접근하면 된다.
(이미 주키퍼 앙상블이 구축되어 있다고 가정)
이후에, 모든 클러스터에서 주키퍼 앙상블에 접속하여 해당 노드에 저장된 값을 얻어서
의도된 작업을 수행하면 된다.
ex) /abcsystem/passlist
python client가 필요했기 때문에
kazoo.readthedocs.io/en/latest/basic_usage.html
Basic Usage — kazoo 2.6.0 documentation
To begin using Kazoo, a KazooClient object must be created and a connection established: By default, the client will connect to a local Zookeeper server on the default port (2181). You should make sure Zookeeper is actually running there first, or the star
kazoo.readthedocs.io
kazoo 라이브러리를 사용하였다.
import ujson
from kazoo.client import KazooClient
zk = KazooClient(hosts='127.0.0.1:2181') # , read_only=True)
zk.start()
pass_list_path = "/abcsystem/passlist"
pass_list = "송제인,박경수,김찬란,박민우,이재경,브재훈,브조"
if not zk.ensure_path(pass_list_path):
zk.create(pass_list_path)
zk.set(pass_list_path, pass_list.encode())
res = zk.get(pass_list_path)
pass_list = res[0].decode()
print(pass_list)