Docker Swarm e Service Mode para criar o cluster do Couchbase explicou como criar um cluster do Couchbase usando o Docker. Ele usou o conceito de um serviço "mestre" e um "trabalhador" para simplificar e automatizar a criação do cluster. O cluster homogêneo foi então criado conforme mostrado no diagrama de arquitetura abaixo:

Detalhes completos e histórico estão no Cluster do Couchbase usando o Docker blog.
Docker 1.13 foi lançado na semana passada. Um novo recurso dessa versão permite implantar aplicativo de vários contêineres definido usando o Docker Compose em vários hosts habilitado usando o modo Swarm. Idealmente, gostaríamos de ter um único Docker Compose que permite iniciar o serviço "mestre" e iniciar/escalar o serviço "de trabalho". Mas o serviço "mestre" e, mais importante, o contêiner dentro do serviço, precisa estar totalmente ativo antes que o serviço "de trabalho" possa ser iniciado. Isso ocorre porque os contêineres no serviço "worker" se registram com o contêiner no serviço "master" para criar o cluster. Isso normalmente exige um pouco de trabalho manual, conforme definido em Controle da ordem de inicialização no Compose. Portanto, voltaremos a essa versão mais tarde.
Este blog fornecerá uma rápida atualização das etapas do original usando o Docker 1.13. Leia este blog para saber rapidamente como e o que fazer. blog original para obter mais detalhes sobre o motivo.
Criar rede:
|
1 2 3 |
docker network create -d overlay couchbase |
Verifique a rede criada usando docker network ls comando:
|
1 2 3 4 5 6 7 |
NETWORK ID NAME DRIVER SCOPE 20a28d56f140 bridge bridge local 5maq7fyqdemx couchbase overlay swarm cd14345ec130 docker_gwbridge bridge local 46a19cdead82 host host local p1kbq62oxmn9 ingress overlay swarm 1b64333f45ec none null local |
Crie o serviço "mestre" do Couchbase:
|
1 2 3 4 5 6 7 |
docker service create --name couchbase-master --replicas 1 -p 8091:8091 --network couchbase -e TYPE=MASTER arungupta/couchbase |
Verifique o serviço criado usando serviço docker ls comando:
|
1 2 |
ID NAME MODE REPLICAS IMAGE v5m0owjs4qo3 couchbase-master replicated 1/1 arungupta/couchbase:latest |
Criar o serviço "worker" do Couchbase:
|
1 2 3 4 5 6 7 8 |
docker service create --name couchbase-worker --replicas 1 --network couchbase -e TYPE=WORKER -e COUCHBASE_MASTER=couchbase-master.couchbase -e AUTO_REBALANCE=false arungupta/couchbase |
Verifique novamente o serviço criado usando serviço docker ls comando:
|
1 2 3 |
ID NAME MODE REPLICAS IMAGE v5m0owjs4qo3 couchbase-master replicated 1/1 arungupta/couchbase:latest zqqqk76cu1jw couchbase-worker replicated 1/1 arungupta/couchbase:latest |
Verifique os registros do serviço de trabalho usando o novo comando introduzido Registros de serviço do docker couchbase-worker comando. Esse comando, introduzido recentemente no Docker 1.13, extrai logs de todos os contêineres no serviço e os transmite para o seu console. Não há necessidade de rastrear quais contêineres estão sendo executados em quais hosts.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
couchbase-worker.1.3x52hro26166@moby | ++ set -m couchbase-worker.1.3x52hro26166@moby | ++ sleep 15 couchbase-worker.1.3x52hro26166@moby | ++ /entrypoint.sh couchbase-server couchbase-worker.1.3x52hro26166@moby | Starting Couchbase Server -- Web UI available at https://:8091 and logs available in /opt/couchbase/var/lib/couchbase/logs couchbase-worker.1.3x52hro26166@moby | ++ curl -v -X POST https://127.0.0.1:8091/pools/default -d memoryQuota=300 -d indexMemoryQuota=300 couchbase-worker.1.3x52hro26166@moby | Note: Unnecessary use of -X or --request, POST is already inferred. couchbase-worker.1.3x52hro26166@moby | * Trying 127.0.0.1... couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-worker.1.3x52hro26166@moby | > POST /pools/default HTTP/1.1 couchbase-worker.1.3x52hro26166@moby | > Host: 127.0.0.1:8091 couchbase-worker.1.3x52hro26166@moby | > User-Agent: curl/7.49.1-DEV couchbase-worker.1.3x52hro26166@moby | > Accept: */* couchbase-worker.1.3x52hro26166@moby | > Content-Length: 36 couchbase-worker.1.3x52hro26166@moby | > Content-Type: application/x-www-form-urlencoded couchbase-worker.1.3x52hro26166@moby | > couchbase-worker.1.3x52hro26166@moby | } [36 bytes data] couchbase-worker.1.3x52hro26166@moby | * upload completely sent off: 36 out of 36 bytes couchbase-worker.1.3x52hro26166@moby | < HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | < Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | < Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | < Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | < Content-Length: 0 couchbase-worker.1.3x52hro26166@moby | < Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | < 100 36 0 0 100 36 0 13057 --:--:-- --:--:-- --:--:-- 18000 couchbase-worker.1.3x52hro26166@moby | * Connection #0 to host 127.0.0.1 left intact couchbase-worker.1.3x52hro26166@moby | ++ curl -v https://127.0.0.1:8091/node/controller/setupServices -d services=kv%2Cn1ql%2Cindex couchbase-worker.1.3x52hro26166@moby | * Trying 127.0.0.1... couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-worker.1.3x52hro26166@moby | > POST /node/controller/setupServices HTTP/1.1 couchbase-worker.1.3x52hro26166@moby | > Host: 127.0.0.1:8091 couchbase-worker.1.3x52hro26166@moby | > User-Agent: curl/7.49.1-DEV couchbase-worker.1.3x52hro26166@moby | > Accept: */* couchbase-worker.1.3x52hro26166@moby | > Content-Length: 26 couchbase-worker.1.3x52hro26166@moby | > Content-Type: application/x-www-form-urlencoded couchbase-worker.1.3x52hro26166@moby | > couchbase-worker.1.3x52hro26166@moby | } [26 bytes data] couchbase-worker.1.3x52hro26166@moby | * upload completely sent off: 26 out of 26 bytes couchbase-worker.1.3x52hro26166@moby | < HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | < Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | < Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | < Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | < Content-Length: 0 couchbase-worker.1.3x52hro26166@moby | < Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | < 100 26 0 0 100 26 0 13171 --:--:-- --:--:-- --:--:-- 26000 couchbase-worker.1.3x52hro26166@moby | * Connection #0 to host 127.0.0.1 left intact couchbase-worker.1.3x52hro26166@moby | ++ curl -v https://127.0.0.1:8091/settings/web -d port=8091 -d username=Administrator -d password=password couchbase-worker.1.3x52hro26166@moby | * Trying 127.0.0.1... couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-worker.1.3x52hro26166@moby | > POST /settings/web HTTP/1.1 couchbase-worker.1.3x52hro26166@moby | > Host: 127.0.0.1:8091 couchbase-worker.1.3x52hro26166@moby | > User-Agent: curl/7.49.1-DEV couchbase-worker.1.3x52hro26166@moby | > Accept: */* couchbase-worker.1.3x52hro26166@moby | > Content-Length: 50 couchbase-worker.1.3x52hro26166@moby | > Content-Type: application/x-www-form-urlencoded couchbase-worker.1.3x52hro26166@moby | > couchbase-worker.1.3x52hro26166@moby | } [50 bytes data] couchbase-worker.1.3x52hro26166@moby | * upload completely sent off: 50 out of 50 bytes couchbase-worker.1.3x52hro26166@moby | < HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | < Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | < Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | < Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | < Content-Type: application/json couchbase-worker.1.3x52hro26166@moby | < Content-Length: 39 couchbase-worker.1.3x52hro26166@moby | < Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | < couchbase-worker.1.3x52hro26166@moby | { [39 bytes data] 100 89 100 39 100 50 3423 4389 --:--:-- --:--:-- --:--:-- 4545 couchbase-worker.1.3x52hro26166@moby | * Connection #0 to host 127.0.0.1 left intact couchbase-worker.1.3x52hro26166@moby | ++ curl -i -u Administrator:password -X POST https://127.0.0.1:8091/settings/indexes -d storageMode=memory_optimized couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 100 180 100 152 100 28 13264 2443 --:--:-- --:--:-- --:--:-- 13818 couchbase-worker.1.3x52hro26166@moby | {"newBaseUri":"https://127.0.0.1:8091/"}HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | Content-Type: application/json couchbase-worker.1.3x52hro26166@moby | Content-Length: 152 couchbase-worker.1.3x52hro26166@moby | Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | couchbase-worker.1.3x52hro26166@moby | ++ echo 'Type: WORKER' couchbase-worker.1.3x52hro26166@moby | ++ '[' WORKER = WORKER ']' couchbase-worker.1.3x52hro26166@moby | ++ echo 'Sleeping ...' couchbase-worker.1.3x52hro26166@moby | ++ sleep 15 couchbase-worker.1.3x52hro26166@moby | {"storageMode":"memory_optimized","indexerThreads":0,"memorySnapshotInterval":200,"stableSnapshotInterval":5000,"maxRollbackPoints":5,"logLevel":"info"}Type: WORKER couchbase-worker.1.3x52hro26166@moby | Sleeping ... couchbase-worker.1.3x52hro26166@moby | +++ hostname -I couchbase-worker.1.3x52hro26166@moby | +++ cut -d ' ' -f1 couchbase-worker.1.3x52hro26166@moby | ++ IP=10.0.0.5 couchbase-worker.1.3x52hro26166@moby | ++ echo 'IP: ' 10.0.0.5 couchbase-worker.1.3x52hro26166@moby | ++ echo 'Auto Rebalance: false' couchbase-worker.1.3x52hro26166@moby | IP: 10.0.0.5 couchbase-worker.1.3x52hro26166@moby | ++ '[' false = true ']' couchbase-worker.1.3x52hro26166@moby | ++ couchbase-cli server-add --cluster=couchbase-master.couchbase:8091 --user=Administrator --password=password --server-add=10.0.0.5 --server-add-username=Administrator --server-add-password=password couchbase-worker.1.3x52hro26166@moby | Auto Rebalance: false couchbase-worker.1.3x52hro26166@moby | Warning: Adding server from group-manage is deprecated couchbase-worker.1.3x52hro26166@moby | Server 10.0.0.5:8091 added couchbase-worker.1.3x52hro26166@moby | ++ fg 1 couchbase-worker.1.3x52hro26166@moby | /entrypoint.sh couchbase-server |
Os registros completos mostram como o serviço "worker" foi criado e se juntou ao cluster originalmente criado pelo "master".
Dimensione o cluster dimensionando o serviço do Docker:
|
1 |
docker service scale couchbase-worker=2 |
Verifique o serviço novamente usando serviço docker ls comando:
|
1 2 3 |
ID NAME MODE REPLICAS IMAGE v5m0owjs4qo3 couchbase-master replicated 1/1 arungupta/couchbase:latest zqqqk76cu1jw couchbase-worker replicated 2/2 arungupta/couchbase:latest |
Agora você tem um cluster do Couchbase de três nós. Antes de rebalanceamento do clusterVamos verificar rapidamente o que faz Console da Web do Couchbase shows.
O Console da Web do Couchbase pode ser acessado em https://localhost:8091 e mostra um único nó do Couchbase com dados, índice e serviço de consulta. Esse nó foi criado usando o serviço "master". Dois nós adicionais criados usando o serviço "worker" são mostrados em Rebalanceamento pendente guia:

Clique em Rebalance para reequilíbrio o cluster e veja o cluster totalmente rebalanceado:

Quer começar a usar o Couchbase? Dê uma olhada em Kits iniciais do Couchbase.
Deseja saber mais sobre como executar o Couchbase em contêineres?
[...] também pode considerar a execução do Couchbase Cluster usando o Docker ou ler mais sobre Implantação de serviços do Docker para [...]