Peb twb tham txog lawm
Txaus siab? Tom qab ntawd thov, hauv qab txiav, peb yuav qhia koj thiab qhia koj txhua yam.
Cia peb pib nrog ib qho piv txwv
Peb tsuas yog saib ib feem ntawm kev ua haujlwm ntawm peb lub luag haujlwm. Koj tuaj yeem nrhiav tau tag nrho cov lus piav qhia ntawm tag nrho nws cov peev xwm thiab cov tswv yim tsis nyob hauv
Tarantool Cartridge muaj api
ΠΈ storage
, uas tuaj yeem muab rau cov piv txwv.
Cartridge nws tus kheej tsis hais dab tsi txog yuav ua li cas tso cov txheej txheem, nws tsuas yog muab lub peev xwm los teeb tsa cov xwm txheej uas twb tau ua lawm. Tus neeg siv yuav tsum ua tus so nws tus kheej: npaj cov ntaub ntawv teeb tsa, pib cov kev pabcuam thiab teeb tsa cov topology. Tab sis peb yuav tsis ua txhua yam no; Ansible yuav ua rau peb.
Los ntawm cov lus mus rau deeds
Yog li, cia peb xa peb daim ntawv thov mus rau ob lub tshuab virtual thiab teeb tsa ib qho yooj yim topology:
- Replicaset
app-1
yuav siv lub luag haujlwmapi
, uas suav nrog lub luag haujlwmvshard-router
. Yuav muaj ib qho piv txwv ntawm no xwb. - Replicaset
storage-1
siv lub luag haujlwmstorage
(thiab tib lub sijhawmvshard-storage
), ntawm no peb yuav ntxiv ob qho piv txwv los ntawm cov tshuab sib txawv.
Txhawm rau ua tus piv txwv peb xav tau
Lub luag haujlwm nws tus kheej yog nyob rau hauv
Cia peb clone lub repository nrog ib qho piv txwv:
$ git clone https://github.com/dokshina/deploy-tarantool-cartridge-app.git
$ cd deploy-tarantool-cartridge-app && git checkout 1.0.0
Peb tsa cov tshuab virtual:
$ vagrant up
Nruab Tarantool Cartridge ansible lub luag haujlwm:
$ ansible-galaxy install tarantool.cartridge,1.0.1
Tua tawm lub luag hauj lwm ntsia:
$ ansible-playbook -i hosts.yml playbook.yml
Peb tos rau lub playbook ua kom tiav, mus rau
Koj tuaj yeem upload cov ntaub ntawv. Txias, txoj cai?
Tam sim no cia peb xav txog yuav ua li cas ua haujlwm nrog qhov no, thiab tib lub sijhawm ntxiv lwm qhov kev hloov pauv rau lub topology.
Cia peb pib xav txog nws
Yog li ntawd ua li cas?
Peb teeb tsa ob lub tshuab virtual thiab tso tawm ib phau ntawv ua si uas tau teeb tsa peb pawg. Cia peb saib cov ntsiab lus ntawm cov ntaub ntawv playbook.yml
:
---
- name: Deploy my Tarantool Cartridge app
hosts: all
become: true
become_user: root
tasks:
- name: Import Tarantool Cartridge role
import_role:
name: tarantool.cartridge
Tsis muaj dab tsi nthuav tshwm sim ntawm no, cia peb pib lub luag haujlwm ansible hu ua tarantool.cartridge
.
Txhua yam tseem ceeb tshaj plaws (xws li, pawg teeb tsa) nyob hauv hosts.yml
:
---
all:
vars:
# common cluster variables
cartridge_app_name: getting-started-app
cartridge_package_path: ./getting-started-app-1.0.0-0.rpm # path to package
cartridge_cluster_cookie: app-default-cookie # cluster cookie
# common ssh options
ansible_ssh_private_key_file: ~/.vagrant.d/insecure_private_key
ansible_ssh_common_args: '-o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
# INSTANCES
hosts:
storage-1:
config:
advertise_uri: '172.19.0.2:3301'
http_port: 8181
app-1:
config:
advertise_uri: '172.19.0.3:3301'
http_port: 8182
storage-1-replica:
config:
advertise_uri: '172.19.0.3:3302'
http_port: 8183
children:
# GROUP INSTANCES BY MACHINES
host1:
vars:
# first machine connection options
ansible_host: 172.19.0.2
ansible_user: vagrant
hosts: # instances to be started on the first machine
storage-1:
host2:
vars:
# second machine connection options
ansible_host: 172.19.0.3
ansible_user: vagrant
hosts: # instances to be started on the second machine
app-1:
storage-1-replica:
# GROUP INSTANCES BY REPLICA SETS
replicaset_app_1:
vars: # replica set configuration
replicaset_alias: app-1
failover_priority:
- app-1 # leader
roles:
- 'api'
hosts: # replica set instances
app-1:
replicaset_storage_1:
vars: # replica set configuration
replicaset_alias: storage-1
weight: 3
failover_priority:
- storage-1 # leader
- storage-1-replica
roles:
- 'storage'
hosts: # replica set instances
storage-1:
storage-1-replica:
Txhua yam peb xav tau yog kawm yuav ua li cas tswj cov xwm txheej thiab cov khoom siv rov ua dua los ntawm kev hloov cov ntsiab lus ntawm cov ntaub ntawv no. Tom ntej no peb yuav ntxiv cov ntu tshiab rau nws. Txhawm rau kom tsis txhob nkag siab qhov twg ntxiv rau lawv, koj tuaj yeem saib cov ntawv kawg ntawm cov ntaub ntawv no, hosts.updated.yml
, uas yog nyob rau hauv cov piv txwv repository.
Instance Management
Hauv cov ntsiab lus Ansible, txhua qhov piv txwv yog tus tswv tsev (tsis yog yuav tsum tsis meej pem nrog lub hardware server), i.e. lub infrastructure node uas Ansible yuav tswj. Rau txhua tus tswv tsev peb tuaj yeem hais qhia txog kev sib txuas (xws li ansible_host
ΠΈ ansible_user
), as well as instance configuration. Kev piav qhia ntawm qhov xwm txheej yog nyob rau hauv ntu hosts
.
Cia peb saib qhov piv txwv configuration storage-1
:
all:
vars:
...
# INSTANCES
hosts:
storage-1:
config:
advertise_uri: '172.19.0.2:3301'
http_port: 8181
...
Nyob rau hauv variable config
peb teev cov piv txwv parameter - advertise URI
ΠΈ HTTP port
.
Hauv qab no yog cov piv txwv parameter app-1
ΠΈ storage-1-replica
.
Peb yuav tsum qhia Ansible qhov kev sib txuas tsis tau rau txhua qhov piv txwv. Nws zoo li muaj laj thawj rau pawg piv txwv rau hauv pawg tshuab virtual. Rau lub hom phiaj no, piv txwv yog muab tso rau hauv pab pawg host1
ΠΈ host2
, thiab hauv txhua pab pawg hauv ntu vars
cov nqi yog qhia ansible_host
ΠΈ ansible_user
rau ib lub tshuab virtual. Thiab nyob rau hauv seem hosts
- tus tswv (aka piv txwv) uas suav nrog hauv pab pawg no:
all:
vars:
...
hosts:
...
children:
# GROUP INSTANCES BY MACHINES
host1:
vars:
# first machine connection options
ansible_host: 172.19.0.2
ansible_user: vagrant
hosts: # instances to be started on the first machine
storage-1:
host2:
vars:
# second machine connection options
ansible_host: 172.19.0.3
ansible_user: vagrant
hosts: # instances to be started on the second machine
app-1:
storage-1-replica:
Peb pib hloov hosts.yml
. Cia peb ntxiv ob qho piv txwv ntxiv, storage-2-replica
ntawm thawj lub tshuab virtual thiab storage-2
Ntawm qhov thib ob:
all:
vars:
...
# INSTANCES
hosts:
...
storage-2: # <==
config:
advertise_uri: '172.19.0.3:3303'
http_port: 8184
storage-2-replica: # <==
config:
advertise_uri: '172.19.0.2:3302'
http_port: 8185
children:
# GROUP INSTANCES BY MACHINES
host1:
vars:
...
hosts: # instances to be started on the first machine
storage-1:
storage-2-replica: # <==
host2:
vars:
...
hosts: # instances to be started on the second machine
app-1:
storage-1-replica:
storage-2: # <==
...
Tua tawm lub ansible playbook:
$ ansible-playbook -i hosts.yml
--limit storage-2,storage-2-replica
playbook.yml
Thov nco ntsoov qhov kev xaiv --limit
. Txij li txhua qhov piv txwv yog tus tswv tsev hauv Ansible cov ntsiab lus, peb tuaj yeem qhia meej meej tias qhov xwm txheej twg yuav tsum tau teeb tsa thaum ua tiav phau ntawv ua si.
Rov qab mus rau Web UI
Cia peb tsis txhob tso tseg thiab tswj hwm topology.
Kev tswj hwm topology
Cia peb muab peb cov xwm txheej tshiab rau hauv cov txheej txheem replica storage-2
. Wb ntxiv ib pab pawg tshiab replicaset_storage_2
thiab piav qhia txog qhov hloov pauv tsis tau hauv nws qhov hloov pauv los ntawm kev sib piv nrog replicaset_storage_1
. Hauv seem hosts
Cia peb qhia seb qhov xwm txheej twg yuav suav nrog hauv pab pawg no (uas yog, peb cov txheej txheem rov ua dua):
---
all:
vars:
...
hosts:
...
children:
...
# GROUP INSTANCES BY REPLICA SETS
...
replicaset_storage_2: # <==
vars: # replicaset configuration
replicaset_alias: storage-2
weight: 2
failover_priority:
- storage-2
- storage-2-replica
roles:
- 'storage'
hosts: # replicaset instances
storage-2:
storage-2-replica:
Cia peb pib lub playbook dua:
$ ansible-playbook -i hosts.yml
--limit replicaset_storage_2
--tags cartridge-replicasets
playbook.yml
Rau parameter --limit
Lub sijhawm no peb dhau lub npe ntawm cov pab pawg uas sib haum rau peb qhov kev hloov pauv.
Cia peb xav txog qhov kev xaiv tags
.
Peb lub luag haujlwm ua ntu zus ua ntau yam haujlwm, uas tau cim nrog cov cim hauv qab no:
cartridge-instances
: kev tswj piv txwv (kev teeb tsa, kev sib txuas rau kev ua tswv cuab);cartridge-replicasets
: topology kev tswj hwm (replicaset tswj thiab tshem tawm mus tas li (tawm) ntawm cov xwm txheej los ntawm pawg);cartridge-config
: kev tswj hwm ntawm lwm qhov tsis sib xws (vshard bootstrapping, hom tsis siv neeg tsis siv neeg, kev tso cai tsis pub dhau thiab daim ntawv thov teeb tsa).
Peb tuaj yeem qhia meej meej txog qhov twg ntawm txoj haujlwm peb xav ua, tom qab ntawd lub luag haujlwm yuav hla lwm cov haujlwm. Hauv peb qhov xwm txheej, peb xav ua haujlwm nrog cov topology nkaus xwb, yog li peb tau teev tseg cartridge-replicasets
.
Cia peb ntsuas qhov tshwm sim ntawm peb qhov kev siv zog. Peb nrhiav tau ib tug tshiab replicaset rau
Ntxawm!
Kev sim nrog kev hloov pauv ntawm cov xwm txheej thiab cov txheej txheem replica thiab saib seb cov pawg topology hloov li cas. Koj tuaj yeem sim tawm cov xwm txheej ua haujlwm sib txawv, piv txwv li. memtx_memory
. Lub luag haujlwm yuav sim ua qhov no yam tsis tau rov pib dua qhov piv txwv txhawm rau txo qis qhov ua tau ntawm koj daim ntawv thov.
Tsis txhob hnov ββqab khiav vagrant halt
kom nres lub tshuab virtual thaum koj ua tiav nrog lawv.
Hauv qab hood yog dab tsi?
Ntawm no kuv yuav qhia koj ntxiv txog dab tsi tshwm sim nyob rau hauv lub hood ntawm lub luag hauj lwm ansible thaum peb sim.
Cia peb saib ntawm kev xa cov ntawv thov Cartridge ib kauj ruam.
Txhim kho lub pob thiab pib ua piv txwv
Ua ntej koj yuav tsum xa cov pob rau lub server thiab nruab nws. Tam sim no lub luag haujlwm tuaj yeem ua haujlwm nrog RPM thiab DEB pob.
Tom ntej no peb tso cov piv txwv. Txhua yam yooj yim heev ntawm no: txhua qhov piv txwv yog cais systemd
- kev pabcuam. Kuv yuav muab piv txwv rau koj:
$ systemctl start myapp@storage-1
Cov lus txib no yuav qhib qhov piv txwv storage-1
apps myapp
. Qhov tshwm sim yuav nrhiav nws /etc/tarantool/conf.d/
. Cov ntaub ntawv piv txwv tuaj yeem pom siv journald
.
Unit ntaub ntawv /etc/systemd/system/[email protected]
rau kev pabcuam systemd yuav raug xa nrog rau pob.
Ansible muaj built-in modules rau kev txhim kho cov pob khoom thiab tswj cov kev pabcuam systemd; peb tsis tau tsim ib yam tshiab ntawm no.
Teem ib pawg topology
Qhov no yog qhov kev lom zem pib. Pom zoo, nws yuav coj txawv txawv rau thab nrog lub luag haujlwm tshwj xeeb Ansible rau kev txhim kho pob khoom thiab khiav systemd
-services.
Koj tuaj yeem configure pawg manually:
- Thawj qhov kev xaiv: qhib Web UI thiab nyem rau ntawm cov nyees khawm. Nws yog qhov tsim nyog rau kev pib ib zaug ntawm ntau zaus.
- Qhov kev xaiv thib ob: koj tuaj yeem siv GraphQl API. Ntawm no koj tuaj yeem hloov kho qee yam, piv txwv li, sau ib tsab ntawv hauv Python.
- Qhov kev xaiv thib peb (rau qhov muaj zog-willed): mus rau tus neeg rau zaub mov, txuas rau ib qho piv txwv siv
tarantoolctl connect
thiab ua txhua yam tsim nyog manipulations nrog Lua modulecartridge
.
Lub luag haujlwm tseem ceeb ntawm peb qhov kev tsim khoom yog ua raws nraim qhov no, qhov nyuaj tshaj plaws ntawm kev ua haujlwm rau koj.
Ansible tso cai rau koj sau koj tus kheej module thiab siv nws hauv lub luag haujlwm. Peb lub luag haujlwm siv cov qauv zoo li no los tswj ntau pawg pawg.
Nws ua haujlwm li cas? Koj piav qhia txog lub xeev xav tau ntawm pawg hauv kev tshaj tawm kev teeb tsa, thiab lub luag haujlwm muab txhua qhov module nrog nws qhov kev teeb tsa raws li kev nkag. Lub module tau txais lub xeev tam sim no ntawm pawg thiab muab piv rau qhov uas tau txais los ntawm cov tswv yim. Tom ntej no, ib qho chaws raug tso tawm los ntawm lub qhov (socket) ntawm ib qho ntawm cov xwm txheej, uas coj cov pawg mus rau lub xeev xav tau.
Cov txiaj ntsim tau los
Hnub no peb tau qhia thiab qhia yuav ua li cas xa koj daim ntawv thov mus rau Tarantool Cartridge thiab teeb tsa ib qho yooj yim topology. Txhawm rau ua qhov no, peb siv Ansible - lub cuab yeej muaj zog uas siv tau yooj yim thiab tso cai rau koj los teeb tsa ntau lub hauv paus (hauv peb qhov xwm txheej, pawg).
Saum toj no peb saib ntawm ib qho ntawm ntau txoj hauv kev los piav qhia txog kev teeb tsa pawg siv Ansible. Thaum koj xav tias npaj mus ntxiv, tshawb nrhiav group_vars
ΠΈ host_vars
.
Tsis ntev dhau los peb yuav qhia koj yuav ua li cas tshem tawm mus tas li (tawm) cov xwm txheej los ntawm topology, bootstrap vshard, tswj tsis siv neeg tsis siv neeg ua haujlwm, teeb tsa kev tso cai thiab kho cov pawg teeb tsa. Lub sijhawm no, koj tuaj yeem kawm ntawm koj tus kheej
Yog tias ib yam dab tsi tsis ua haujlwm, nco ntsoov
Tau qhov twg los: www.hab.com