usmannasir / cyberpanel

Cyber Panel - The hosting control panel for OpenLiteSpeed
GNU General Public License v3.0
1.58k stars 610 forks source link

Installation error and “ERROR - 500” Post Installation on AWS EC2 with RDS as Remote MySQL Server #936

Open kghosh007 opened 2 years ago

kghosh007 commented 2 years ago

After 2 successful years with CyberPanel, I encountered a peculiar problem few days ago. Inatalling CyberPanel with Remote SQL always leading to failures, error 1045 in CyberPanel.

django.db.utils.OperationalError: (1045, "Access denied for user 'cyberpanel'@'172.31.26.240' (using password: YES)")

Here's are the Steps i performed and Possible Cause for this to Happen:

My Server Architecture:

  1. AWS EC2 as the server with c6a type instances.
  2. AlmaLinux 8.x / Ubuntu Minimal 20.xx as OS
  3. AWS RDS MariaDB with Read Replica for Database
  4. AWS S3 for Static Assets serving
  5. AWS CloudFront for CDN

    Screenshot 2022-07-24 100730

Here's the Post-Installation Result.

AWS EC2 instances have 2 type of ips, one is internal private ip, which is not accessible to the public, and another is Elastic IP, which is a Static Public IP. Look at the Screenshot Below: Screenshot 2022-07-24 100637

Note the Public and Private IP here.

Private IP: 172.31.26.240
Public IP: 43.204.104.194

When CyberPanel is getting installed, it Creates a USER CyberPanel, limiting the connecting host to matching the IP of Server.

Here, from the screenshot, you can see that the CYBERPANEL user is Created, limiting the host to Public IP address of the Instance : 43.204.104.194 Screenshot (16)

which can be re-verified via MySQL Workbench Screenshot: 2


After this , as per my understanding of the Installation Logs, a local instance of Mariadb Server is created and then the details are migrated to Remote SQL via:

[07.23.2022_21-27-28] Running: /usr/local/CyberPanel/bin/python manage.py makemigrations

That's when the Problem Occurs. if we go through the logs we can see:

Traceback (most recent call last):
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 234, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/MySQLdb/__init__.py", line 130, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'cyberpanel'@'172.31.26.240' (using password: YES)")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
    loader.check_consistent_history(connection)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
    applied = recorder.applied_migrations()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
    if self.has_table():
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
    with self.connection.cursor() as cursor:
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
    return self._cursor()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
    self.ensure_connection()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 234, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/MySQLdb/__init__.py", line 130, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/CyberPanel/lib/python3.6/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'cyberpanel'@'172.31.26.240' (using password: YES)")

The database is accessed with username cyberpanel, but the connecting IP has changed to the PRIVATE IP of the Instance i.e. 172.31.26.240.

This is when everything falls apart, and the installation fails. I don't think this will take to much time of you guys to resolve this, and my production server actually depends on this. So i Request you to look into it.

If there is any wrong in my installing technique, kindly let me know.

and Thanks Again for such an wonderful product that the market was void of for a very long time.

As per my understanding, this fix will also solve majority of remote sql related problems here

kghosh007 commented 2 years ago

@qtwrk @usmannasir Hi, Can you confirm this issue? even after I bypass this issue, after login, when I'm creating a WordPress website, the same problem persists. ["ERROR 1045 (28000): Access denied for user '6JnFUEeumYccOl'@'172.31.23.251' (using password: YES)"," [404]"] mw The user is being created based upon the public ip, and is being accessed with private / Localhost ip

zining3235 commented 2 years ago

Aha, I just encountered the same problem. After the installation, I visited ip:8090, error 500

kghosh007 commented 2 years ago

Yes, and debugging all options, what I have found is that, this PUBLIC IP / PRIVATE IP conflict is causing this issue.

kghosh007 commented 2 years ago

Aha, I just encountered the same problem. After the installation, I visited ip:8090, error 500

What's your log says? Databases created successfully? are you using remote sql?

kenny-nt commented 2 years ago

Hi @kghosh007, With my experience, there 2 ways: (While waiting new version fixing private IP and public IP)

Solution 1:

Solution 2:

CREATE DATABASE cyberpanel;
CREATE USER 'cyberpanel'@'172.31.26.240' IDENTIFIED BY 'password of cypernel from settings.py';
GRANT INDEX, DROP, UPDATE, ALTER, CREATE, SELECT, INSERT, DELETE ON cyberpanel.* TO 'cyberpanel'@'172.31.26.240';

Edit: /usr/local/CyberCP/CyberCP/settings.py and update at line 110 Edit: /etc/cyberpane/mysqlPassword update to: {"remotemysql": "ON", "mysqlhost": "RDS_HOSTNAME", "mysqldb": "mysql", "mysqluser": "RDS_User", "mysqlpassword": "RDS_Admin_Pass", "mysqlport": "3306"}