ONLYOFFICE Document Server with MariaDB uses 127.0.0.1 when asked to use localhost

I don’t seen to be able to get ONLYOFFICE Document Server to work with MariaDB, I have a local database that works with the settings from /etc/onlyoffice/documentserver/local.json, for example:

{
  "services": {
      "sql": {
        "dbHost": "localhost",
        "dbName": "onlyoffice",
        "dbPass": "C3mbo3P5PZZ10mlNSsOY",
        "dbPort": "3306",
        "dbUser": "onlyoffice",
        "type": "mariadb"
      }
}
mysql -hlocalhost -uonlyoffice -pC3mbo3P5PZZ10mlNSsOY onlyoffice -e "SHOW TABLES"
+----------------------+
| Tables_in_onlyoffice |
+----------------------+
| doc_changes          |
| task_result          |
+----------------------+

But in /var/log/onlyoffice/documentserver/docservice/out.log I have:

[2023-04-20T14:54:41.943] [WARN] [localhost] [docId] [userId] nodeJS - Express server starting...
[2023-04-20T14:54:41.947] [WARN] [localhost] [docId] [userId] nodeJS - Failed to subscribe to plugin folder updates. When changing the list of plugins, you must restart the server. https://nodejs.org/docs/latest/api/fs.html#fs_availability
[2023-04-20T14:54:42.086] [ERROR] [localhost] [docId] [userId] nodeJS - pool.getConnection error: Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true
}
[2023-04-20T14:54:42.090] [ERROR] [localhost] [docId] [userId] nodeJS - getTableColumns error: Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)

I suspect it is because ONLYOFFICE is trying to connect to 127.0.0.1 rather than localhost:

mysql -h127.0.0.1 -uonlyoffice -pC3mbo3P5PZZ10mlNSsOY onlyoffice -e "SHOW TABLES"
ERROR 2002 (HY000): Can't connect to MySQL server on '127.0.0.1' (115)

Check the name resolution:

dig A localhost +short
127.0.0.1
dig AAAA localhost +short
::1

The same with IPv6:

mysql -h::1 -uonlyoffice -pC3mbo3P5PZZ10mlNSsOY onlyoffice -e "SHOW TABLES"
ERROR 2002 (HY000): Can't connect to MySQL server on '::1' (115)

I think using localhost results in the socket at /var/run/mysqld/mysqld.sock being used for the the connection and not TCP/IP, can ONLYOFFICE use the socket or do I need to enable MariaDB to allow TCP/IP connections? However the user is set to use password auth:

mysql -e "SELECT User,Host,plugin from user WHERE User='onlyoffice'" mysql
+------------+-----------+-----------------------+
| User       | Host      | plugin                |
+------------+-----------+-----------------------+
| onlyoffice | localhost | mysql_native_password |
+------------+-----------+-----------------------+

I 've also tried creating a ~/.my.cnf file for the ds user:

ls -lah /var/www/onlyoffice/documentserver/.my.cnf
-rw-r----- 1 root ds 113 Apr 20 17:04 /var/www/onlyoffice/documentserver/.my.cnf

cat /var/www/onlyoffice/documentserver/.my.cnf
[client]
host="localhost"
user="onlyoffice"
password="C3mbo3P5PZZ10mlNSsOY"
database="onlyoffice"

su - ds -s /bin/bash
mysql -e "show databases"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| onlyoffice         |
+--------------------+

I’ve tried adding an additional user account:

mysql -e "CREATE USER 'onlyoffice'@'127.0.0.1' IDENTIFIED BY 'C3mbo3P5PZZ10mlNSsOY'" mysql
mysql -e "GRANT ALL PRIVILEGES ON onlyoffice.* TO 'onlyoffice'@'127.0.0.1'" mysql
mysql -e "SELECT User,Host,plugin from user WHERE User='onlyoffice'" mysql
+------------+-----------+-----------------------+
| User       | Host      | plugin                |
+------------+-----------+-----------------------+
| onlyoffice | localhost | mysql_native_password |
| onlyoffice | 127.0.0.1 | mysql_native_password |
+------------+-----------+-----------------------+

But a service ds-docservice restart results in the same error being written to /var/log/onlyoffice/documentserver/docservice/out.log.

Hello @chris
I believe we have to start from scratch. Please point me to the guide which you used for Document server installation, additionally let us know current version of the app and your OS.
Do I understand it right that external database (MariaDB) is installed on the same server as Document server?
One more thing. Could you please run a test? Please change necessary lines in default.json config file (‘sql’ section) too and restart all services. Will the situation change?

I’m using Debian Bullseye and the latest version of the ONLYOFFICE Docs Community Edition, MariaDB is running on the same server as ONLYOFFICE, the issue is that while connections to localhost work fine using the MariaDB client it appears that ONLYOFFICE resolves the database host address from the specified localhost to 127.0.0.1, which then doesn’t work, I suspect that the domain name resolution needs skipping in ONLYOFFICE for the special case of localhost when the services.sql.type is set to mariadb , the sql section from the local.json is at the top of the post above and I’ve tried restarting everything several times.

There should be no difference between localhost and 127.0.0.1 in this scenario. Could you please provide us with MariaDB logs? We will check them out. Additionally, please let us know your MariaDB version.

