在CentOS中进行负载均衡配置可以通过多种方法实现,以下是几种常见的方法:
ipvsadm
和keepalived
。yum install -y ipvsadm keepalived
/etc/keepalived/keepalived.conf
文件,配置VRRP实例和虚拟IP地址(VIP)。vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.2.254
}
}
systemctl start keepalived
systemctl enable keepalived
yum install nginx -y
/etc/nginx/nginx.conf
文件,添加负载均衡配置。http {
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://backend;
}
}
}
systemctl start nginx
systemctl enable nginx
yum install haproxy -y
/etc/haproxy/haproxy.cfg
文件,添加负载均衡配置。global
log /dev/log local0
log /dev/log local1 notice
maxconn 4096
tune.ssl.default-dh-param 2048
defaults
log global
mode http
option httplog
option dontlognull
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
frontend http-in
bind *:80
default_backend servers
backend servers
balance roundrobin
server server1 192.168.0.101:80
server server2 192.168.0.102:80
systemctl start haproxy
systemctl enable haproxy
以上是在CentOS系统中进行负载均衡配置的几种常见方法。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:CentOS如何进行负载均衡配置