How to Install and Configure MariaDB 10.11 for Optimal Performance on a Low-RAM Ubuntu VPS

Introduction

At ByteHosting, we understand that running a database server on a low-resource VPS can be challenging. That's why we’ve put together this comprehensive guide on how to install MariaDB 10.11 on Ubuntu VPS and optimize it for environments with limited RAM. Whether you're hosting a small website, a development environment, or a lightweight application, tuning MariaDB for performance without overloading your server is crucial.

Prerequisites: VPS Setup and Requirements

Before we begin, ensure your VPS meets the following requirements:

  • Ubuntu 20.04 LTS or later installed
  • Root or sudo privileges
  • At least 512MB of RAM (preferably 1GB or more for better performance)
  • Basic familiarity with Linux command line

Our affordable KVM-based VPS plans in Frankfurt am Main, such as the Xeon 4GB or 6GB options, are perfect for hosting MariaDB with room to spare. Now, let’s move on to downloading and compiling MariaDB 10.11 from source.

Download and Compile MariaDB 10.11 from Source

Step 1: Update your system

Start by updating your package list and installing necessary dependencies:

sudo apt update
sudo apt upgrade -y
sudo apt install -y build-essential libncurses5-dev libssl-dev libaio-dev libboost-dev

Step 2: Download MariaDB 10.11 source code

Visit the official MariaDB repository to get the latest source tarball:

wget https://downloads.mariadb.org/f/mariadb-10.11.0/source/mariadb-10.11.0.tar.gz
tar -xzf mariadb-10.11.0.tar.gz
cd mariadb-10.11.0

Step 3: Compile and install

Configure the build with options suitable for low RAM environments:

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DPLUGIN_AUTH_GSSAPI=OFF -DPLUGIN_AUTH_PAM=OFF -DPLUGIN_AUTH_PAM_SASL=OFF -DPLUGIN_AUTH_GSSAPI=OFF -DPLUGIN_AUTH_PAM=OFF -DPLUGIN_AUTH_PAM_SASL=OFF -DPLUGIN_AUTH_CACHING_SHA2=ON -DPLUGIN_TOKUDB=OFF -DPLUGIN_MROONGA=OFF -DPLUGIN_MYISAM=ON -DPLUGIN_INNOBASE=ON -DPLUGIN_FEDERATED=OFF -DPLUGIN_FEED=OFF -DPLUGIN_ROCKSDB=OFF -DPLUGIN_TOKUDB=OFF -DWITH_SSL=ON -DWITH_INNOBASE_STORAGE_ENGINE=ON -DWITH_PARTITION_STORAGE_ENGINE=ON -DWITHOUT_TOKUDB=ON

make -j$(nproc)
sudo make install

Note: Adjust the -j parameter based on your CPU cores for faster compilation.

Configure MariaDB for Low RAM Environments

After installation, it's essential to tune MariaDB to run efficiently on a low-resource VPS. The main configuration file is located at /etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf.

Step 1: Backup the default configuration

sudo cp /etc/mysql/mariadb.conf.d/50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf.bak

Step 2: Edit the configuration

Open the file with your preferred editor:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Adjust the following parameters to reduce memory usage:

[mysqld]
max_connections = 50
innodb_buffer_pool_size = 64M
key_buffer_size = 16M
query_cache_size = 16M
tmp_table_size = 32M
max_heap_table_size = 32M
innodb_log_file_size = 64M

These settings limit the number of concurrent connections and reduce buffer sizes, which helps prevent your server from running out of RAM.

Start and Secure MariaDB Service

Step 1: Start MariaDB

sudo systemctl start mariadb
sudo systemctl enable mariadb

Step 2: Secure the installation

Run the security script to set root password, remove anonymous users, and disable remote root login:

sudo mysql_secure_installation

Follow the prompts to complete the security setup.

Verify Installation and Performance

Check that MariaDB is running correctly:

sudo systemctl status mariadb

Log into the database:

mysql -u root -p

Run some basic queries to verify responsiveness:

SHOW VARIABLES LIKE 'version';
SHOW STATUS LIKE 'Threads_connected';

For performance testing, consider using tools like Percona Toolkit or pt-stalk to analyze slow queries and server load.

Troubleshoot Common Issues with MariaDB on Low RAM

  • High swap usage: Reduce max_connections and buffer sizes further.
  • Slow queries: Use EXPLAIN to analyze queries and optimize indexes.
  • Service not starting: Check logs at /var/log/mysql/error.log for clues.

Remember, on a low-resource VPS, monitoring your server’s memory and CPU usage is vital. Use tools like htop or top to keep an eye on resource consumption.

Conclusion

Installing and tuning MariaDB 10.11 on an Ubuntu VPS with limited RAM requires careful configuration and optimization. By compiling from source, adjusting memory settings, and monitoring performance, we can ensure a stable and efficient database environment. At ByteHosting, our cost-effective VPS plans in Frankfurt am Main provide an excellent foundation for hosting MariaDB and other critical services. With proper setup, even low-resource servers can deliver reliable database performance.

Read more