-
Title explains it already.
I'm looking to connect my minecraft server to the lamp stack's database, but this isn't possible.
Neither is it possible to connect to the MC Server's Database, as the hostname gets rewritten by cloudron automatically to localhost.
Please fix this or let me know how I can make either database accessible.
-
If minecraft is on Cloudron as well, then you can just use the MySQL credentials of the LAMP app directly. You can get the credentials by opening a web terminal for the LAMP app and then running this:
env | grep CLOUDRON_MYSQL
If minecraft is one a different server, it's more complicated because the MySQL addon is completely sandboxed in the sever. But it's possible (can explain more, if this is the case).
-
Here's a more complete tutorial.
- First open the web terminal for the lamp app. Get the MySQL access credentials. Note that the credentials only work inside Cloudron server.
root@f6af0aef-2e29-4b53-a674-c2eed67eea36:/app/data# env | grep MYSQL MYSQL_PASSWORD=9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d MYSQL_DATABASE=0133aefa8ed2d231 MYSQL_PORT=3306 MYSQL_HOST=mysql MYSQL_USERNAME=0133aefa8ed2d231 MYSQL_URL=mysql://0133aefa8ed2d231:9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d@mysql/0133aefa8ed2d231
- SSH into the Cloudron server and get the IP address of the
mysql
container.
root@localhost:~# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql 172.18.0.5
- SSH into the Cloudron server to verify that we can connect to the app's database. Carefully plug the values from the env vars into the command line below.
root@localhost:~# mysql --user=0133aefa8ed2d231 --password=9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d --host=172.18.0.5 --port=3306 0133aefa8ed2d231 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8037 Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show tables;
- Now to connect to this mysql server from another server or your laptop, you have to create a SSH tunnel. Run this command on the other server or your laptop:
$ ssh -N -L 127.0.0.1:3306:172.18.0.5:3306 root@my.cloudron.domain
What this command is doing is connecting to your Cloudron via SSH. The
-L
sets up port forwarding. It forward port 3306 of 127.0.0.1 (localhost) to port 3306 of 172.18.0.5 (mysql).- We can now connect to port 3306 of 127.0.0.1 to access mysql:
$ mysql --user=0133aefa8ed2d231 --password=9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d --host=127.0.0.1 --port=3306 0133aefa8ed2d231 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8038 Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show tables; Empty set (0.01 sec)
- Some additional thoughts. If you want the ssh proxying to persist in your laptop/other server, use autossh. https://pronto185.com/blog/2014/01/30/how-i-use-autossh/ has a simple tutorial. For windows, there is https://persistentssh.com/ (I have never used it).
-
How about this then. On Cloudron, install socat and also open up port 5555 in iptables. Then just forward port 5555 to the internal mysql.
root@localhost:~# apt install socat root@localhost:~# iptables -I INPUT -p tcp --dport 5555 -j ACCEPT root@localhost:~# mkdir /etc/iptables root@localhost:~# iptables-save > /etc/iptables/rules.v4 root@localhost:~# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql 172.18.0.4 root@localhost:~# socat TCP-LISTEN:5555,fork TCP:172.18.0.4:3306
- Then you can connect from your PC or minecraft server to the sql server using port 5555 as:
$ mysql --user=e89d41145799e97 --password=e97e3fb41f3e52dd2462997d6008ccc0e0b0cffb9443b4ff --host=my.cloudron.domain --port=5555 e89d41668599e97 mysql> show tables; Empty set (0.01 sec)
You have to install the socat as a systemd service or such to make it persist reboots. Otherwise, just use
nohup socat TCP-LISTEN:5555,fork TCP:172.18.0.4:3306 &
-