@@ -15,6 +15,15 @@ REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
1515source " ${REPO_DIR} /lib/common.sh"
1616
1717require_root
18+ load_config
19+
20+ INSTALL_MARIADB=" ${INSTALL_MARIADB:- yes} "
21+ INSTALL_POSTGRES=" ${INSTALL_POSTGRES:- yes} "
22+
23+ if [[ " ${INSTALL_MARIADB} " != " yes" && " ${INSTALL_POSTGRES} " != " yes" ]]; then
24+ info " Neither MariaDB nor PostgreSQL selected — skipping 20-databases."
25+ exit 0
26+ fi
1827
1928MARIADB_VERSION=" ${MARIADB_VERSION:- 12.0} "
2029PG_VERSION=" ${PG_VERSION:- 16} "
@@ -30,23 +39,24 @@ info "Detected RAM: ${RAM_MB}MB → tuning to shared=${SHARED_25}MB, effective=$
3039# -----------------------------------------------------------------------------
3140# 1. MariaDB
3241# -----------------------------------------------------------------------------
33- if rpm -q MariaDB-server > /dev/null 2>&1 || rpm -q mariadb-server > /dev/null 2>&1 ; then
34- info " MariaDB already installed."
35- else
36- info " Installing MariaDB ${MARIADB_VERSION} ..."
37- curl -fsSL https://downloads.mariadb.com/MariaDB/mariadb_repo_setup -o /tmp/mariadb_repo_setup
38- chmod +x /tmp/mariadb_repo_setup
39- if ! /tmp/mariadb_repo_setup --mariadb-server-version=" mariadb-${MARIADB_VERSION} " 2> /dev/null; then
40- warn " MariaDB version ${MARIADB_VERSION} unavailable; falling back to repo default."
41- /tmp/mariadb_repo_setup
42+ if [[ " ${INSTALL_MARIADB} " == " yes" ]]; then
43+ if rpm -q MariaDB-server > /dev/null 2>&1 || rpm -q mariadb-server > /dev/null 2>&1 ; then
44+ info " MariaDB already installed."
45+ else
46+ info " Installing MariaDB ${MARIADB_VERSION} ..."
47+ curl -fsSL https://downloads.mariadb.com/MariaDB/mariadb_repo_setup -o /tmp/mariadb_repo_setup
48+ chmod +x /tmp/mariadb_repo_setup
49+ if ! /tmp/mariadb_repo_setup --mariadb-server-version=" mariadb-${MARIADB_VERSION} " 2> /dev/null; then
50+ warn " MariaDB version ${MARIADB_VERSION} unavailable; falling back to repo default."
51+ /tmp/mariadb_repo_setup
52+ fi
53+ rm -f /tmp/mariadb_repo_setup
54+ dnf -y install MariaDB-server MariaDB-client
4255 fi
43- rm -f /tmp/mariadb_repo_setup
44- dnf -y install MariaDB-server MariaDB-client
45- fi
4656
47- info " Writing MariaDB tuning config..."
48- mkdir -p /etc/my.cnf.d
49- cat > /etc/my.cnf.d/serverdeploy.cnf << EOF
57+ info " Writing MariaDB tuning config..."
58+ mkdir -p /etc/my.cnf.d
59+ cat > /etc/my.cnf.d/serverdeploy.cnf << EOF
5060# Generated by serverdeploy 20-databases.sh
5161[mariadb]
5262innodb_buffer_pool_size = ${SHARED_25} M
@@ -63,45 +73,49 @@ bind-address = 127.0.0.1
6373default-character-set = utf8mb4
6474EOF
6575
66- systemctl enable mariadb
67- systemctl restart mariadb
68- sleep 2
76+ systemctl enable mariadb
77+ systemctl restart mariadb
78+ sleep 2
6979
70- info " Securing MariaDB (drop test db, anonymous users, remote root)..."
71- mariadb << 'SQL ' || die "MariaDB SQL failed."
80+ info " Securing MariaDB (drop test db, anonymous users, remote root)..."
81+ mariadb << 'SQL ' || die "MariaDB SQL failed."
7282DELETE FROM mysql.user WHERE User='';
7383DELETE FROM mysql.global_priv WHERE User='' OR User IS NULL;
7484DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
7585DROP DATABASE IF EXISTS test;
7686DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
7787FLUSH PRIVILEGES;
7888SQL
79- success " MariaDB installed and secured."
89+ success " MariaDB installed and secured."
90+ else
91+ info " Skipping MariaDB (INSTALL_MARIADB=${INSTALL_MARIADB} )."
92+ fi
8093
8194# -----------------------------------------------------------------------------
8295# 2. PostgreSQL
8396# -----------------------------------------------------------------------------
84- if rpm -q " postgresql${PG_VERSION} -server" > /dev/null 2>&1 ; then
85- info " PostgreSQL ${PG_VERSION} already installed."
86- else
87- info " Installing PostgreSQL ${PG_VERSION} ..."
88- dnf -y install " https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
89- dnf -qy module disable postgresql || true
90- dnf -y install " postgresql${PG_VERSION} -server" " postgresql${PG_VERSION} -contrib"
91- fi
97+ if [[ " ${INSTALL_POSTGRES} " == " yes" ]]; then
98+ if rpm -q " postgresql${PG_VERSION} -server" > /dev/null 2>&1 ; then
99+ info " PostgreSQL ${PG_VERSION} already installed."
100+ else
101+ info " Installing PostgreSQL ${PG_VERSION} ..."
102+ dnf -y install " https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
103+ dnf -qy module disable postgresql || true
104+ dnf -y install " postgresql${PG_VERSION} -server" " postgresql${PG_VERSION} -contrib"
105+ fi
92106
93- PG_DATA=" /var/lib/pgsql/${PG_VERSION} /data"
94- if [[ ! -f " ${PG_DATA} /PG_VERSION" ]]; then
95- info " Initializing Postgres data directory..."
96- " /usr/pgsql-${PG_VERSION} /bin/postgresql-${PG_VERSION} -setup" initdb
97- fi
107+ PG_DATA=" /var/lib/pgsql/${PG_VERSION} /data"
108+ if [[ ! -f " ${PG_DATA} /PG_VERSION" ]]; then
109+ info " Initializing Postgres data directory..."
110+ " /usr/pgsql-${PG_VERSION} /bin/postgresql-${PG_VERSION} -setup" initdb
111+ fi
98112
99- info " Tuning PostgreSQL..."
100- PG_CONF=" ${PG_DATA} /postgresql.conf"
101- PG_TUNING_DIR=" ${PG_DATA} /conf.d"
102- PG_TUNING_FILE=" ${PG_TUNING_DIR} /serverdeploy.conf"
103- mkdir -p " ${PG_TUNING_DIR} "
104- cat > " ${PG_TUNING_FILE} " << EOF
113+ info " Tuning PostgreSQL..."
114+ PG_CONF=" ${PG_DATA} /postgresql.conf"
115+ PG_TUNING_DIR=" ${PG_DATA} /conf.d"
116+ PG_TUNING_FILE=" ${PG_TUNING_DIR} /serverdeploy.conf"
117+ mkdir -p " ${PG_TUNING_DIR} "
118+ cat > " ${PG_TUNING_FILE} " << EOF
105119# Generated by serverdeploy 20-databases.sh
106120listen_addresses = '127.0.0.1'
107121max_connections = 200
@@ -113,26 +127,29 @@ wal_compression = on
113127log_min_duration_statement = 1000
114128log_line_prefix = '%t [%p] %u@%d '
115129EOF
116- chown postgres:postgres " ${PG_TUNING_FILE} "
117- chown -R postgres:postgres " ${PG_TUNING_DIR} "
130+ chown postgres:postgres " ${PG_TUNING_FILE} "
131+ chown -R postgres:postgres " ${PG_TUNING_DIR} "
118132
119- if ! grep -q " include_dir = 'conf.d'" " ${PG_CONF} " ; then
120- echo " " >> " ${PG_CONF} "
121- echo " include_dir = 'conf.d'" >> " ${PG_CONF} "
122- fi
133+ if ! grep -q " include_dir = 'conf.d'" " ${PG_CONF} " ; then
134+ echo " " >> " ${PG_CONF} "
135+ echo " include_dir = 'conf.d'" >> " ${PG_CONF} "
136+ fi
123137
124- systemctl enable " postgresql-${PG_VERSION} "
125- systemctl restart " postgresql-${PG_VERSION} "
126- sleep 2
127- sudo -u postgres psql -tAc " SELECT version()" > /dev/null || die " Postgres not responding."
128- success " PostgreSQL ${PG_VERSION} installed and tuned."
138+ systemctl enable " postgresql-${PG_VERSION} "
139+ systemctl restart " postgresql-${PG_VERSION} "
140+ sleep 2
141+ sudo -u postgres psql -tAc " SELECT version()" > /dev/null || die " Postgres not responding."
142+ success " PostgreSQL ${PG_VERSION} installed and tuned."
143+ else
144+ info " Skipping PostgreSQL (INSTALL_POSTGRES=${INSTALL_POSTGRES} )."
145+ fi
129146
130147# -----------------------------------------------------------------------------
131148# Done
132149# -----------------------------------------------------------------------------
133150echo
134151success " 20-databases.sh complete."
135- info " MariaDB : connect with 'mariadb' (unix_socket auth as root)"
136- info " Postgres : connect with 'sudo -u postgres psql' (peer auth)"
152+ [[ " ${INSTALL_MARIADB} " == " yes " ]] && info " MariaDB : connect with 'mariadb' (unix_socket auth as root)"
153+ [[ " ${INSTALL_POSTGRES} " == " yes " ]] && info " Postgres : connect with 'sudo -u postgres psql' (peer auth)"
137154info " RAM-tuned: shared/buffer=${SHARED_25} MB effective=${EFFECTIVE_50} MB"
138- info " Both bind 127.0.0.1 only — not reachable from network."
155+ info " Installed engines bind 127.0.0.1 only — not reachable from network."
0 commit comments