MySQL, MongoDB, RabbitMQ, and Redis on an Android Device

MySQL, MongoDB, RabbitMQ, and Redis are probably pretty familiar to a lot of developers. If you are using any of them. Chances are you're using Docker to manage them.

Instead, as a fun exercise, we'll install them on an Android device. Then configure them to be accessible remotely.

The basic steps involve:

  • Installing Termux
  • Installing Ubuntu
  • Installing MySQL, MongoDB, RabbitMQ, and Redis
  • Testing Remote Access
Let's get started.

Installing Termux

What is Termux? Taken directly from the project's homepage. "Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required."

You install Termux directly from the Google Play Store. This version of Termux will not be receiving further updates due to increasing Android restrictions. But for our purpose, it should be fine.

If you find the steps in this article are not working for you. You can try installing the latest version of Termux from F-Droid(Free and Open Source Android App Repository).

Once you have Termux installed. Open the app to access its terminal.

Update and upgrade existing packages.
pkg update && pkg upgrade

Installing SSH Server - Optional

This next step is optional. But it will make things easier. Install an SSH server and log in remotely from a computer.
pkg install openssh
To log in using SSH. We'll need a user, password, and the internal IP address of your Android device. For this article, it is u0_a260, motootspassword, and 192.168.0.68. Get the user.
whoami
Set the password.
passwd
Get the IP address.
ifconfig
If you're having trouble identifying your IP address. You can always go into the Android Wi-Fi settings. It will be available under the network you are currently connected to.

Start the SSH server.
sshd
Open a terminal from your computer and log into Termux on the Android device.
ssh u0_a260@192.168.0.68 -p 8022

Installing Ubuntu

Termux provides a package for installing Linux.
pkg install proot-distro
You can view a list of available distros with the command proot-distro list. Install Ubuntu.
proot-distro install ubuntu-20.04
Log in.
proot-distro login ubuntu-20.04
Update and upgrade existing packages.
apt update && apt upgrade

Installing MySQL

Install MySQL.
apt install mysql-server
To access MySQL remotely. We'll need to edit a configuration file and create a user with proper permissions. Nano is part of the standard Ubuntu distribution. We'll edit the configuration file using that.
nano /etc/mysql/mysql.conf.d/mysqld.cnf
Find and comment out bind-address to accept all connections.
# bind-address = 127.0.0.1
Start MySQL.
/etc/init.d/mysql start &
Access the MySQL Command-Line Client.
mysql -u root
Create a database and user with proper privileges.
CREATE DATABASE motootsdb;
CREATE USER 'motootsuser'@'%' IDENTIFIED BY 'motootspassword';
GRANT ALL PRIVILEGES ON *.* TO 'motootsuser'@'%' WITH GRANT OPTION;
exit
MySQL is ready to use.

Installing MongoDB

Install MongoDB.
apt install mongodb
Create a directory needed by MongoDB.
mkdir /data/db
Start MongoDB with remote access enabled.
mongod --bind_ip 0.0.0.0 &
MongoDB is ready to use.

Installing RabbitMQ

Install RabbitMQ.
apt install rabbitmq-server
To access RabbitMQ remotely. We'll need to edit a configuration file and create a user with proper permissions.
nano /etc/rabbitmq/rabbitmq-env.conf
Find, uncomment, and edit NODE_IP_ADDRESS to allow all connections.
NODE_IP_ADDRESS=0.0.0.0
Create a user with proper permissions.
rabbitmqctl add_user motootsadmin pa55word
rabbitmqctl set_user_tags motootsadmin administrator
rabbitmqctl set_permissions -p / motootsadmin ".*" ".*" ".*"
Start RabbitMQ. It might take a while before it is up and running.
rabbitmq-server -detached
RabbitMQ is ready to use.

Installing Redis

Install Redis.
apt install redis-server
Start Redis with remote access enabled.
redis-server --protected-mode no &
Redis is ready to use.

Testing Remote Access

To test remote access. You'll need the Android device's IP address.

If you didn't skip the optional portion of this article. You already have the IP address needed. Otherwise, go to that section to obtain your device's IP address.

For MongoDB and Redis. The IP address is all you need. For MySQL and RabbitMQ. You also need the user created in those sections.

Use your favorite tools to test remote connections from your computer. The default ports have not changed. Or use this companion Spring Boot application to test all, or some, of the connections in this article. Instruction can be found in the README file.

That's all for this exercise. A video version is available on YouTube.

Comments

Post a Comment

Popular posts from this blog

Running Docker using QEMU on an Android Device