pcs+corosync+pacemaker+haproxy负载均衡环境部署
pcs+corosync+pacemaker+haproxy负载均衡环境部署
一、实验环境:
centos7.4
三台服务器做集群,两台服务器做后端web服务器
cos11:192.168.124.11
cos135 : 192.168.124.135
cos136 : 192.168.124.136
web后端服务器
cos10:192.168.124.10
cos40:192.168.124.40
cos11、cos135、cos136三台机器上面都安装pacemaker,因此下述操作都需要在三台机器上面都执行。
二、修改环境
1、cos11&cos135&cos136关闭firewalld及selinux防火墙
systemctl disable firewalld
systemctl stop firewalld
vim /etc/selinux/conf
SELINUX==disabled
2、配置hostname
cos11:
hostnamectl --static --transient set-hostname cos11
cos135:
hostnamectl --static --transient set-hostname cos135
cos136:
hostnamectl --static --transient set-hostname cos136
3.修改hosts
cos11&cos135&cos136:
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.124.11 cos11
192.168.124.135 cos135
192.168.124.136 cos136
4、时间同步
cos11&cos135&cos136:
yum install ntp -y
vim /etc/ntp.conf
# new(新增阿里云ntp服务器)
server ntp1.aliyun.com prefer
server ntp2.aliyun.com
timedatectl set-timezone Asia/Shanghai (设置时区)
ntpdate ntp1.aliyun.com (时间同步)
systemctl status ntpd (启动ntpd服务)
systemctl enable ntpd.service (ntpd服务设置开机自启动)
5、双机互信(本次实验发现,不配置双机互信似乎也不会出现问题):
[root@cos11 ~]#
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@cos135
ssh-copy-id -i ~/.ssh/id_rsa.pub root@cos136
[root@cos135 ~]#
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@cos11
ssh-copy-id -i ~/.ssh/id_rsa.pub root@cos136
[root@cos136 ~]#
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@cos11
ssh-copy-id -i ~/.ssh/id_rsa.pub root@cos135
6、安装pacemaker集群相关组件:
yum install pcs pacemaker corosync fence-agents-all -y
启动pcsd服务(开机自启动)
systemctl start pcsd.service
systemctl enable pcsd.service
7、创建集群用户:
passwd hacluster(此用户在安装pcs时候会自动创建,密码为hacluster)
上述所有操作都需要在三个集群服务器上面执行,下面命令只需要在一台集群服务器上面做操作
8、集群各节点之间进行认证:
pcs cluster auth cos11 cos135 cos136(此处需要输入的用户名必须为pcs自动创建的hacluster,其他用户不能添加成功)
9,创建并启动名为my_cluster的集群,其中cos11 cos135 cos136为集群成员:
pcs cluster setup --start --name my_cluster cos11 cos135 cos136
10、设置集群自启动:
pcs cluster enable --all
11、查看并设置集群属性:
查看当前集群状态:
pcs cluster status
检查pacemaker服务:
ps aux | grep pacemaker
检验Corosync的安装及当前corosync状态:
corosync-cfgtool -s
corosync-cmapctl | grep members
pcs status corosync
禁用STONITH: && 无法仲裁时候,选择忽略:
pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
三、编译安装haproxy服务
1.创建存放安装包的文件夹并下载haproxy压缩包
mkdir /etc/haproxy
curl -o /etc/haproxy/haproxy-2.0.28.tar.gz
https://www.haproxy.org/download/2.0/src/haproxy-2.0.28.tar.gz
2.进入haproxy目录并解压haproxy-2.0.28.tar.gz
tar -zxvf haproxy-2.0.28.tar.gz
3.编译安装
进入解压好的目录运行make编译安装,(make编译安装时,后面跟的几个参数,需要确定已安装,如OPENSSL、ZLIB、PCRE、SYSTEMD,没有安装使用yum命令先安装上之后再运行make)
make TARGET=linux3100 ARCH=x86_64 PREFIX=/usr/local/haproxy TARGET=generic USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1 USE_SYSTEMD=1
make isntall /usr/local/haproxy (haproxy安装目录,不使用make install 该服务无法正常安装到服务器。)
安装完成运行haproxy -v 确定服务安装完成
编译参数说明:
TARGET:linux内核版本
ARCH: linux系统版本
PREFIX:haprox安装目录
OPENSSL、ZLIB、PCRE、SYSTEMD安装haproxy需要的工具,不安装启动haproxy时会报错
4.haproxy安装完成之后,需配置haproxy的配置文件及启动文件
(1)、新增haproxy配置文件(配置文件放到一个常用的路径)
mkdir /etc/haproxyvim /etc/haproxy/haproxy.cfg
global
# log loghost local0
# log syslog-2.zpepc.com.cn local3 infolog localhost local3 infomaxconn 25000uid 99gid 99chroot /var/runpidfile /var/run/haproxy.piddaemonquietdefaultslog globaltimeout client 600stimeout server 600stimeout connect 30soption log-health-checks#frontend cos32
# bind 192.168.85.132:8080
# mode tcp
# log global
# maxconn 50000
# default_backend cosfrontend cos135bind 192.168.124.138:80mode tcplog globalmaxconn 50000#2020-10-10capture request header WL-Proxy-Client-IP len 15capture request header Referer len 150capture request header User-agent len 150capture request header Host len 40acl url_stats path_beg /admin/statsuse_backend stats if url_statsdefault_backend cosbackend defaultmode httpbalance roundrobinfullconn 100timeout connect 20000timeout server 20000retries 2server apache1 127.0.0.1:8090backend cosmode httpbalance roundrobin
# balance sourcecookie cos insert indirect nocacheserver w1 192.168.124.10:80 cookie www10 check inter 16000server w2 192.168.124.40:80 cookie www40 check inter 16000# long timeout to support connection queueingtimeout connect 200000timeout server 200000option redispatchretries 3backend statslog globalmode httpstats uri /balance roundrobin
(2)、haproxy启动文件,使用systemctl启动,需设置service文件
在/usr/lib/systemd/system/目录下面创建一个haproxy.service的文件
cd /usr/lib/systemd/system/vim haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=network.target[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
ExecStartPre=/usr/local/sbin/haproxy -f $CONFIG -c -q
ExecStart=/usr/local/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE
ExecReload=/usr/local/sbin/haproxy -f $CONFIG -c -q
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
SuccessExitStatus=143
#Type=notify# The following lines leverage SystemD's sandboxing options to provide
# defense in depth protection at the expense of restricting some flexibility
# in your setup (e.g. placement of your configuration files) or possibly
# reduced performance. See systemd.service(5) and systemd.exec(5) for further
# information.# NoNewPrivileges=true
# ProtectHome=true
# If you want to use 'ProtectSystem=strict' you should whitelist the PIDFILE,
# any state files and any other files written using 'ReadWritePaths' or
# 'RuntimeDirectory'.
# ProtectSystem=true
# ProtectKernelTunables=true
# ProtectKernelModules=true
# ProtectControlGroups=true
# If your SystemD version supports them, you can add: @reboot, @swap, @sync
# SystemCallFilter=~@cpu-emulation @keyring @module @obsolete @raw-io[Install]
WantedBy=multi-user.target
3、创建pcs_test集群并设置开机自启动
(1)、创建pcs_test集群
pcs cluster setup --start --name pcs_test cos11 cos135 cos136 --force
(2)、设置集群开机自启动
pcs cluster enable --all
(3)、配置虚IP资源(虚IP地址为192.168.124.138)
pcs resource create vip138 ocf:heartbeat:IPaddr2 ip=192.168.124.138 cidr_netmask=24 op monitor interval=10s timeout=15s
(4)、配置haproxy进程资源
pcs resource create haproxy systemd:haproxy op monitor interval=10s
(5)、配置资源约束绑定
pcs constraint colocation add haproxy with vip138
(6)、配置优先级约束
pcs constraint order start vip138 then haproxy
(7)、创建资源组
pcs resource group add pcs_test vip138 haproxy
配置完成启动资源,确认是否启动正常
pcs resource cleanup vip138
查询资源状态,确认资源是否启动
pcs status
pcsd常用命令
验证集群安装
pacemakerd -F ## 查看pacemaker组件,ps axf | grep pacemaker
corosync-cfgtool -s ## 查看corosync序号
corosync-cmapctl | grep members ## corosync 2.3.x
orosync-objctl | grep members ## corosync 1.4.x
查看集群资源
pcs resource standards ## 查看支持资源类型
pcs resource providers ## 查看资源提供商
pcs resource agents ## 查看所有资源代理
pcs resource list ## 查看支持资源列表
pcs stonith list ## 查看支持Fence列表
pcs property list --all ## 显示群集默认变量参数
crm_simulate -sL ## 检验资源 score 值
使用集群脚本
pcs cluster cib ra_cfg ## 将群集资源配置信息保存在指定文件
pcs -f ra_cfg resource create ## 创建群集资源并保存在指定文件中(而非保存在运行配置)
pcs -f ra_cfg resource show ## 显示指定文件的配置信息,检查无误后
pcs cluster cib-push ra_cfg ## 将指定配置文件加载到运行配置中
管理集群
pcs status ## 查看群集状态
pcs status cluster
pcs status corosync
pcs cluster stop [node11] ## 停止群集
pcs cluster start --all ## 启动群集
pcs cluster standby cos11 ## 将节点置为后备standby状态,pcs cluster unstandby cos11
pcs cluster destroy [--all] ## 删除群集,[--all]同时恢复corosync.conf文件
pcs resource cleanup ClusterIP ## 清除指定资源的状态与错误计数
pcs stonith cleanup vmware-fencing ## 清除Fence资源的状态与错误计数
pcs resource move vip138 cos135 ## 漂移vip资源到cos135
pcs+corosync+pacemaker+haproxy负载均衡环境部署相关推荐
- centos7 rabbitmq 单机部署 集群部署 HAProxy 负载均衡搭建
准备工作 搭建 RabbitMQ Server 单机版 搭建 RabbitMQ Server 高可用集群 搭建 HAProxy 负载均衡 一.准备工作 节点 系统 版本 ip node1 centos ...
- Nginx/LVS/HAProxy 负载均衡软件的优缺点详解
Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术,具体的应用需求还得具体分析. 如果是中小型的Web应用,比 ...
- Nginx、LVS及HAProxy负载均衡软件的优缺点详解
摘要:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术,具体的应用需求还得具体分析,本文总结了三者之间的优缺 ...
- Nginx/LVS/HAProxy负载均衡软件的优缺点详解
PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使用经验,总结一下. 一般对负载均衡的使用是随着网站规模的提升根据不 ...
- (总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解 (转载)
一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术.具体的应用需求还得具体分析,如果是中小型的Web应用,比如日PV小于1000万,用Nginx就完全可以了:如果机器不少,可以用D ...
- 负载均衡环境中和如何设置Expires和Etag
在负载均衡环境中(LVS, LoadBalance)为了减少浏览器数据的重复请求操作,一般需要设置 Http Header 的 Etage 和 Expires 告诉浏览器请求数据是否已过期.以下内容主 ...
- haproxy负载均衡_做负载均衡Nginx、HAProxy和LVS总有一个适合你
Nginx Nginx优点: 1.工作在网络7层之上,可针对http应用做一些分流的策略,如针对域名.目录结构,它的正规规则比HAProxy更为强大和灵活,所以,目前为止广泛流行. 2.Nginx对网 ...
- LVS负载均衡群集部署之——NAT模式的介绍及搭建步骤
文章目录 一.企业群集应用概述 1.1 群集的三种类型 1 负载均衡群集 2 高可用群集 3 高性能运算群集 1.2 负载均衡结构 1.3 负载均衡群集工作模式 (1) NAT模式--地址转换 (2) ...
- 运维面试精选:1、史上最详细的Nginx、LVS、HAProxy负载均衡精选面试题
文章目录 1.nginx 如何做优化 2.nginx upsteam有哪几种轮训方式? 3.Nginx怎样对同一IP访问进行限流? 4.Nginx 如何获取客户端的真实IP? 5.Nginx 如何设置 ...
最新文章
- 计算机改名后无法上网,CDEF磁盘分区无法修改名字修复方法
- custom的短语_custom的短语_custom的用法总结大全
- 【翻译】【linux设备驱动】linux地址类型
- aws s3 php,Amazon S3 预签名 POSTs 与 AWS SDK for PHP 版本 3 - 适用于 PHP 的 AWS 开发工具包...
- (C#基本语法)2.类型
- 基于JAVA+SpringMVC+Mybatis+MYSQL的小说管理系统
- 一帧图像最多有几种不同颜色_几种不锈钢屏风隔断创造灵感来源。颜色不同款,风格各有千秋...
- SPOJ LCMSUM - LCM Sum
- FFT(快速傅里叶变换):UVAoj 12298 - Super Poker II
- python vim 自动换行_Vim学习笔记整理
- CSV 文件打开乱码?如何批量解决 CSV 文件乱码问题
- win10彻底禁用chrome自动升级方法
- P4556-线段树合并,差分
- Rviz显示不出数据了之一文搞懂Qos
- web常用模块的测试用例
- Procmon 的使用
- 网络共享计算机怎么连接,电脑共享网络怎么连接
- 风险评估等级计算机化系统分类,计算机化系统风险评估报告
- 日照华软游戏开发价格_棋牌游戏开发价格预算需要多少钱?
- springboot汽车配件销售系统-预约洗车系统java