Postgres
Содержание
Развёртываем 30 контейнеров на Альт Рабочая станция 10
Обновим систему и установим docker
Включим ssh сервер
systemctl enable sshd systemctl start sshd
Создадим скрипты развёртывания и уничтожения
cat /opt/create-x30-containers.sh
#!/bin/bash rm /tmp/cred port=54320 for i in `seq -w 1 30`; do port=$((port+1)) docker run \ --name postgres-srv-$i \ -e POSTGRES_USER="dbuser${i}" \ -e POSTGRES_PASSWORD="dbpass${i}" \ -e POSTGRES_DB="database${i}" \ -p $port:5432 \ -d \ postgres:11 echo "psql -h localhost -p ${port} -U dbuser${i} database${i} # password=dbpass${i}" >> /tmp/cred done echo "Credentials: " echo "-----" cat /tmp/cred echo "-----" #install postgresql 14 client on alt workstation 10 #apt-get install postgresql14 #connect example from dockerhost #psql -h localhost -p 54321 -U dbuser01 database01 #connect example from some host (where 172.16.228.138 -- remote address of dockerhost) #psql -h 172.16.228.138 -p 54321 -U dbuser01 database01
cat /opt/destroy-x30-containers.sh
#!/bin/bash for i in `seq -w 1 30`; do docker stop postgres-srv-$i docker rm postgres-srv-$i done
Примеры
Установить только клиент для postgresql 14 для Альт Рабочая станция 10 (или любого дистрибутива на базе P10)
apt-get install postgresql14
Пример подключения к базе данных непосредственно с docker хоста
psql -h localhost -p 54321 -U dbuser01 database01
далее нужно будет ввести пароль
Пример подключения к базе данных с любого хоста
Представим, что наш докерхост имеет ip адрес 172.16.228.138, тогда на машине, с которой мы собираемся подключаться, для подключения к базе данных команда будет такая:
psql -h 172.16.228.138 -p 54321 -U dbuser01 database01
далее нужно будет ввести пароль
Список из 30 хостов
psql -h localhost -p 54321 -U dbuser01 database01 # password=dbpass01 psql -h localhost -p 54322 -U dbuser02 database02 # password=dbpass02 psql -h localhost -p 54323 -U dbuser03 database03 # password=dbpass03 psql -h localhost -p 54324 -U dbuser04 database04 # password=dbpass04 psql -h localhost -p 54325 -U dbuser05 database05 # password=dbpass05 psql -h localhost -p 54326 -U dbuser06 database06 # password=dbpass06 psql -h localhost -p 54327 -U dbuser07 database07 # password=dbpass07 psql -h localhost -p 54328 -U dbuser08 database08 # password=dbpass08 psql -h localhost -p 54329 -U dbuser09 database09 # password=dbpass09 psql -h localhost -p 54330 -U dbuser10 database10 # password=dbpass10 psql -h localhost -p 54331 -U dbuser11 database11 # password=dbpass11 psql -h localhost -p 54332 -U dbuser12 database12 # password=dbpass12 psql -h localhost -p 54333 -U dbuser13 database13 # password=dbpass13 psql -h localhost -p 54334 -U dbuser14 database14 # password=dbpass14 psql -h localhost -p 54335 -U dbuser15 database15 # password=dbpass15 psql -h localhost -p 54336 -U dbuser16 database16 # password=dbpass16 psql -h localhost -p 54337 -U dbuser17 database17 # password=dbpass17 psql -h localhost -p 54338 -U dbuser18 database18 # password=dbpass18 psql -h localhost -p 54339 -U dbuser19 database19 # password=dbpass19 psql -h localhost -p 54340 -U dbuser20 database20 # password=dbpass20 psql -h localhost -p 54341 -U dbuser21 database21 # password=dbpass21 psql -h localhost -p 54342 -U dbuser22 database22 # password=dbpass22 psql -h localhost -p 54343 -U dbuser23 database23 # password=dbpass23 psql -h localhost -p 54344 -U dbuser24 database24 # password=dbpass24 psql -h localhost -p 54345 -U dbuser25 database25 # password=dbpass25 psql -h localhost -p 54346 -U dbuser26 database26 # password=dbpass26 psql -h localhost -p 54347 -U dbuser27 database27 # password=dbpass27 psql -h localhost -p 54348 -U dbuser28 database28 # password=dbpass28 psql -h localhost -p 54349 -U dbuser29 database29 # password=dbpass29 psql -h localhost -p 54350 -U dbuser30 database30 # password=dbpass30