当前位置:网站首页>Haproxy+kept cluster setup 02
Haproxy+kept cluster setup 02
2022-07-03 08:01:00 【zhqlee】
haproxy+keepalived Cluster building 02
- Preface
- 1 install haproxy
- 1.1 download
- 1.2 Installation dependency
- 1.3 compile
- 1.4 Create a directory of configuration files
- 1.5 Add configuration file soft connection
- 1.6 Copy the error page and add directory soft connection (HTTP Matching mode )
- 1.7 Copy the startup file and authorize
- 1.8 add to haproxy Command script soft link
- 1.9 Set up HAProxy Boot up
- 1.10 add to haproxy User groups and users and create chroot Running path
- 1.11 haproxy The configuration file
- 2 install rsyslog The log service
- 3、 Open port
- 4、 Turn on haproxy And verify
- 5、 install keepalived( Customize )
- 6、 verification keepalived
Preface
Installation mode : Custom installation Server environment :Centos7.5haproxy edition :2.5.7keepalived edition :2.0.20
1 install haproxy
1.1 download
HAProxy The official download address is : https://www.haproxy.org/#down, If this site is inaccessible , You can also get it from hkps:/src.fedoraproject.org/repo/pkgs/haproxy/ Download from . What I download here is 2.5.7 edition , Download it and go through xftp And other tools upload the compressed package to the server /usr/app/ Under the table of contents , among app Folders need to be created in advance , Then decompress :
cd /usr/local
tar -zxvf haproxy-2.5.7.tar.gz
1.2 Installation dependency
yum -y install make gcc gcc-c++ libpcre3-dev openssl libssl-dev zlib1g-dev
1.3 compile
cd /usr/local/haproxy-2.5.7
make TARGET=3100 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install TARGET=3100 ARCH=x86_64 PREFIX=/usr/local/haproxy
1.4 Create a directory of configuration files
mkdir -p /usr/local/haproxy/conf
mkdir -p /etc/haproxy/
1.5 Add configuration file soft connection
touch /usr/local/haproxy/conf/haproxy.cfg
ln -s /usr/local/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg
1.6 Copy the error page and add directory soft connection (HTTP Matching mode )
cp -r /usr/local/haproxy-2.5.7/examples/errorfiles /usr/local/haproxy/
ln -s /usr/local/haproxy/errorfiles /etc/haproxy/errorfiles
1.7 Copy the startup file and authorize
cp /usr/local/haproxy-2.5.7/examples/haproxy.init /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
1.8 add to haproxy Command script soft link
ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin
1.9 Set up HAProxy Boot up
chkconfig --add haproxy
chkconfig haproxy on
1.10 add to haproxy User groups and users and create chroot Running path
HAProxy The configuration file has specified users and user groups , as well as chroot Running path :
groupadd haproxy
useradd -g haproxy haproxy
mkdir /usr/share/haproxy
1.11 haproxy The configuration file
vi /usr/local/haproxy/conf/haproxy.cfg
The contents of the configuration file are as follows :
global
log 127.0.0.1 local0
chroot /usr/share/haproxy
group haproxy
user haproxy
daemon
maxconn 4096
node edu-haproxy-01
description edu-haproxy-01
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:8000
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 rabbitmq-node1 192.168.45.201:5672 maxconn 2000 weight 1 check inter 5s rise 2 fall 2
server rabbitmq-node2 192.168.45.202:5672 maxconn 2000 weight 1 check inter 5s rise 2 fall 2
server rabbitmq-node3 192.168.45.203:5672 maxconn 2000 weight 1 check inter 5s rise 2 fall 2
2 install rsyslog The log service
2.1 install
yum -y install rsyslog
2.2 To configure
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
2.3 Add configuration file
stay /etc/rsyslog.d/ Create under directory haproxy Log profile for haproxy.log
vi /etc/rsyslog.d/haproxy.log
Add the configuration as follows :
local0.* /var/log/haproxy.log
&~
2.4 restart rsyslog service
systemctl restart rsyslog.service
3、 Open port
Need reference haproxy Configuration file in “/usr/local/haproxy/conf/haproxy.cfg”, You can open which ports are used in this file ; I've used... Here 8000 and 5672 port ;
# View firewall status , If the firewall is not turned on , Then you need to turn on the firewall first
firewall-cmd --state
# Turn on the firewall
systemctl start firewalld.service
# View open ports
firewall-cmd --list-ports
# Open the specified port
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --zone=public --add-port=5672/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload
4、 Turn on haproxy And verify
systemctl start haproxy
systemctl status haproxy
Manage background address :http://192.168.45.191:8000/haproxystats
account number :admin
password :admin

