INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / Микроблог / Thingiverse / RSS / GPG

bash: wait database for connection

№ 10430 В разделе "Sysadmin" от December 6th, 2019,
В подшивках: , ,

You can easily use it to check MySQL or Postgresql connection.

#!/bin/bash

for i in `seq 1 ${CONNECT_TIMEOUT}`;
do
  mysql -h "${DB_HOST}" -u${DB_USERNAME} -p${DB_PASSWORD} ${DB_DATABASE} -e 'select 1'
  if [ $? -eq 0 ]; then
    echo "Connected to MySQL"
    exit 0
  fi
  if [ $i -eq ${CONNECT_TIMEOUT} ]; then
    echo "MySQL timeout"
    exit 1
  fi
  sleep 1
done

Нет комментариев »

Zabbix: MySQL to Postgresql migration

№ 9662 В разделе "Sysadmin" от December 28th, 2018,
В подшивках: , , ,

All services containerized by Docker, MySQL and Zabbix containers connected to network “zabbix”.

Start Postgresql container and add it to zabbix network group in Docker, set parameters as you need

docker run --name postgres -d --restart=Always \
    -e POSTGRES_USER=postgres
    -e POSTGRES_PASSWORD=postgres
    postgres
docker network connect zabbix postgres

Now create database and user

docker exec -it postgres su -c "createuser -P zabbix" postgres
docker exec -it postgres su -c "createdb -E UTF-8 -O zabbix zabbix" postgres

Ok, database online and accessible for Zabbix services.

Now you can stop old containers with Zabbix services for MySQL and run migration

docker stop zabbix-server-mysql zabbix-panel-mysql
docker run --network zabbix --rm -v /tmp/zabbix:/zabbix dimitri/pgloader:latest \
    bash -c "pgloader --debug --verbose \
    mysql://root:pa55w0rd@mariadb/zabbix \
    postgresql://zabbix:zabbix@postgres/zabbix"

Lets create script to start new Zabbix containers for Postgres DB

!/bin/bash

alertscripts="/srv/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts"
externalscripts="/srv/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts"

docker run --name zabbix-server-pg -p 10051:10051 \
    -v $alertscripts \
    -v $externalscripts \
    -e DB_SERVER_HOST="postgres" \
    -e DB_SERVER_PORT=5432 \
    -e POSTGRES_USER="zabbix" \
    -e POSTGRES_PASSWORD="zabbix" \
    -e POSTGRES_DB="zabbix" \
    -d --restart=always \
    --network zabbix \
    zabbix/zabbix-server-pgsql:ubuntu-latest

docker run --name zabbix-panel-pg -p 5001:80 \
    -e DB_SERVER_HOST="postgres" \
    -e POSTGRES_USER="zabbix" \
    -e POSTGRES_PASSWORD="zabbix" \
    -e POSTGRES_DB="zabbix" \
    -e ZBX_SERVER_HOST="zabbix-server-pg" \
    -e ZBX_SERVER_PORT="10051" \
    -e PHP_TZ="Asia/Novosibirsk" \
    -d --restart=always \
    --network zabbix \
    zabbix/zabbix-web-nginx-pgsql:ubuntu-latest

You did it! Take a cookie from shelf.

Нет комментариев »

Backup MySQL в Docker

№ 9567 В разделе "Sysadmin" от November 22nd, 2018,
В подшивках: , ,

Backup

docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

Restore

cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

Нет комментариев »

Terraform docker provider: wordpress + mysql

№ 9409 В разделе "Sysadmin" от September 13th, 2018,
В подшивках: , ,

Terraform infrastructure sample for docker provider. Creates docker containers on local machine.

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
a647e8f04629        6a834f03bd02        "docker-entrypoint.s…"   10 minutes ago      Up 10 minutes       3306/tcp, 33060/tcp   mysql
e69d24a3920a        63b422244491        "docker-entrypoint.s…"   13 minutes ago      Up 13 minutes       80/tcp                wordpress

How to run:

vlad@turtle:$ terraform init

... some strings

vlad@turtle:$ terraform apply
 
... some strings

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Outputs:

address_my = 172.17.0.2
address_wp = 172.17.0.3

You can find repository here https://git.blindage.org/21h/terraform-samples

Нет комментариев »

Bitrix: MySQL server has gone away при заливке дампа

№ 9069 В разделе "Sysadmin" от July 15th, 2018,
В подшивках: , ,

Размер транзакции слишком большой, нужно увеличить max_allowed_packet до, например, 128M. Возможно понадобится изменить wait_timeout.

Нет комментариев »

Яндекс.Метрика

Fortune cookie: Inside, I'm already SOBBING!