HAproxy&keepalived 實現tcp負載均衡
haproxy 安裝 (安裝到兩臺Server)
#untar the tar package to /usr/local/
tar -zxvf haproxy-1.7.3.tar.gz -C /usr/local/
to check the Linux Kernel version
uname -a
change directory to the haproxy-1.7.3
cd /usr/local/haproxy-1.7.3
make install, TARGET is the Linux Kernel version
make TARGET=linux26 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
cd /usr/local/haproxy
mkdir conf
mkdir logs- haproxy 配置(兩臺Server配置相同)
vi /usr/local/haproxy/conf/haproxy.cfg ##global config##
global
chroot /usr/local/haproxy
daemon
nbproc 1
group root
user root
pidfile /usr/local/haproxy/logs/haproxy.pid
ulimit-n 65536
#spread-checks 5m
#stats timeout 5m
#stats maxconn 100
##defalt config##
defaults
mode tcp # mode{tcp|http|health}, tcp is for 4th layer, http is for 7th layer
retries 3 # retry 3 times fail, the server is supposed to be unavailable
option redispatch # while the server download, enforce re-direct to other health server
option abortonclose # while the load is high, close the more logger connection automatically
maxconn 32000 # max connection
timeout connect 5000ms # connect timeout
timeout client 30000ms # client connect timeout
timeout server 30000ms # server connect timeout
#timeout check 2000 # heart check
log 127.0.0.1 local0 err #[err warning info debug]
##google mail##
listen google_mail
bind 10.103.219.60:8006
mode tcp
balance roundrobin
server s-67 10.103.219.67:41414 weight 1 maxconn 10000 check inter 10s
server s-68 10.103.219.68:41414 weight 1 maxconn 10000 check inter 10s
server s-69 10.103.219.69:41414 weight 1 maxconn 10000 check inter 10s
##google drive##
listen google_drive
bind 10.103.219.60:8007
mode tcp
balance roundrobin
server s-67 10.103.219.67:41424 weight 1 maxconn 10000 check inter 10s
server s-68 10.103.219.68:41424 weight 1 maxconn 10000 check inter 10s
server s-69 10.103.219.69:41424 weight 1 maxconn 10000 check inter 10s
##dropbox##
listen dropbox
bind 10.103.219.60:8008
mode tcp
balance roundrobin
server s-67 10.103.219.67:41434 weight 1 maxconn 10000 check inter 10s
server s-68 10.103.219.68:41434 weight 1 maxconn 10000 check inter 10s
server s-69 10.103.219.69:41434 weight 1 maxconn 10000 check inter 10s
##statistics##
listen proxy_stats
bind 0.0.0.0:8099 # listen port
mode http
option httplog # http log
#log 127.0.0.1 local0 err
maxconn 10
stats refresh 30s #
stats uri /proxy_stats # url of the statistics page
stats realm CASB Haproxy Statistics # prompt message
stats auth admin:admin #user and password
stats auth molly:molly #can set several user and password
#stats hide-version # hide version of haproxy
stats admin if TRUE - 服務開啟
vi /usr/local/haproxy/sbin/haproxy.sh
#!/bin/sh
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg &
chmod +x /usr/local/haproxy/sbin/haproxy.sh
# start the haproxy
./usr/local/haproxy/sbin/haproxy.sh # check haproxy is running
ps -ef| grep haproxy
- haproxy 配置(兩臺Server配置相同)
Keepalived 安裝(兩臺Server均安裝)
# prerequisites
apt-get install libssl-dev
#untar the tar package to /usr/local/
tar zxvf /home/molly/keepalived-1.3.5.tar.gz -C /usr/local/
# change directory to the keepalived-1.3.5
cd /usr/local/keepalived-1.3.5
# make install,
./configure --prefix=/usr/local/keepalived
make && make installkeepalived配置(master Server)
vi /usr/local/keepalived/etc/keepalived/keepalived.conf
global_defs {
notification_email {
mywang@xxx.com
}
notification_email_from keepalived@domain.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/usr/local/keepalived/check_haproxy.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER ## the other server is BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 10.103.219.71
priority 100 ##value is bigger than backup
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port ### monitoring service
}
virtual_ipaddress {
10.103.219.60
}
}
#check haproxy
vi /usr/local/keepalived/check_haproxy.sh
#!/bin/bash
if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then
./usr/local/haproxy/sbin/haproxy.sh
fi
sleep 2
if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then
service keepalived stop
fi
vi /usr/local/keepalived/sbin/keepalived.sh
#!/bin/sh
/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf &
chmod +x /usr/local/keepalived/sbin/keepalived.sh
# start keepalived
./usr/local/keepalived/sbin/keepalived.sh
# check virtual IP
ip addrkeepalived配置(backup Server)
global_defs {
notification_email {
mywang@xxxx.com
}
notification_email_from keepalived@domain.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/usr/local/keepalived/check_haproxy.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP ## BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 10.103.219.72
priority 99 ##value is smaller than master
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
#track_script {
# chk_http_port ### monitoring service
# }
virtual_ipaddress {
10.103.219.60
}
}
vi /usr/local/keepalived/check_haproxy.sh
#!/bin/bash
if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then
./usr/local/haproxy/sbin/haproxy.sh
fi
sleep 2
if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then
service keepalived stop
fi
vi /usr/local/keepalived/sbin/keepalived.sh
#!/bin/sh
/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf &
chmod +x /usr/local/keepalived/sbin/keepalived.sh
# start keepalived
./usr/local/keepalived/sbin/keepalived.sh
# check virtual IP
ip addr
相關文章
- Ribbon實現負載均衡負載
- GRPC 負載均衡實現RPC負載
- nginx實現負載均衡Nginx負載
- 使用Nginx配置TCP負載均衡NginxTCP負載
- HaProxy 實現 MySQL 負載均衡MySql負載
- nginx+tomcat實現負載均衡NginxTomcat負載
- dubbo(三):負載均衡實現解析負載
- 使用YARP來實現負載均衡負載
- Python實現簡單負載均衡Python負載
- 做了反向代理和負載均衡的nginx配置檔案簡單示例(nginx.conf) HTTP負載均衡/TCP負載均衡負載NginxHTTPTCP
- SpringCloud微服務中使用RestTemplate+Ribbon實現負載均衡(實現方法+實現原理+替換負載均衡策略)SpringGCCloud微服務REST負載
- Nginx實現簡單的負載均衡Nginx負載
- Haproxy搭建 Web 群集實現負載均衡Web負載
- 在Linux中,如何實現負載均衡?Linux負載
- Nginx如何實現四層負載均衡?Nginx負載
- Keepalived實現Nginx負載均衡高可用Nginx負載
- Docker Compose+nginx實現負載均衡DockerNginx負載
- orleans叢集及負載均衡實現負載
- DockerCompose編排Nginx+Mysql並實現Nginx配置Mysql(TCP協議)負載均衡DockerNginxMySqlTCP協議負載
- jmeter壓力測試實現負載均衡JMeter負載
- 伺服器負載均衡原理及實現伺服器負載
- nginx實現兩臺服務負載均衡Nginx負載
- nginx讓多個tomcat實現負載均衡NginxTomcat負載
- RHEL 7配置HAProxy實現Web負載均衡Web負載
- SpringCloud Fegin結合Ribbon實現負載均衡SpringGCCloud負載
- LVS+Keepalived 實現高可用負載均衡負載
- Nginx如何實現負載均衡釋出策略?Nginx負載
- haporxy+keepalived實現負載均衡+高可用負載
- LVS負載均衡群集概念、NAT模式LVS負載均衡實戰部署負載模式
- gRPC負載均衡(自定義負載均衡策略)RPC負載
- gRPC負載均衡(客戶端負載均衡)RPC負載客戶端
- 超實用:實現負載均衡技術的方式負載
- 負載均衡負載
- 淺談負載均衡演算法與實現負載演算法
- Spring Cloud:使用 Feign 實現負載均衡詳解SpringCloud負載
- keepalived+haproxy實現mysql負載均衡高可用MySql負載
- Go實現了一個負載均衡器Go負載
- 在 kubernetes 環境中實現 gRPC 負載均衡RPC負載
- SAP 應用服務負載均衡的實現負載