无法连接到虚拟 IP 负载均衡器直接到 mysql 服务器

无法连接到虚拟 IP 负载均衡器直接到 mysql 服务器

我无法通过虚拟 IP 连接到数据库服务器

https://towardsdatascience.com/high-availability-mysql-cluster-with-load-balancing-using-haproxy-and-heartbeat-40a16e134691

我按照本指南操作,但当我的网络服务器尝试连接它时,它失败了

sudo mysql -u wordpress -h 192.168.122.98 -p

Enter password:

ERROR 1045 (28000): Access denied for user 'wordpress'@'db1' (using password: YES)

该接口的虚拟 IP 是:192.168.122.98

我的数据库 IP 是:192.168.122.187

我可以直接连接到数据库:

sudo mysql -u wordpress -h 192.168.122.187 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1724 Server version: 5.7.27-0ubuntu0.16.04.1-log (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights保留。`

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.

quan@db1:~$ ip addr show ens3

2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast

状态UP 组默认 qlen 1000`

link/ether 52:54:00:a1:83:fb brd ff:ff:ff:ff:ff:ff

`inet 192.168.122.187/24 brd 192.168.122.255 scope global ens3`

  ` valid_lft forever preferred_lft forever`

inet 192.168.122.98/24 brd 192.168.122.255 scope global secondary ens3:0 valid_lft forever preferred_lft forever

`inet6 fe80::5054:ff:fea1:83fb/64 scope link `

   `valid_lft forever preferred_lft forever`

答案1

将您的 Web 服务器 IP 添加到数据库:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'wordpress'@'YourWebServerIP' IDENTIFIED BY 'YourPassword' WITH GRANT OPTION;

相关内容