5、 install keepalived( Customize )
Follow the above steps to install two haproxy:
haproxy-01:192.168.45.191
haproxy-02:192.168.45.192 Plan to configure virtual ip:192.168.45.190
5.1 Download and unzip
Download address :https://www.keepalived.org/download.html
cd /usr/local/
tar -zxvf keepalived-2.0.20.tar.gz
5.2 Installation dependency
yum -y install openssl-devel libnl libnl-devel
5.3 Compilation and installation
cd keepalived-2.0.20/
./configure --prefix=/usr/local/keepalived
make && make install
The following file path will be generated after compilation and installation :
/usr/local/etc/keepalived/keepalived.conf
/usr/local/etc/sysconfig/keepalived
/usr/local/sbin/keepalived
5.4 To configure
# keepalived Startup script variable reference file , The default file path is /etc/sysconfig/, Also can not do soft link , Directly modify the file path in the startup script ( Installation directory )
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
# take keepalived The main program is added to the environment variable ( Installation directory )
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
# keepalived The startup script ( Source directory ), Put it in /etc/init.d/ It can be used in the directory service Command is easy to call
cp /usr/local/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
# take keepalived Put the configuration file in the default path
mkdir /etc/keepalived
touch /etc/keepalived/keepalived.conf
haproxy-01 Of keepalived.conf The contents of the configuration file are as follows :
! 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.190
}
track_script {
check_haproxy
}
}
haproxy-02 Of keepalived.conf The contents of the configuration file are as follows :
! 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.190
}
track_script {
check_haproxy
}
}
5.5 Set boot up
# Add as system service
chkconfig –-add keepalived
# Set boot up
chkconfig keepalived on
# start-up 、 close 、 restart 、 see keepalived
systemctl starts keepalived
systemctl stop keepalived
systemctl restart keepalived
systemctl status keepalived
6、 verification keepalived


边栏推荐
- 链式长取值
- [cocos creator] Click the button to switch the interface
- Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
- 多旅行商问题——公式和求解过程概述
- Worldview satellite remote sensing image data / meter resolution remote sensing image
- P2704 [NOI2001] 炮兵阵地(状压dp)
- Register keyword
- Lua framwrok framework starts
- JSON与Object之间转换
- How to clear the console password for s7700 device
猜你喜欢

LwIP learning socket (application)

Zohocrm deluge function application time verification
![[global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel](/img/51/04f5a9dbd03438fbdf25545a81b7ba.jpg)
[global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel

Wpf: solve the problem that materialdesign:dialoghost cannot be closed

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03

WPF:解决MaterialDesign:DialogHost 无法关闭问题

Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task

WorldView卫星遥感影像数据/米级分辨率遥感影像
![[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)](/img/38/3435d353e50b19fe09c8ab9db52204.png)
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)

vcs import src < ros2. Repos failed
随机推荐
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
Wechat applet taro learning record
How to configure GDAL under idea
oracle 插入单引号
What to do after the browser enters the URL
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
E: 无法定位软件包 ros-melodic-desktop-full
Oracle insert single quotation mark
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
The general trend of data news releases the power of visual reporting ----- essays after reading
Ilruntime learning - start from scratch
Redis view client connection
Redis配置文件
Clip Related Script
oracle中的 (+)是什么意思
华为交换机Console密码重置、设备初始化、默认密码
C2 several methods of merging VCF files
YOLO系列 --- xml2txt脚本
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Unity performance optimization