Thank you for reading this post, don't forget to subscribe!
Ниже будут танцы с бубном для запуска in-memory database apache ignite
https://apacheignite-tools.readme.io/
https://hub.docker.com/u/apacheignite
1.Создаём сеть:
docker network create --driver overlay ignite
2.Выкачиваем образ:
docker pull apacheignite/web-console-standalone:2.7.0
перетегируем чтоб добавить в гитлаб
docker tag apacheignite/web-console-standalone:2.7.0 gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0
пушим образ в гитлаб:
docker push gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0
3.Создаём директорию в которой уже будет весь наш стек:
mkdir apache-ignite
В этой директории создадим файл settings.js с настройками для нашего бекенда(он нужен только для того, чтобы порт 3000 слушал 0,0,0,0 а не только 127,0,0,1, но чтобы это работало необходимо ещё и в переменные добавить server_host=0.0.0.0)
cat settings.js
[codesyntax lang="php" blockstate="collapsed"]
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 |
<span style="font-size: 12pt; font-family: arial, helvetica, sans-serif;">/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; const fs = require('fs'); // Fire me up! /** * Module with server-side configuration. */ module.exports = { implements: 'settings', inject: ['nconf'], factory(nconf) { /** * Normalize a port into a number, string, or false. */ const _normalizePort = function(val) { const port = parseInt(val, 10); // named pipe if (isNaN(port)) return val; // port number if (port >= 0) return port; return false; }; const mail = nconf.get('mail') || {}; const packaged = __dirname.startsWith('/snapshot/') || __dirname.startsWith('C:\\snapshot\\'); const dfltAgentDists = packaged ? 'libs/agent_dists' : 'agent_dists'; const dfltHost = packaged ? '0.0.0.0' : '127.0.0.1'; const dfltPort = packaged ? 80 : 3000; return { agent: { dists: nconf.get('agent:dists') || dfltAgentDists }, packaged, server: { host: nconf.get('server:host') || dfltHost, port: _normalizePort(nconf.get('server:port') || dfltPort), SSLOptions: nconf.get('server:ssl') && { enable301Redirects: true, trustXFPHeader: true, key: fs.readFileSync(nconf.get('server:key')), cert: fs.readFileSync(nconf.get('server:cert')), passphrase: nconf.get('server:keyPassphrase') } }, mail, mongoUrl: nconf.get('mongodb:url') || 'mongodb://127.0.0.1/console', cookieTTL: 3600000 * 24 * 30, sessionSecret: nconf.get('server:sessionSecret') || 'keyboard cat', tokenLength: 20 }; } }; </span> |
[/codesyntax]
4.Создадим файл с нашим стеком:
cat swarm-ignite.yml
[codesyntax lang="php" blockstate="collapsed"]
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
version: '3.4' services: ignite1: image: gitnexus.test.local:4567/swarm/apache-ignite/web-ignite ports: - target: 10800 published: 10800 protocol: tcp mode: host - target: 47500 published: 47500 protocol: tcp mode: host # volumes: # - ignite1:/opt/ignite/apache-ignite/work networks: - ignite hostname: ignite1 environment: - OPTION_LIBS=ignite-rest-http deploy: mode: replicated replicas: 1 update_config: parallelism: 1 delay: 10s order: start-first # configs: # - source: config.xml # target: /opt/ignite/apache-ignite/config/ignite-config.xml ignite2: image: gitnexus.test.local:4567/swarm/apache-ignite/web-ignite ports: - target: 10800 published: 10800 protocol: tcp mode: host - target: 47500 published: 47500 protocol: tcp mode: host # volumes: # - ignite2:/opt/ignite/apache-ignite/work networks: - ignite hostname: ignite2 environment: - OPTION_LIBS=ignite-rest-http deploy: mode: replicated replicas: 1 update_config: parallelism: 1 delay: 10s order: start-first # configs: # - source: config.xml # target: /opt/ignite/apache-ignite/config/ignite-config.xml ignite3: image: gitnexus.test.local:4567/swarm/apache-ignite/web-ignite ports: - target: 10800 published: 10800 protocol: tcp mode: host - target: 47500 published: 47500 protocol: tcp mode: host # volumes: # - ignite3:/opt/ignite/apache-ignite/work networks: - ignite hostname: ignite3 environment: - OPTION_LIBS=ignite-rest-http deploy: mode: replicated replicas: 1 update_config: parallelism: 1 delay: 10s order: start-first # configs: # - source: config.xml # target: /opt/ignite/apache-ignite/config/ignite-config.xml agent: image: gitnexus.test.local:4567/swarm/apache-ignite/web-agent deploy: mode: replicated replicas: 1 update_config: parallelism: 1 delay: 10s order: start-first environment: - DRIVER_FOLDER=./jdbc-drivers - SERVER_URI=http://backend:3000 - NODE_URI=http://ignite1:8080,http://ignite2:8080,http://ignite3:8080 - TOKENS=calnof9OY9jp695ECbaH networks: - ignite backend: image: gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0 hostname: backend deploy: mode: replicated replicas: 1 update_config: parallelism: 1 delay: 10s order: start-first # ports: # - "80:80" # - "3000:3000" # - "3001:3001" networks: - ignite - proxy environment: - server_port=3000 - server_host=0.0.0.0 - server_sessionSecret=CHANGE ME - mail_service= - mail_sign= - mail_greeting= - mail_from= - mail_auth_user= - mail_auth_pass= configs: - source: settings.js target: /opt/web-console/backend/app/settings.js deploy: mode: replicated replicas: 1 update_config: parallelism: 1 delay: 10s order: start-first labels: - com.df.notify=true - com.df.serviceDomain=ignite.swarm.test.local - com.df.port=80 # volumes: # - mongo:/data/db #volumes: # ignite1: # driver: "rexray/rbd:latest" # driver_opts: # size: 2 # ignite2: # driver: "rexray/rbd:latest" # driver_opts: # size: 2 # ignite3: # driver: "rexray/rbd:latest" # driver_opts: # size: 2 # mongo: # driver: "rexray/rbd:latest" # driver_opts: # size: 1 configs: # config.xml: # file: ./ignite-config.xml settings.js: file: ./settings.js networks: ignite: external: true proxy: external: true |
[/codesyntax]
5.Запускаем его:
docker stack deploy -c swarm-ignite.yml ignite --with-registry-auth
у нас будет работать только 1 сервис, наш бекенд.
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
tkdj3ezz393b ignite_agent replicated 0/1 gitnexus.test.local:4567/swarm/apache-ignite/web-agent
h75fy9cn0ljs ignite_backend replicated 1/1 gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0 *:80->80/tcp, *:3000-3001->3000-3001/tcp
vc6mhn0tz303 ignite_ignite1 replicated 0/1 gitnexus.test.local:4567/swarm/apache-ignite/web-ignite:latest
m86b2v880mqu ignite_ignite2 replicated 0/1 gitnexus.test.local:4567/swarm/apache-ignite/web-ignite:latest
x9i6aojpqo8j ignite_ignite3 replicated 0/1 gitnexus.test.local:4567/swarm/apache-ignite/web-ignite:latest
6.Выкачиваем агента который позволит нам работать с кластером:
заходим в контейнер:
[root@node1 apache-ignite]# docker service ps ignite_backend
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
qtl2jc6ut7k1 ignite_backend.1 gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0 node1 Running Running 8 minutes ago
[root@node1 apache-ignite]# docker ps | grep ignite_backend
58a43ccfe953 gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0 "/opt/web-console/do…" 8 minutes ago Up 8 minutes 80/tcp ignite_backend.1.qtl2jc6ut7k1l95j9uwliwvrr
[root@node1 apache-ignite]# docker exec -ti 58a43ccfe953 bash
Находим архив с агентом:
root@58a43ccfe953:/opt/web-console# find / -name ignite-web-agent*
/opt/web-console/backend/agent_dists/ignite-web-agent-2.7.0.zip
Выходим:
root@58a43ccfe953:/opt/web-console# exit
скачиваем его на хостовую ноду:
[root@node1 apache-ignite]# docker cp 58a43ccfe953:/opt/web-console/backend/agent_dists/ignite-web-agent-2.7.0.zip .
Распаковываем:
[root@node1 apache-ignite]# unzip ignite-web-agent-2.7.0.zip
В файле:
[root@node1 apache-ignite]# vim ignite-web-agent-2.7.0/ignite-web-agent.sh
правим строку:
source "${IGNITE_HOME}"/include/functions.sh
на
source ${IGNITE_HOME}/functions.sh
После чего добавляем следующий Dockerfile:
[root@node1 apache-ignite]# cat ignite-web-agent-2.7.0/Dockerfile
[codesyntax lang="php" blockstate="collapsed"]
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 |
<span style="font-size: 12pt; font-family: arial, helvetica, sans-serif;">FROM openjdk:8-jre-alpine # Provide default arguments ARG DEFAULT_DRIVER_FOLDER="/opt/ignite/drivers" ARG DEFAULT_NODE_URI="http://localhost:8080" ARG DEFAULT_SERVER_URI="http://localhost" ARG DEFAULT_TOKENS="NO_TOKENS" ENV DRIVER_FOLDER=$DEFAULT_DRIVER_FOLDER ENV NODE_URI=$DEFAULT_NODE_URI ENV SERVER_URI=$DEFAULT_SERVER_URI ENV TOKENS=$DEFAULT_TOKENS # Settings USER root ENV AGENT_HOME /opt/ignite/ignite-web-agent WORKDIR ${AGENT_HOME} # Add missing software RUN apk --no-cache \ add bash # Copy main binary archive COPY * ./ # Entrypoint CMD ./ignite-web-agent.sh -d ${DRIVER_FOLDER} -n ${NODE_URI} -s ${SERVER_URI} -t ${TOKENS} </span> |
[/codesyntax]
Далее билдим образ:
[root@node1 ignite-web-agent-2.7.0]# docker build -t gitnexus.test.local:4567/swarm/apache-ignite/web-agent .
Пушим его в гитлаб:
docker push gitnexus.test.local:4567/swarm/apache-ignite/web-agent
7.Далее заходим по домену или ip адресу, нажимаем sign up
Заполняем поля:
sign up
Create cluster configuration
Advanced
Discovery: Static Ips
Addresses:
ignite1:47500..47510
Ignite2:47500..47510
Ignite3:47500..47510
Если нужно будет настроить хранение данных, то проматываем вниз до:
"Data storage configuration" включаем "Persistence enabled" и настраиваем конфигурацию, а в стеке прокидываем вольюм
volumes:
- ignite1:/opt/ignite/apache-ignite/work
(для каждого из инстансов)
после чего нажимаем на расширенную часть save и выбираем save and download
Будет скачан архив Cluster-project.zip
создаём для него директорию: mkdir ignite_nodes
загружаем архив на сервер в эту директорию, и распаковываем:
unzip Cluster-project.zip
Далее билдим образ:
docker build -t gitnexus.test.local:4567/swarm/apache-ignite/web-ignite .
(билдить лучше на сервере с прямым доступом в нет так как прокси в mvn не получилось подтянуть)
пушим:
docker push gitnexus.test.local:4567/swarm/apache-ignite/web-ignite:latest
всё теперь у нас появилось в гитлабе 3 образа, это:
backend:
gitnexus.test.local:4567/swarm/apache-ignite/web-console-standalone:2.7.0
agent:
gitnexus.test.local:4567/swarm/apache-ignite/web-agent
Ignite:
gitnexus.test.local:4567/swarm/apache-ignite/web-ignite
8.Смотрим токен, для этого нажимаем на имя кластера, -> Profile
Show security token
копируем токен, y0kWMLkQglgEt7UdJfI7 и добавляем его в наш стек swarm-ignite.yml, к сервису agent
[codesyntax lang="php"]
1 2 3 4 5 6 7 8 9 |
<span style="font-size: 12pt; font-family: arial, helvetica, sans-serif;"> agent: image: gitnexus.test.local:4567/swarm/apache-ignite/web-agent environment: - DRIVER_FOLDER=./jdbc-drivers - SERVER_URI=http://backend:3000 - NODE_URI=http://ignite1:8080,http://ignite2:8080,http://ignite3:8080 - TOKENS=<strong>y0kWMLkQglgEt7UdJfI7</strong> networks: - ignite</span> |
[/codesyntax]
9.Удаляем сервисы:
[root@node1 apache-ignite]# docker service rm ignite_agent ignite_ignite1 ignite_ignite2 ignite_ignite3
и повторно деплоим наш стек:
[root@node1 apache-ignite]# docker stack deploy -c swarm-ignite.yml ignite --with-registry-auth
10.Проверяем
Смотрим по логам:
- что кластер видит все сервера:
[root@node1 apache-ignite]# docker service logs ignite_ignite1 | grep servers
ignite_ignite1.1.nxrgmzppxk5y@node3 | [06:31:38] New version is available at ignite.apache.org: 2.7.6
ignite_ignite1.1.nxrgmzppxk5y@node3 | [06:31:38] Topology snapshot [ver=3, locNode=a40d49cd, servers=3, clients=0, state=ACTIVE, CPUs=6, offheap=2.2GB, heap=3.0GB]
- что агент нормально подцепился:
[root@node1 apache-ignite]# docker service logs ignite_agent
ignite_agent.1.qb2kxa6nvbkp@node1 | [2020-02-19 06:31:01,790][INFO ][main][AgentLauncher] Starting Apache Ignite Web Console Agent…
ignite_agent.1.qb2kxa6nvbkp@node1 | [2020-02-19 06:31:02,087][WARN ][main][AgentLauncher] Failed to find agent property file: default.properties
ignite_agent.1.qb2kxa6nvbkp@node1 |
ignite_agent.1.qb2kxa6nvbkp@node1 | Agent configuration:
ignite_agent.1.qb2kxa6nvbkp@node1 | User's security tokens : ****************JfI7
ignite_agent.1.qb2kxa6nvbkp@node1 | URI to Ignite node REST server : http://ignite1:8080, http://ignite2:8080, http://ignite3:8080
ignite_agent.1.qb2kxa6nvbkp@node1 | URI to Ignite Console server : http://backend:3000
ignite_agent.1.qb2kxa6nvbkp@node1 | Path to agent property file : default.properties
ignite_agent.1.qb2kxa6nvbkp@node1 | Path to JDBC drivers folder : ./jdbc-drivers
ignite_agent.1.qb2kxa6nvbkp@node1 | Demo mode : enabled
ignite_agent.1.qb2kxa6nvbkp@node1 |
ignite_agent.1.qb2kxa6nvbkp@node1 | [2020-02-19 06:31:02,542][INFO ][main][AgentLauncher] Connecting to: http://backend:3000
ignite_agent.1.qb2kxa6nvbkp@node1 | [2020-02-19 06:31:02,734][INFO ][EventThread][AgentLauncher] Connection established.
ignite_agent.1.qb2kxa6nvbkp@node1 | [2020-02-19 06:31:02,837][INFO ][EventThread][AgentLauncher] Authentication success.
В панели мы увидим, что появился подключённый кластер:
Если необходимо активировать кластер без веб панели то заходим на любой поднятый контейнер кластера и активируем кластер:
$IGNITE_HOME/bin/control.sh –activate
Режим проверки
./ignitevisorcmd.sh
Чтобы проверить записи в таблицах:
cd apache-ignite/bin
./sqlline.sh --verbose=true -u jdbc:ignite:thin://127.0.0.1
!tables покажет все таблицы