Ubuntu 上实现 Oracle 负载均衡的可落地方案
一、方案总览与选型
二、数据库层原生负载均衡(Oracle RAC)
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE = YES)
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan.example.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
)
srvctl start database -db orcl
srvctl stop database -db orcl
srvctl start listener
srvctl stop listener
srvctl start instance -db orcl -instance orcl1
三、连接层代理负载均衡(HAProxy/Nginx,Ubuntu 16.04/18.04/20.04/22.04)
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
defaults
log global
mode tcp
option tcplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend oracle_front
bind *:1521
default_backend oracle_back
backend oracle_back
balance leastconn
option tcp-check
server db1 192.168.1.101:1521 check
server db2 192.168.1.102:1521 check
sudo systemctl restart haproxy
sudo systemctl enable haproxy
events { worker_connections 1024; }
stream {
upstream oracle_backend {
least_conn;
server 192.168.1.101:1521;
server 192.168.1.102:1521;
}
server {
listen 1521;
proxy_pass oracle_backend;
proxy_timeout 50s;
proxy_responses 1;
}
}
sudo systemctl restart nginx
sudo systemctl enable nginx
四、高可用与验证
v$session 中观察连接分布。五、关键注意事项