当前位置:网站首页>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.5
haproxy 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
边栏推荐
- the installer has encountered an unexpected error installing this package
- E: 无法定位软件包 ros-melodic-desktop-full
- static关键字
- [MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
- Clip Related Script
- Usage of (case, when) in PostgreSQL
- Generate video using clipout in viz engine
- Docker installs MySQL and successfully uses Navicat connection
- YOLO系列 --- xml2txt脚本
- Use filechannel to copy files
猜你喜欢
the installer has encountered an unexpected error installing this package
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Unity2019_ Natural ambient light_ Sky box
Transfinite hacker cognition
Screenshot tool snipaste
Ventuz Foundation Series "one step at the door"
My touch screen production "brief history" 2
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
What to do after the browser enters the URL
Research shows that breast cancer cells are more likely to enter the blood when patients sleep
随机推荐
Generate video using clipout in viz engine
Pulitzer Prize in the field of information graphics - malofiej Award
MAE
Huawei switch basic configuration (telnet/ssh login)
Redis profile
idea取消引用顯示效果
Are you still watching the weather forecast on TV?
the installer has encountered an unexpected error installing this package
freetype库的移植
Demonstration of plug-in use of ventuz basic series
Pat class a 1030 travel plan
Unity dotween sequence animation replay problem.
P2622 light off problem II (state compression search)
Pat class a 1028 list sorting
Precautions for opensips and TLS SIP trunk docking
Lua framwrok framework starts
一篇文章让你读懂-曼彻斯特编码
The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
STM32F103 SPI (pit Diary)
How to configure GDAL under idea