I’m using Debian Bullseye which provides MariaDB 10.5.18, there is nothing of interest in the MariaDB logs.

There is a difference between using localhost and 127.0.0.1, you can test this on any Debian server with MariaDB installed with the default settings as root

mysql -hlocalhost

Results in:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 249426
Server version: 10.5.18-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> ^DBye

Where as:

mysql -h127.0.0.1

Results in:

ERROR 2002 (HY000): Can't connect to MySQL server on '127.0.0.1' (115)

And also as a regular user:

mysql -hlocalhost -uonlyoffice -p onlyoffice

Results in:


Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 10.5.18-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [onlyoffice]> show tables;
+----------------------+
| Tables_in_onlyoffice |
+----------------------+
| doc_changes          |
| task_result          |
+----------------------+
2 rows in set (0.001 sec)

MariaDB [onlyoffice]> ^DBye

Where as:

mysql -h127.0.0.1 -uonlyoffice -p onlyoffice

Results in:

Enter password: 
ERROR 2002 (HY000): Can't connect to MySQL server on '127.0.0.1' (115)

I believe that this is because specifying the host as localhost results in a socket connection rather than a TCP/IP connection.

I haven’t managed to find a working configuration that allows connections to 127.0.0.1 using TCP/IP, if you have one could you let me know what it is?

Thank you for detailed information, we’re checking the situation.

1 Like

We reproduced the described scenario. All things are OK. Steps which have been made:

  1. We used Debian 11 with MariaDB 10.5.18.
  2. Document server was installed according to this guide:Installing ONLYOFFICE Docs for Debian, Ubuntu, and derivatives - ONLYOFFICE
  3. After that we installed MariaDB: apt update > apt install mariadb
  4. Added the user and created database:
mysql -u root -p

CREATE DATABASE onlyoffice;
CREATE USER 'onlyoffice'@'localhost' IDENTIFIED BY 'onlyoffice';
GRANT ALL ON onlyoffice.* TO 'onlyoffice'@'localhost' IDENTIFIED BY 'onlyoffice';
FLUSH PRIVILEGES;
  1. Ran database set up script:
cd /var/www/onlyoffice/documentserver/server/schema/mysql/
mysql -u onlyoffice -p < createdb.sql
  1. Changed ‘sql’ section in local.json file:
   "sql": {
        "type": "mariadb",
        "dbHost": "localhost",
        "dbPort": "3306",
        "dbName": "onlyoffice",
        "dbUser": "onlyoffice",
        "dbPass": "onlyoffice"
      },
  1. All services were restarted: systemctl restart ds-*

For the final step we checked out the editor itself. All things were OK. No issue was detected.

Probably the described issue from your posts is related to some restriction of TCP/IP connections or some changed settings of MariaDB since the issue doesn’t reproduce on clean server with the installation from scratch. We tried to check out this scenario and added skip-networking to /etc/mysql/mariadb.conf.d/50-server.cnf and then systemctl restart mariadb
1

As you can see, we faced similar error entries as you did.

1 Like

I’m not sure that I can replicate your MariaDB configuration.

On a brand new Debian Bullseye VPS:

cat /etc/debian_version 
11.6
apt install mariadb-server

Results in:

The following NEW packages will be installed:
galera-4 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl libmariadb3 libsnappy1v5 lsof mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common
mariadb-server mariadb-server-10.5 mariadb-server-core-10.5 mysql-common psmisc rsync socat

Then:

mysql -hlocalhost -e "SHOW databases;"

Returns:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

But:

mysql -h127.0.0.1 -e "SHOW databases;"

Returns:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Above you report running mysql -u root -p – there is no password authentication for root by default, there is no password set as socket authentication is used, so it sounds as if there might be some MariaDB configuration steps you haven’t documented, did you set a root password?

However having said that, after adding a regular user it is working using 127.0.0.1 and localhost :slight_smile: .

mysql -h127.0.0.1 -uonlyoffice -p onlyoffice
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2035
Server version: 10.5.18-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [onlyoffice]> show tables;
+----------------------+
| Tables_in_onlyoffice |
+----------------------+
| doc_changes          |
| task_result          |
+----------------------+
2 rows in set (0.001 sec)

MariaDB [onlyoffice]> ^DBye

So I feel I owe you an apology for wasting your time – there must have been some MariaDB configuration on the old server causing the issue, however I’m still unsure what that was.

1 Like

We are glad to have helped.

there must have been some MariaDB configuration on the old server causing the issue, however I’m still unsure what that was.

Unfortunately, I’m not sure how to troubleshoot your old server (MariaDB) and what could be the problem. Probably it’s better to deploy your installation on a clean server to avoid dependencies and settings conflicts.

1 Like

Thanks again @Alexandre, I have tracked down the setting that was preventing connections to 127.0.0.1 but allowing them to localhost – it was a systemd setting I had added to a /etc/systemd/system/mariadb.service.d/mariadb.conf file I created ages ago and forgot about :roll_eyes: :

[Service]
PrivateNetwork=true

By default this is set to False.

2 Likes

Great job! We are glad that you managed the situation. Please feel free to contact us if you face any issues.