From d0f053485d6635d0128b815b422b421bbb836514 Mon Sep 17 00:00:00 2001 From: Cullum Smith Date: Thu, 27 Mar 2025 21:51:45 -0400 Subject: add mysql --- scripts/hostclass/mysql_server | 65 ++++++++++++++++++++++++++++++++++++++++ scripts/hostclass/pkg_repository | 4 +-- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 scripts/hostclass/mysql_server (limited to 'scripts/hostclass') diff --git a/scripts/hostclass/mysql_server b/scripts/hostclass/mysql_server new file mode 100644 index 0000000..115b591 --- /dev/null +++ b/scripts/hostclass/mysql_server @@ -0,0 +1,65 @@ +#!/bin/sh + +mysql_user=mysql +mysql_home=/var/db/mysql +mysql_tls_cert="${mysql_home}/mysql.crt" +mysql_tls_key="${mysql_home}/mysql.key" +mysql_keytab="${keytab_dir}/mariadb.keytab" +mysql_conf_dir=/usr/local/etc/mysql +mysql_log_dir=/var/log/mysql + +# Install packages. +pkg install -y "mariadb$(echo "$mariadb_version" | tr -d .)-server" + +# Create ZFS dataset for mysql data. +create_dataset \ + -o "mountpoint=${mysql_home}" \ + -o primarycache=metadata \ + -o atime=off \ + "${state_dataset}/mysql" +create_dataset \ + -o "mountpoint=${mysql_home}/data" \ + -o recordsize=16k \ + "${state_dataset}/mysql/data" +create_dataset \ + -o "mountpoint=${mysql_home}/log" \ + "${state_dataset}/mysql/log" + +zfs set \ + com.sun:auto-snapshot:daily=true \ + com.sun:auto-snapshot:weekly=true \ + com.sun:auto-snapshot:monthly=true \ + "${state_dataset}/mysql/data" + +install_directory -m 0755 -o "$mysql_user" -g "$mysql_user" "$mysql_home" +install_directory -m 0770 -o "$mysql_user" -g "$mysql_user" "${mysql_home}/data" "${mysql_home}/log" + +# Create service principal and keytab. +add_principal -nokey -x "containerdn=${services_basedn}" "mariadb/${fqdn}" + +ktadd -k "$mysql_keytab" "mariadb/${fqdn}" +chgrp "$mysql_user" "$mysql_keytab" +chmod 640 "$mysql_keytab" + +mysql_uid=$(id -u "$mysql_user") +install_directory -o "$mysql_user" -m 0700 "/var/krb5/user/${mysql_uid}" +ln -snfv "$mysql_keytab" "/var/krb5/user/${mysql_uid}/keytab" + +# Copy PAM configuration. +install_template -m 0644 /etc/pam.d/mysql + +# Copy TLS certificate for mysql. +install_certificate -m 0644 -o root -g "$mysql_user" mysql "$mysql_tls_cert" +install_certificate_key -m 0640 -o root -g "$mysql_user" mysql "$mysql_tls_key" + +# Generate mysql configuration. +install_template -m 0644 "${mysql_conf_dir}/conf.d/server.cnf" + +# Start mariadb. +sysrc -v mysql_enable=YES +service mysql-server restart + +cat <