当前位置:网站首页>Haproxy+kept build 01
Haproxy+kept build 01
2022-07-03 08:01:00 【zhqlee】
haproxy+keepalived build 01
Preface
Installation mode :yum Server environment :Centos7.5haproxy edition :1.5.18 The goal is : Realize two haproxy Dual server hot standby , To solve the problem haproxy Server single point of failure , Realize the high availability of the server ;
1、 preparation
1.1 Server preparation
- haproxy11:192.168.45.11
- haproxy12:192.168.45.12
- fictitious ip Address :192.168.145.10
1.2 Turn off firewall
# View firewall status , If the state is “running”, So close it !
firewall-cmd --state
# Turn off firewall
systemctl stop firewalld
1.3 Set up selinux
setenforce 0
2、haproxy Installation and configuration
haproxy11 And haproxy12 The installation and configuration are completely consistent
2.1 install
yum -y install haproxy
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
vi /etc/haproxy/haproxy.cfg
2.2 haproxy.cfg To configure
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log 127.0.0.1 local1
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen stats
bind 0.0.0.0:8888
mode http
stats enable
stats hide-version
stats uri /haproxystats
stats realm Haproxy\ stats
stats auth admin:admin
stats admin if TRUE
frontend http-in
bind 0.0.0.0:5672
mode tcp
log global
option httplog
option httpclose
default_backend rabbitmq-server
backend rabbitmq-server
mode tcp
balance roundrobin
server node1 192.168.45.201:5672 maxconn 2000 weight 1 check inter 5s rise 2 fall 2
server node2 192.168.45.202:5672 maxconn 2000 weight 1 check inter 5s rise 2 fall 2
server node3 192.168.45.203:5672 maxconn 2000 weight 1 check inter 5s rise 2 fall 2
2.3 rsyslog Log configuration
vi /etc/rsyslog.conf
# Provides UDP syslog reception
# Open the following configuration
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
# Open the following configuration
$ModLoad imtcp
$InputTCPServerRun 514
# Save boot messages also to boot.log
# Add the following configuration
local1.* /var/log/haproxy/haproxy.log
2.4 Start the service
# Create log folder
mkidr /var/log/haproxy
# Start log service
systemctl restart rsyslog.service
# start-up haproxy
systemctl start haproxy
# see haproxy start log
cat /var/log/haproxy/haproxy.log
# Real-time view haproxy journal
tail -f /var/log/haproxy.log
2.5 Login and verify
haproxy11 Manage background address :192.168.45.11:8888/haproxystats
haproxy12 Manage background address :192.168.45.12:8888/haproxystats
account number :admin
password :admin


3、 Installation and configuration keepalived
stay haproxy11 And haproxy12 Install separately in keepalived
3.1 install keepalived
yum -y install keepalived
3.2 To configure keepalived(haproxy11)
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
keepalived.conf Configure the content
! Configuration File for keepalived
global_defs {
router_id director1
}
vrrp_script check_haproxy {
script "/etc/keepalived/haproxy_chk.sh"
interval 5
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.45.10
}
track_script {
check_haproxy
}
}
3.3 To configure keepalived(haproxy12)
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
keepalived.conf Configure the content
! Configuration File for keepalived
global_defs {
router_id director2
}
vrrp_script check_haproxy {
script "/etc/keepalived/haproxy_chk.sh"
interval 5
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 80
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.45.10
}
track_script {
check_haproxy
}
}
3.4 Configure health detection scripts haproxy_chk.sh
haproxy11 And haproxy12 The configuration in is the same !
#!/usr/bin/env bash
# test haproxy server running
systemctl status haproxy.service &>/dev/null
if [ $? -ne 0 ];then
systemctl start haproxy.service &>/dev/null
sleep 5
systemctl status haproxy.service &>/dev/null
if [ $? -ne 0 ];then
systemctl stop keepalived
fi
fi
3.5 Verify virtual IP
systemctl start keepalived
# stay haproxy11 and haproxy12 In case of successful startup , Respectively in haproxy11 and haproxy12 Run the following command in
ip addr

Stop haproxy11 The server stay haproxy12 View in ip Address :


4、 Related startup commands
firewall-cmd --state
systemctl stop firewalld && setenforce 0
systemctl restart rsyslog.service
systemctl start haproxy
systemctl start keepalived
systemctl status haproxy
5、 Problems encountered
5.1 Network card problem
When it's done haproxy + keepalived After the dual active hot standby server , It was found during the test that , When one of them is completely shut down haproxy After the server , Find out :IP The address cannot be displayed normally , namely :ip addr And other related commands , There is no previous configuration IP Address information , And use commands :systemctl restart network.service Will report a mistake :
Solution :
# see NetworkManager state
systemctl status NetworkManager
# NetworkManager and network There are two different services , They are conflicting . The most fundamental solution is to NetworkManager Service stopped
# Pause , After the server restarts, it will still start
systemctl stop NetworkManager
# Permanent stop
systemctl disable NetworkManager
# Start network service
systemctl start network.service
# see IP Address , See if it works . If it still doesn't work , Then restart the server !
ip addr
5.2 keepalived Service issues
When it's done haproxy + keepalived After the dual active hot standby server , It was found during the test that , occasionally keepalived Even if the service is running , Still can't use vip visit haproxy The address of the server . Then you may need to restart keepalived service :
systemctl restart keepalived
边栏推荐
- Oracle insert single quotation mark
- vcs import src < ros2. Repos failed
- [cocos creator] get the resource UUID
- When did you find out that youth was over
- Redis批量启停脚本
- Huawei switch basic configuration (telnet/ssh login)
- regular expression
- [at] ABC 258g - triple Reach - violence
- Unity2019_ Natural ambient light_ Sky box
- JS to implement publish and subscribe
猜你喜欢

C language learning notes (mind map)

What is a data type? What is the use of data types?

Unity2019_ Lighting system

Research shows that breast cancer cells are more likely to enter the blood when patients sleep
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

Viz artist advanced script video tutorial -- stringmap use and vertex operation

Getting started with minicom

LwIP learning socket (application)

L'installateur a été installé avec une erreur inattendue

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
随机推荐
Idea unreference Display Effect
Transfinite hacker cognition
PostGIS space function
A tunnel to all ports of the server
Pulitzer Prize in the field of information graphics - malofiej Award
Yolo series --- xml2txt script
Pat class a 1032 sharing
Microsoft Security Response Center
Screenshot tool snipaste
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
Huawei switches are configured with SSH login remote management switches
什麼是定義?什麼是聲明?它們有何區別?
STM32F103 SPI (pit Diary)
When did you find out that youth was over
An intern's journey to cnosdb
Static keyword
Technical dry goods | some thoughts on the future of AI architecture
华为S5700交换机初始化和配置SSH和TELNET远程登录方法
C2 several methods of merging VCF files
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task