content:serverbasics:docker-mariadb
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Nächste Überarbeitung | Vorherige Überarbeitung | ||
| content:serverbasics:docker-mariadb [2023/12/29 17:08] – angelegt obel1x | content:serverbasics:docker-mariadb [2025/06/05 23:40] (aktuell) – [STOP] obel1x | ||
|---|---|---|---|
| Zeile 5: | Zeile 5: | ||
| Note that this will NOT work out of the Box right now, see this bug here: [[https:// | Note that this will NOT work out of the Box right now, see this bug here: [[https:// | ||
| - | ===== Yaml and .env ===== | + | Using Postgres for some time, i switched to mysql and than to mariadb as i like it most, as you can do good performence- measurements with the ability to slowlog. |
| - | i created the directory ''/ | + | Remarks to my setup: |
| - | '' | + | * Tuned mariadb for Nextcloud |
| - | <code> | + | * Using Sockets, not TCP/IP on the host |
| - | #Allgemeine Einstellungen für docker/ | + | * Added some tweaks from the net |
| + | |||
| + | ====== STOP ====== | ||
| + | |||
| + | This - it turned out is a very bad idea. MariaDB on Docker performs VERY bad. So i would strongly not advise to use Docker for this. Use native mariadb on your host and adept what is written here. | ||
| + | |||
| + | When you link the native mariadb- Socket to the services like this, you will be able to use Mariadb: | ||
| + | |||
| + | < | ||
| + | volumes: | ||
| + | #Bind mount: Socketfile needs to be definied by full filename, not only path! | ||
| + | - / | ||
| + | |||
| + | </ | ||
| + | |||
| + | Or you can use Port 3306 and as host your servername (NOT localhost). | ||
| + | |||
| + | So stop reading here, maybe only adjusting your local mariadb with these values beneath, thats all. | ||
| + | |||
| + | |||
| + | ===== Create Socket in tmpfs ===== | ||
| + | |||
| + | On the Host, the directory / | ||
| + | |||
| + | Create the File '' | ||
| + | |||
| + | <file> | ||
| + | #Type Path Mode UID GID Age Argument | ||
| + | d / | ||
| + | |||
| + | </file> | ||
| + | |||
| + | ===== Yaml and .env, configuration of mariadb | ||
| + | |||
| + | First, create the directory ''/ | ||
| + | |||
| + | File '' | ||
| + | |||
| + | < | ||
| COMPOSE_HTTP_TIMEOUT=180 | COMPOSE_HTTP_TIMEOUT=180 | ||
| - | #Diese Variabeln hier sind ganz anders, als die env-files: sie können als parameter in der yaml verwendet werden, nicht so die .env-files der dienste | ||
| - | #vgl: | ||
| - | # .env file which is used for variable substitution in the docker-compose.yaml file, and should resolve when you run docker-compose config | ||
| - | # env_file element in a service definition, which is just setting the environment file to send to docker engine when starting container, as a definition of runtime | ||
| - | environment. Compose will not parse this file which is opaque to him. | ||
| - | # | ||
| - | #Also die globalen Werte müssen hier rein! | ||
| - | #Mariadb immer dreistellig, | ||
| MARIADB_TAG=11.2.2 | MARIADB_TAG=11.2.2 | ||
| + | </ | ||
| + | |||
| + | File '' | ||
| + | |||
| + | < | ||
| + | version: ' | ||
| + | # | ||
| + | # Nach einigem hin und her, hat sich mariadb als zuverlässigste datenbank herausgestellt | ||
| + | # Achtung: NICHT mysql, sondern mariadb ! | ||
| + | # | ||
| + | services: | ||
| + | mariadb: | ||
| + | | ||
| + | | ||
| + | | ||
| + | - SYS_NICE | ||
| + | | ||
| + | | ||
| + | | ||
| + | #Attention: won't work ! | ||
| + | # - MARIADB_ROOT_PASSWORD=" | ||
| + | #use this and check the password at the logs of the first start: | ||
| + | - MARIADB_RANDOM_ROOT_PASSWORD=1 | ||
| + | - MARIADB_AUTO_UPGRADE=1 | ||
| + | # 0 = Null = False, but false does not work here | ||
| + | - MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=0 | ||
| + | #Could be set when opening port 3306 to the hosts network and disallow root when connecting from other hosts | ||
| + | #is only set the first time for user creation - after that its fixed and may only be changed after login or internally in the container | ||
| + | #wenn leer, dann wird als host % genommen (also alle)if not set, % = allow all is taken | ||
| + | # - MARIADB_ROOT_HOST=' | ||
| + | | ||
| + | - seccomp: | ||
| + | - apparmor: | ||
| + | #can be set to prevent some limitations. as long as the service is fine, don't change! | ||
| + | # ulimits: | ||
| + | # nproc: " | ||
| + | # nofile: | ||
| + | # soft: " | ||
| + | # hard: " | ||
| + | # memlock: " | ||
| + | | ||
| + | test: healthcheck.sh --connect --innodb_initialized | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | #This opens the IP- Port of MariaDB - i won't do this as the socket / | ||
| + | # ports: | ||
| + | # - 3306:3306 | ||
| + | | ||
| + | - mariadb_data:/ | ||
| + | - mariadb_log:/ | ||
| + | - ./ | ||
| + | - / | ||
| + | #This won't work as mariadb does not get lock to that file when managed by docker (don't now why exactly) | ||
| + | # - / | ||
| + | | ||
| + | - /tmp | ||
| + | | ||
| + | - mariadb | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | - 8081:80 | ||
| + | | ||
| + | - PMA_ARBITRARY=1 | ||
| + | - PMA_ABSOLUTE_URI=http:// | ||
| + | - PMA_HOSTS=localhost | ||
| + | # - PMA_PORTS=/ | ||
| + | - PMA_PMADB=phpmyadmin | ||
| + | | ||
| + | # Own Config in local config.user.inc.php | ||
| + | - ./ | ||
| + | - / | ||
| + | | ||
| + | test: "curl localhost: | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | - mariadb | ||
| + | | ||
| + | - mariadb | ||
| + | |||
| + | volumes: | ||
| + | mariadb_data: | ||
| + | | ||
| + | | ||
| + | type: "" | ||
| + | o: " | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | type: "" | ||
| + | o: " | ||
| + | |||
| + | networks: | ||
| + | | ||
| </ | </ | ||
| + | |||
| + | File '' | ||
| + | |||
| + | < | ||
| + | [server] | ||
| + | max_connections = 12 | ||
| + | # | ||
| + | skip_name_resolve = 1 | ||
| + | #und Statistiken ausschalten | ||
| + | innodb_stats_on_metadata = 0 | ||
| + | # | ||
| + | max_allowed_packet = 16M | ||
| + | sql_mode=NO_ENGINE_SUBSTITUTION, | ||
| + | |||
| + | #tmp-tables werden zum beispiel für update-select verwendet. wenn die hier nicht rein passen, werden sie auf der Platte | ||
| + | #erzeugt. | ||
| + | #Achtung: Warnungen, dass 0_TMPFILE nicht angelegt werden können, sind normal(!), hindern nicht an der Ausführung, | ||
| + | #Diese soll gleich sein mit max_heap_table_size | ||
| + | tmp_table_size = 1024M | ||
| + | max_heap_table_size = 1024M | ||
| + | |||
| + | #Timeouts hochsetzen | ||
| + | # 3600 ist wohl zu viel, sagt mysqltuner | ||
| + | wait_timeout = 300 | ||
| + | # damit wird dann nach 6 minuten inaktivität doch mal getrennt | ||
| + | interactive_timeout = 360 | ||
| + | |||
| + | #[Warning] ' | ||
| + | # | ||
| + | # Standard 128 - wir haben 16GB Hauptspeicher und das soll eine große DB werden. Also diese auch etwas nutzen. | ||
| + | # | ||
| + | innodb_buffer_pool_size = 1024M | ||
| + | # | ||
| + | #sollen aber nicht mehr als 256M sein sagt der ratgeber... mal sehen | ||
| + | innodb_log_file_size = 256M | ||
| + | innodb_log_buffer_size = 32M | ||
| + | innodb_flush_log_at_trx_commit = 2 | ||
| + | innodb_flush_method = fsync | ||
| + | innodb_max_dirty_pages_pct = 90 | ||
| + | query_cache_type = 1 | ||
| + | query_cache_limit = 56M | ||
| + | query_cache_min_res_unit = 2k | ||
| + | query_cache_size = 64M | ||
| + | low-priority-updates=on | ||
| + | join_buffer_size = 256M | ||
| + | sort_buffer_size = 4M | ||
| + | read_rnd_buffer_size = 2M | ||
| + | |||
| + | #Nur fuer MyISAM-Tabellen: | ||
| + | key_buffer_size=64M | ||
| + | |||
| + | #Bin-Log: sehr wichtig! | ||
| + | log_bin=mysql-bin | ||
| + | binlog_format = ROW | ||
| + | expire_logs_days=3 | ||
| + | |||
| + | #Slow Logs - Todos: Wie kann man das in Docker gut machen - also persistent, aber OHNE zuviel Datenmüll? | ||
| + | #solange ich die rotation nicht an habe, würde das zuviel schreiben | ||
| + | slow_query_log_file = / | ||
| + | log-slow-verbosity=explain | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | ## Alder - default=sp - aber keiner weiss, wofür sp steht! Also raus! | ||
| + | # | ||
| + | #Deprecated mit MariaDB11 - "use log_slow_filter without admin" | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | slow-query-log = 1 | ||
| + | long-query-time=1 | ||
| + | # | ||
| + | |||
| + | [client] | ||
| + | default-character-set = utf8mb4 | ||
| + | socket = / | ||
| + | |||
| + | [mysqld] | ||
| + | character_set_server = utf8mb4 | ||
| + | collation_server = utf8mb4_general_ci | ||
| + | transaction_isolation = READ-COMMITTED | ||
| + | innodb_file_per_table=1 | ||
| + | #[Warning] ' | ||
| + | # | ||
| + | #[Warning] ' | ||
| + | # | ||
| + | |||
| + | </ | ||
| + | |||
| + | File '' | ||
| + | |||
| + | < | ||
| + | <?php | ||
| + | |||
| + | declare(strict_types=1); | ||
| + | |||
| + | # Settings for phpMyAdmin | ||
| + | |||
| + | # $cfg[' | ||
| + | $cfg[' | ||
| + | |||
| + | // Array starts at 1 ... | ||
| + | $i = 1; | ||
| + | $cfg[' | ||
| + | $cfg[' | ||
| + | # | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Backup ===== | ||
| + | |||
| + | Backing up MariaDB on Docker works like this: | ||
| + | |||
| + | < | ||
| + | #!/bin/bash | ||
| + | # This would be Postgres - i don't like postgres, so see beneath for mariadb: | ||
| + | # rm / | ||
| + | # docker exec -t postgresql-pgsql_db-1 pg_dumpall -c -U postgres | ||
| + | # For mariadb use mariadb-dump and root | ||
| + | # For mysql use mysqldump and admin | ||
| + | BACKUPFILE=/ | ||
| + | MARIADB_PASS=' | ||
| + | echo " | ||
| + | rm ${BACKUPFILE} | ||
| + | docker exec -t mariadb-mariadb-1 mariadb-dump --all-databases --single-transaction --quick --lock-tables=false -u root -p${MARIADB_PASS} | ||
| + | echo ' | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== No Docker Service ==== | ||
| + | |||
| + | If you have MariaDB as native Host- Service installed, use: | ||
| + | < | ||
| + | |||
| + | #!/bin/bash | ||
| + | # Makes a Backup of the whole Mariadb | ||
| + | BACKUPFILE=/ | ||
| + | echo " | ||
| + | # Keep one Copy of the old Backup | ||
| + | if [ -f ${BACKUPFILE} ]; then | ||
| + | if [ -f ${BACKUPFILE}.back ]; then | ||
| + | rm ${BACKUPFILE}.back | ||
| + | fi | ||
| + | mv ${BACKUPFILE} ${BACKUPFILE}.back | ||
| + | else | ||
| + | echo "File ${BACKUPFILE} was not found, not removing ${BACKUPFILE}.back" | ||
| + | fi | ||
| + | # for mysql use mysqldump... | ||
| + | / | ||
| + | if [ ! -f ${BACKUPFILE} ]; then | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Optimizing Tables ===== | ||
| + | |||
| + | Doing this will remove defragmentation and repair some stuff, so maybe you want to do this once a month or so '' | ||
| + | < | ||
| + | |||
| + | #!/bin/bash | ||
| + | #Optimize Database | ||
| + | # 28.11.2023: Docker-Version | ||
| + | # 13.12.2023: Replaced mysql by mariadb | ||
| + | # | ||
| + | echo "Check and optimize DB Mysql" | ||
| + | |||
| + | RUN_SQL=/ | ||
| + | RUN_LOG=/ | ||
| + | |||
| + | # | ||
| + | SQL=" | ||
| + | SQL=" | ||
| + | SQL=" | ||
| + | SQL=" | ||
| + | |||
| + | MARIADB_USER=' | ||
| + | MARIADB_PASS=' | ||
| + | CONTAINERNAME=' | ||
| + | |||
| + | RUN_CMD=" | ||
| + | |||
| + | # Create SQL Commands to run | ||
| + | ${RUN_CMD} -ANe" | ||
| + | # Execute CHECK TABLE Commands | ||
| + | ${RUN_CMD} --raw --silent --table < | ||
| + | |||
| + | #cat " | ||
| + | # | ||
| + | RUN_ERROR=(`cat " | ||
| + | if [[ ! -z " | ||
| + | echo " | ||
| + | echo "" | ||
| + | echo "!!!! ERROR- STOP OPTIMIZE: Some MySQL Databases are corrupt, please check output in ${RUN_LOG}:" | ||
| + | cat " | ||
| + | echo "" | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | echo "Check MysqlDB was sucessful, no errors found" | ||
| + | |||
| + | exit 0 | ||
| + | |||
| + | #For me, i choose to run this only every 6th of the month | ||
| + | ifStart=`date ' | ||
| + | if [ $ifStart == 06 ] | ||
| + | then | ||
| + | echo " | ||
| + | RUN_SQL=/ | ||
| + | RUN_LOG=/ | ||
| + | |||
| + | SQL=" | ||
| + | SQL=" | ||
| + | SQL=" | ||
| + | SQL=" | ||
| + | |||
| + | # Create SQL Commands to run | ||
| + | ${RUN_CMD} -ANe" | ||
| + | |||
| + | # Execute Commands | ||
| + | ${RUN_CMD} --raw --silent --table <" | ||
| + | cat " | ||
| + | RUN_ERROR=(`cat " | ||
| + | if [[ ! -z " | ||
| + | echo " | ||
| + | echo "" | ||
| + | echo "!!!! ERROR- STOP OPTIMIZE: Some MySQL Databases are corrupt, please check output in ${RUN_LOG}:" | ||
| + | echo "" | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | # Useless for Docker... | ||
| + | # /sbin/btrfs filesystem defragment / | ||
| + | fi | ||
| + | echo " | ||
| + | exit 0 | ||
| + | |||
| + | #Diese Version geht leider nicht, weil die KOmmandos im Docker nicht vorhanden sind... | ||
| + | #docker exec -t mysql-mysqldb-1 mysqlcheck -u admin -p' | ||
| + | #docker exec -t mysql-mysqldb-1 mysqlcheck -u admin -p' | ||
| + | |||
| + | </ | ||
| + | |||
content/serverbasics/docker-mariadb.1703866081.txt.gz · Zuletzt geändert: von obel1x
