proxy SQL 集群状态异常

mysql> select hostgroup_id, hostname, port,status from runtime_mysql_servers order by hostgroup_id;
+--------------+-----------------+------+--------+
| hostgroup_id | hostname        | port | status |
+--------------+-----------------+------+--------+
| 1            | 192.168.211.129 | 3306 | ONLINE |
| 2            | 192.168.211.133 | 3306 | ONLINE |
| 2            | 192.168.211.134 | 3306 | ONLINE |
+--------------+-----------------+------+--------+

上图可以看出主库缺一个2的状态;查看proxy SQL日志如下:

[root@localhost /]# tail -f /data/proxysql/proxysql.log
2024-08-13 16:41:32 [INFO] New mysql_galera_hostgroups table
2024-08-13 16:41:32 [INFO] New mysql_aws_aurora_hostgroups table
2024-08-13 16:41:32 [INFO] MySQL_HostGroups_Manager::commit() locked for 5ms
Standard Query Processor rev. 2.0.6.0805 -- Query_Processor.cpp -- Sun May 17 20:24:24 2020
In memory Standard Query Cache (SQC) rev. 1.2.0905 -- Query_Cache.cpp -- Sun May 17 20:24:24 2020
Standard MySQL Monitor (StdMyMon) rev. 2.0.1226 -- MySQL_Monitor.cpp -- Sun May 17 20:24:24 2020
2024-08-13 16:41:32 MySQL_Monitor.cpp:718:monitor_connect_thread(): [ERROR] Server 192.168.211.134:3306 is returning "Access denied" for monitoring user
2024-08-13 16:41:33 MySQL_Monitor.cpp:718:monitor_connect_thread(): [ERROR] Server 192.168.211.133:3306 is returning "Access denied" for monitoring user
2024-08-13 16:41:33 MySQL_Monitor.cpp:718:monitor_connect_thread(): [ERROR] Server 192.168.211.129:3306 is returning "Access denied" for monitoring user
2024-08-13 16:41:35 [INFO] Latest ProxySQL version available: 2.6.3-107-gcdfcfdc

解决办法如下:

先检查proxysql.cnf文件的密码和IP地址,然后执行如下命令:

[root@localhost /]# vi /etc/proxysql.cnf 
[root@localhost /]# rm -rf /var/lib/proxysql /data/proxysql
[root@localhost /]# mkdir /var/lib/proxysql /data/proxysql && chown -R proxysql:proxysql  /var/lib/proxysql /data/proxysql
[root@localhost /]# vi /data/proxysql.cnf 
[root@localhost /]# cd data/
[root@localhost data]# \cp -rf proxysql.cnf /etc/proxysql.cnf
[root@localhost data]# systemctl restart proxysql 

完美解决如下

[root@localhost data]# mysql -uadmin -padmin -h127.0.0.1 -P6032
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 1
Server version: 8.0.12 (ProxySQL Admin Module)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> select hostgroup_id, hostname, port,status from runtime_mysql_servers order by hostgroup_id;
+--------------+-----------------+------+--------+
| hostgroup_id | hostname        | port | status |
+--------------+-----------------+------+--------+
| 1            | 192.168.211.129 | 3306 | ONLINE |
| 2            | 192.168.211.129 | 3306 | ONLINE |
| 2            | 192.168.211.130 | 3306 | ONLINE |
| 3            | 192.168.211.128 | 3306 | ONLINE |
+--------------+-----------------+------+--------+
4 rows in set (0.04 sec)

### Nginx 中 `proxy_pass` 地址异常解决方案 当遇到 Nginx 的 `proxy_pass` 配置导致地址异常的问题时,通常可以从以下几个方面入手分析并解决问题。 #### 1. **检查 `proxy_pass` 是否正确配置** - 确保 `proxy_pass` 被放置在 `location` 块中[^2]。如果未放在 `location` 块中,则可能导致请求无法被正确转发。 - 如果使用了正则表达式的 `location`(如 `location ~ /api/ {}`),需注意 `proxy_pass` 不应附加 URI 参数,否则可能会引发错误。 #### 2. **验证目标服务器状态** - 确认后端服务是否正常运行,并监听指定的 IP 和端口。可以通过命令测试连接情况: ```bash curl -I http://192.168.243.129:8080/ ``` 若返回非预期的状态码(如 404 或 502),说明可能是后端服务本身存在问题[^3]。 #### 3. **调整 `proxy_set_header` 设置** - 默认情况下,Nginx 使用 `$host` 替代原始请求中的主机头字段。如果需要传递真实的客户端请求头部信息,可以设置以下参数: ```nginx proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ``` 此外,确保没有误配为 `$proxy_host`,因为这可能改变实际的目标地址[^1]。 #### 4. **处理路径重写问题** - 当 `proxy_pass` 后面带有斜杠 `/` 时,表示完全替换匹配到的部分;如果不带斜杠,则保留原路径的一部分。例如: ```nginx location /api/ { proxy_pass http://backend/; } ``` 上述配置会将 `/api/example` 请求转发至 `http://backend/example`。而如果没有结尾的斜杠: ```nginx location /api/ { proxy_pass http://backend; } ``` 则最终 URL 将变为 `http://backend/api/example`。 #### 5. **排查权限与文件访问限制** - 对于某些场景下的 403 错误,除了确认后端资源是否存在之外,还需核实前端静态文件夹及其子项是否有足够的读取权限[^4]。可尝试通过更改所有权来修复: ```bash chown -R nginx.nginx /path/to/html/* ``` #### 6. **日志诊断** - 开启详细的调试模式以便定位具体原因: ```nginx error_log /var/log/nginx/error.log debug; access_log /var/log/nginx/access.log main; ``` 查看最近的日志条目可以帮助发现潜在的语法或者逻辑缺陷。 以下是综合上述要点的一个典型示例配置: ```nginx server { listen 80; server_name www.a.com; location / { root /usr/share/nginx/html; index index.html index.htm; } location /api/ { proxy_pass http://192.168.243.129:8080/; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值