experius / SeoSnap

Server Side Rendering (SSR) for javascript applications
GNU General Public License v3.0
52 stars 12 forks source link

Cannot connect to database #3

Closed habitatcreative closed 4 years ago

habitatcreative commented 4 years ago

Hello,

I am following the instructions, but I am experiencing a strange error on docker-compose up

Seems like dashboard_1 cannot connect to the database. I am using your default settings in .env as I also tried my own.

Will appreciate your help. I am including a larger output, because it happens a few times and one time is stating:

"Host '192.168.80.4' is not allowed to connect to this MySQL server"

but before that it's:

"Can't connect to MySQL server on 'db' (115)"

Here is the output:

dashboard_1 | Traceback (most recent call last): dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection dashboard_1 | self.connect() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(*args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect dashboard_1 | self.connection = self.get_new_connection(conn_params) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection dashboard_1 | return Database.connect(conn_params) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/MySQLdb/init.py", line 84, in Connect dashboard_1 | return Connection(args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in init dashboard_1 | super(Connection, self).init(*args, kwargs2) dashboard_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)") dashboard_1 | dashboard_1 | The above exception was the direct cause of the following exception: dashboard_1 | dashboard_1 | Traceback (most recent call last): dashboard_1 | File "./manage.py", line 21, in dashboard_1 | main() dashboard_1 | File "./manage.py", line 17, in main dashboard_1 | execute_from_command_line(sys.argv) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/init.py", line 401, in execute_from_command_line dashboard_1 | utility.execute() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/init.py", line 395, in execute dashboard_1 | self.fetch_command(subcommand).run_from_argv(self.argv) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv dashboard_1 | self.execute(*args, cmd_options) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 366, in execute dashboard_1 | self.check() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 395, in check dashboard_1 | include_deployment_checks=include_deployment_checks, dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 63, in _run_checks dashboard_1 | issues = run_checks(tags=[Tags.database]) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks dashboard_1 | new_errors = check(app_configs=app_configs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/database.py", line 10, in check_database_backends dashboard_1 | issues.extend(conn.validation.check(kwargs)) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/validation.py", line 9, in check dashboard_1 | issues.extend(self._check_sql_mode(*kwargs)) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode dashboard_1 | with self.connection.cursor() as cursor: dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 260, in cursor dashboard_1 | return self._cursor() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 236, in _cursor dashboard_1 | self.ensure_connection() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(*args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection dashboard_1 | self.connect() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 90, in exit dashboard_1 | raise dj_exc_value.with_traceback(traceback) from exc_value dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection dashboard_1 | self.connect() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(*args, *kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect dashboard_1 | self.connection = self.get_new_connection(conn_params) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection dashboard_1 | return Database.connect(conn_params) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/MySQLdb/init.py", line 84, in Connect dashboard_1 | return Connection(*args, *kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in init dashboard_1 | super(Connection, self).init(args, kwargs2) dashboard_1 | django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)") dashboard_1 | Admin: snaptron db_1 | 2020-02-26T10:19:12.533296Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. db_1 | 2020-02-26T10:19:12.549801Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. db_1 | 2020-02-26T10:19:12.588375Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL. db_1 | 2020-02-26T10:19:12.706303Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060 cachewarmer_1 | Usage: crawl.py [OPTIONS] COMMAND [ARGS]... cachewarmer_1 | cachewarmer_1 | Options: cachewarmer_1 | --help Show this message and exit. cachewarmer_1 | cachewarmer_1 | Commands: cachewarmer_1 | cache cachewarmer_1 | clean cachewarmer_1 | load cacheserver_1 | 2020-02-26 10:19:12,757 INFO spawned: 'nginx' with pid 10 cacheserver_1 | 2020-02-26 10:19:12,760 INFO spawned: 'uwsgi' with pid 11 cacheserver_1 | [uWSGI] getting INI configuration from /app/uwsgi.ini cacheserver_1 | [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini cacheserver_1 | cacheserver_1 | ;uWSGI instance configuration cacheserver_1 | [uwsgi] cacheserver_1 | cheaper = 2 cacheserver_1 | processes = 16 cacheserver_1 | ini = /app/uwsgi.ini cacheserver_1 | module = rendertron_cache_server.wsgi cacheserver_1 | callable = application cacheserver_1 | enable-threads = true cacheserver_1 | ini = /etc/uwsgi/uwsgi.ini cacheserver_1 | socket = /tmp/uwsgi.sock cacheserver_1 | chown-socket = nginx:nginx cacheserver_1 | chmod-socket = 664 cacheserver_1 | hook-master-start = unix_signal:15 gracefully_kill_them_all cacheserver_1 | need-app = true cacheserver_1 | die-on-term = true cacheserver_1 | show-config = true cacheserver_1 | ;end of configuration cacheserver_1 | cacheserver_1 | Starting uWSGI 2.0.18 (64bit) on [Wed Feb 26 10:19:12 2020] cacheserver_1 | compiled with version: 6.3.0 20170516 on 14 October 2019 23:20:32 cacheserver_1 | os: Linux-4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 cacheserver_1 | nodename: dec3bf2a821b cacheserver_1 | machine: x86_64 cacheserver_1 | clock source: unix cacheserver_1 | pcre jit disabled cacheserver_1 | detected number of CPU cores: 6 cacheserver_1 | current working directory: /app cacheserver_1 | detected binary path: /usr/local/bin/uwsgi cacheserver_1 | your memory page size is 4096 bytes cacheserver_1 | detected max file descriptor number: 1048576 cacheserver_1 | lock engine: pthread robust mutexes cacheserver_1 | thunder lock: disabled (you can enable it with --thunder-lock) cacheserver_1 | uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3 cacheserver_1 | uWSGI running as root, you can use --uid/--gid/--chroot options cacheserver_1 | WARNING: you are running uWSGI as root !!! (use the --uid flag) cacheserver_1 | Python version: 3.7.4 (default, Sep 12 2019, 16:02:06) [GCC 6.3.0 20170516] cacheserver_1 | Python main interpreter initialized at 0x559e71e38750 cacheserver_1 | uWSGI running as root, you can use --uid/--gid/--chroot options cacheserver_1 | WARNING: you are running uWSGI as root !!! (use the --uid flag) cacheserver_1 | python threads support enabled cacheserver_1 | your server socket listen backlog is limited to 100 connections cacheserver_1 | your mercy for graceful operations on workers is 60 seconds cacheserver_1 | mapped 1239640 bytes (1210 KB) for 16 cores cacheserver_1 | Operational MODE: preforking seosnap_cachewarmer exited with code 0 cacheserver_1 | WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x559e71e38750 pid: 11 (default app) cacheserver_1 | uWSGI running as root, you can use --uid/--gid/--chroot options cacheserver_1 | WARNING: you are running uWSGI as root !!! (use the --uid flag) cacheserver_1 | uWSGI is running in multiple interpreter mode cacheserver_1 | spawned uWSGI master process (pid: 11) cacheserver_1 | spawned uWSGI worker 1 (pid: 13, cores: 1) cacheserver_1 | spawned uWSGI worker 2 (pid: 14, cores: 1) cacheserver_1 | running "unix_signal:15 gracefully_kill_them_all" (master-start)... dashboard_1 | Traceback (most recent call last): dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection dashboard_1 | self.connect() dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(*args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect dashboard_1 | self.connection = self.get_new_connection(conn_params) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner dashboard_1 | return func(args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection dashboard_1 | return Database.connect(conn_params) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/MySQLdb/init.py", line 84, in Connect dashboard_1 | return Connection(args, kwargs) dashboard_1 | File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in init dashboard_1 | super(Connection, self).init(*args, **kwargs2) dashboard_1 | MySQLdb._exceptions.OperationalError: (1130, "Host '192.168.80.4' is not allowed to connect to this MySQL server")

egordm commented 4 years ago

Hey @habitatcreative,

Did you get this error at the first startup? If so, it is a known issue that on the first startup mysql server needs to create the files and is therefore not reachable for a moment. Waiting till database is done and restarting all the services should fix it. Currently fixing this is high on the todo list.

If it didn't help you let me know.

habitatcreative commented 4 years ago

Hey,

Thank you for the quick reply :)

I tried waiting and restarting, but no luck. I tried opening phpMyAdmin at http://127.0.0.1:8081/, but I get the same error.

MySQL said: Documentation

Cannot connect: invalid settings.

 mysqli::real_connect(): (HY000/1130): Host '192.168.176.5' is not allowed to connect to this MySQL server

 phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

I am using Docker on a Mac if this makes any difference

habitatcreative commented 4 years ago

Hi, It seems that my issue may have been resolved.

Two things happened:

  1. I had a .env file present apart from the main one. Both had the default values I think, so after I re-cloned everything it got fixed, so I was at least able to login to phpMyAdmin. This is my bad and I am sorry to waste your time with it.

  2. After the re-clone and docker-compose up it seemed that no database tables were created. I also got the message

    dashboard_1    | You have 22 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, guardian, seosnap, sessions.
    dashboard_1    | Run 'python manage.py migrate to apply them.

    So after a login to the container, applying the migrations and docker-compose up, everything seems to be running now and I was able to login to the dashboard.