lvs+ldirectord+corosync+pacemaker+httpd实现高可用负载均衡
lvs+ldirectord+corosync+pacemaker+httpd实现高可用负载均衡实验要求
1、lvs+ ldirectord负载均衡
2、corosync+pacemaker高可用lvs
实验环境:
实验拓扑:
https://s5.运维网.com/wyfs02/M02/8D/A5/wKiom1ikX8XyuE3cAABB4SOBdLU545.jpg
ip网络地址规划
1、node1:lvs :172.16.76.10(corosync+pacmaker)
2、node2:lvs :172.16.76.20(corosync+pacmaker)
3、node3:172.16.76.30Httpd
4、node4:172.16.76.40Httpd
实验前提:
1、关闭iptables及selinux
2、服务器时间同步ntpdate
3、基于主机名互相通信、ssh的互信通信(可选)
注释:实验所有rpm包所有已上传至运维网资料链接地址如下:
http://down.运维网.com/data/2287593
基础配置
node1:
#grep-i -C 10 "ipvs" /boot/config-3.10.0-327.el7.x86_64 #查看是否加载ipvs
#yuminstall ipvsadmldirectord –y
#yum install corosync pacemakerhttpd–y
#yum install./pssh-2.3.1-4.2.x86_64.rpm crmsh-2.1.4-1.1.x86_64.rpm \ python-pssh-2.3.1-4.2.x86_64.rpm
root@node1~]# cd /var/www/html/
# vim index.html
web.server:Test
# systemctlrestart httpd.service
node2:
#grep-i -C 10 "ipvs" /boot/config-3.10.0-327.el7.x86_64 #查看是否加载ipvs
#yuminstall ipvsadmldirectord –y
#yum install corosync pacemakerhttpd–y
#yum install./pssh-2.3.1-4.2.x86_64.rpm crmsh-2.1.4-1.1.x86_64.rpm \ python-pssh-2.3.1-4.2.x86_64.rpm
# cd /var/www/html/
# vim index.html
web.server:Test
# systemctlrestart httpd.service
node3
#yum install httpd -y
# cd /var/www/html/
# vim index.html
web.server:172.16.76.30:Test
# systemctlrestart httpd.service
node4
#yum install httpd–y
# cd /var/www/html/
# vim index.html
web.server:172.16.76.30:Test
# systemctl restart httpd.service
ldirectord配置
node1
#ssh-keygen-t rsa
#ssh-copy-id -i.ssh/id_rsa.pub172.16.76.20
# cd /etc/ha.d/
# cat ldirectord.cf
checktimeout=3 #检测超时
checkinterval=1 #检测间隔
#fallback=127.0.0.1:80
#fallback6=[::1]:80
autoreload=yes 自动载入
logfile="/var/log/ldirectord.log"日志输出
#logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=no
# Sample for an http virtual service
virtual=172.16.76.100:80 #虚拟ip
real=172.16.76.30:80 gate#DR模式 realserver
real=172.16.76.40:80 gate
fallback=127.0.0.1:80 gate #备份server (sorroy server)
service=http #协议
scheduler=rr #轮询
#persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate协商
checkport=80 检测端口
request="index.html"检测请求url
receive="Test" 请求页面包含信息
# systemctl restart ldirectord.service
https://s4.运维网.com/wyfs02/M01/8D/A5/wKiom1ikYRXCKgYkAABP1Et_Ed4436.jpg
node2:
#ssh-keygen-t rsa#密钥
#ssh-copy-id -i.ssh/id_rsa.pub172.16.76.10
#scp 172.16.76.10/etc/ha.d/ldirectord.cf /etc/ha.d/
# systemctl restart ldirectord.servicehttps://s3.运维网.com/wyfs02/M01/8D/A2/wKioL1ikYRfSELG_AABWeGAT3F8634.jpg
Corosync配置
node1
# systemctl stop ldirectord.service
# systemctl enable directord.service
# systemctl enable httpd.service
# cd /etc/corosync/
# vim corosync.conf
totem {
version: 2#版本
crypto_cipher: aes128#加密
crypto_hash: md5
interface {
ringnumber:0环0
bindnetaddr:172.16.0.0 绑定网络
mcastaddr:239.255.101.11#组播传递ip
mcastport:5405#组播传递端口
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile:/var/log/cluster/corosync.log
to_syslog: no
debug: off
timestamp: on
logger_subsys {
subsys: QUORUM
debug: off
}
}
quorum {
provider:corosync_votequorum
two_nodes: on
}
nodelist { 节点列表
node {
ring0_addr:172.16.76.10
nodeid:1
}
node {
ring0_addr:172.16.76.20
nodeid:2
}
}
# corosync-keygen #生成多播信息密码
#scp authkey corosync.conf 172.16.76.20:/etc/corocync/
#systemctl restart corosync.service
#systemctl restart pacemaker.service
#注生成密钥时需要用到 /dev/random一共需要1024位的长度
# 生成后的密钥文件会在配置文件目录下自行生成一个authkey文件;
#/dev/random是 Linux系统下的随机数生成器,它会从当前系统的内存中一个叫熵池的地址空间中根据系统中断来生成随机数,加密程序或密钥生成程序会用到大量的随机数,就会出现随机数不够用的情况,random 的特性就是一旦熵池中的随机数被取空,会阻塞当前系统进程等待产生中断会继续生成随机数;
#由于此处会用到1024位长度的密钥,可能会存在熵池中的随机数不够用的情况,就会一直阻塞在生成密钥的阶段,两种解决办法:
1、手动在键盘上输入大量字符,产生系统中断(产生中断较慢,不建议使用)
2、通过互联网或FTP服务器下载较大的文件(产生中断较快,建议使用)
node2
#systemctl stop ldirectord.service
# systemctl enable directord.service
# systemctl enable httpd.service
#systemctl restart corosync.service
# systemctl restart pacemaker.service
Crm
# crm
crm(live)# configure
crm(live)configure# primitive vipocf:heartbeat:IPaddr params ip="172.16.76.100" #资源vip
crm(live)configure# primitivelvs_direcror systemd:ldirectord#添加资源ldirectord
crm(live)configure# primitive sorry_httpd systemd:httpd #添加资源httpd
crm(live)configure# group lvs_dir viplvs_direcror sorry_httpd #组约束
crm(live)configure# show查看配置
node 1: node1 \
attributes standby=on
node 2: node2 \
attributes standby=off
primitive lvs_direcror systemd:ldirectord
primitive sorry_httpd systemd:httpd
primitive vip IPaddr \
params ip=172.16.76.100
group lvs_dir vip lvs_direcror sorry_httpd
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.13-10.el7-44eb2dd\
cluster-infrastructure=corosync\
stonith-enabled=falsehttps://s5.运维网.com/wyfs02/M02/8D/A5/wKiom1ikYXagcsmMAAB9XJy9etU691.jpg
crm(live)configure# verify #语法检查
crm(live)configure#commit #提交保存
crm(live)configure#cd
crm(live)# status #状态查看
https://s1.运维网.com/wyfs02/M00/8D/A2/wKioL1ikYZKgvrNtAACP6KDh-qg081.jpg
node2:
# crm node standby (手动离线节点2) #online (上线) #即手动离线node2后服务自动漂移至node1节点之上;
https://s2.运维网.com/wyfs02/M02/8D/A2/wKioL1ikYbaCKG9PAACdjYQOqFw610.jpg
测试:
https://s3.运维网.com/wyfs02/M00/8D/A5/wKiom1ikYjLA2caCAABl6Z8lHzE853.jpg
https://s3.运维网.com/wyfs02/M01/8D/A2/wKioL1ikYjfxI-F4AAFC7R_e1I0915.jpg
至此实验完成。本实验只为简单介绍其配置方式,文中指令诸多解释将在随后博客之中发布;
若实验中真有问题欢迎指正;
页:
[1]