Linux系统架构(LB—HA集群)-HA集群配置

HA集群配置

准备两台设备,分别为主从

主:

[[email protected] ~]# ifconfig

eth0       inet addr:192.168.137.21

从:

[[email protected] ~]# ifconfig

eth0      inet addr:192.168.137.23

先开始配置

主上:

[[email protected] ~]# hostname master

[[email protected] ~]# iptables -F

[[email protected] ~]# setenforce 0

[[email protected] ~]# vim /etc/hosts

192.168.137.21 master

192.168.137.23 slave

[email protected] ~]# yum list |grep heartbeat

无显示,先安装扩展源

[[email protected]~]#wget www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm

[[email protected] ~]# rpm -ivh epel-release-6-8_32.noarch.rpm

[[email protected] ~]# yum  install -y heartbeat  libnet

从上类似操作:

[[email protected] ~]# hostname slave

[[email protected] ~]# iptables -F

[[email protected] ~]# setenforce 0

[[email protected] ~]# vim /etc/hosts

192.168.137.21 master

192.168.137.23 slave

[[email protected]~]#wget www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm

[[email protected] ~]#  rpm -ivh epel-release-6-8_32.noarch.rpm

[[email protected] ~]# yum  install -y heartbeat  libnet

软件安装完成,现配置文件

主上:

[[email protected] ~]# cd /usr/share/doc/heartbeat-3.0.4/

[[email protected] heartbeat-3.0.4]# ls

[[email protected] heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/

[[email protected] heartbeat-3.0.4]# cd /etc/ha.d/

[[email protected] ha.d]# vim authkeys

auth 3

#1 crc

#2 sha1 HI!

3 md5 Hello!

[[email protected] ha.d]# chmod 600 authkeys

[[email protected] ha.d]# vim haresources              //加入

master 192.168.137.100/24/eth0:0 nginx

// master (主的主机名)192.168.137.100/24/eth0:0(虚拟的IP,指定网段,网卡eth0:0) nginx(哪些资源做主从)

此不可不做,此不为一个网卡配置多个IP地址方法:

[[email protected] ha.d]# cd /etc/sysconfig/network-scripts/

[[email protected] network-scripts]# ls

[[email protected] network-scripts]# cp ifcfg-eth0 ifcfg-eth0\:1

[[email protected] network-scripts]# vim ifcfg-eth0\:1

DEVICE=eth0:1

HWADDR=00:0C:29:6A:A5:9B

TYPE=Ethernet

UUID=4e9798c5-cbbc-45d1-9483-51d8c50643f8

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=192.168.137.109

NETMASK=255.255.255.0

#GATEWAY=192.168.137.1

[[email protected] network-scripts]# /etc/init.d/network restart

[[email protected] network-scripts]# ifconfig

eth0      inet addr:192.168.137.21

eth0:1    inet addr:192.168.137.109

[[email protected] network-scripts]# cd -

/etc/ha.d

[[email protected] ha.d]# vim ha.cf            //清空配置输入

debugfile /var/log/ha-debug

logfile /var/log/ha-log

logfacility     local0

keepalive 2

deadtime 30

warntime 10

initdead 60

udpport 694

ucast eth0 192.168.137.23

auto_failback on

node    master

node    slave

ping 192.168.21.1

respawn hacluster /usr/lib/heartbeat/ipfail

[[email protected] ha.d]# scp authkeys haresources ha.cf slave:/etc/ha.d/

//将这几份文件拷贝到从slave设备上

[[email protected] ha.d]# yum install -y  nginx

先配置从:

[[email protected] init.d]# cd /etc/ha.d/

[[email protected] ha.d]# cat authkeys           //该文件不用改

[[email protected] ha.d]# cat haresources        //该文件也不用改

[[email protected] ha.d]# vim ha.cf

ucast eth0 192.168.137.21                 //改成对端IP

[[email protected] ha.d]#  yum install -y  nginx

测试:

启动heartbeat先启动主,再启动从

主:

[[email protected] ha.d]# /etc/init.d/heartbeat start

[[email protected] ha.d]# ps aux |grep nginx                    //nginx还未启动

[[email protected] ha.d]# ip add

inet 192.168.137.100/24 brd 192.168.137.255 scope global secondary eth0:0

//虚拟IP已有

[[email protected] ha.d]# ps aux |grep nginx

root      5309  0.0  0.1  15648  1512 ?        Ss   14:35   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

nginx     5311  0.0  0.1  15804  1960 ?        S    14:35   0:00 nginx: worker process

//nginx已启动

从:

[[email protected] ha.d]# /etc/init.d/heartbeat start

[[email protected] ha.d]# ip add

//虚拟IP未启动

[root[email protected] ha.d]# ps aux |grep nginx

//nginx也未启动

主:

[[email protected] ha.d]# echo "master" >/usr/share/nginx/html/index.html

//将网站默认页面改成master,方便测试区分

windows客户端访问192.168.137.100页面为master

[[email protected] ha.d]# curl 192.168.137.100

master

从上:

[[email protected] ha.d]# echo "slave" > /usr/share/nginx/html/index.html

现模拟主设备宕机了,看是否能切换到从上

方法使主上禁ping,模拟宕机

主上:

[[email protected] ha.d]# iptables -A INPUT -p icmp -j DROP

//禁ping规则

[[email protected] ha.d]# tail /var/log/ha-log

[[email protected] ha.d]# tail -f /var/log/ha-log

[[email protected] ha.d]# ifconfig

eth0:0已释放

[[email protected] ha.d]# ps aux |grep nginx

//无nginx进程

从上查看:

[[email protected] ha.d]# less /var/log/ha-log

IPaddr(IPaddr_192.168.137.100)[3276]:   2015/07/25_19:15:47 INFO: Bringing device eth0 up

ResourceManager(default)[3115]: 2015/07/25_19:15:47 info: Running /etc/init.d/nginx  start

//eth0启动,nginx启动

[[email protected] ha.d]# ifconfig

eth0:0    inet addr:192.168.137.100

//虚拟IP已启动

[[email protected] ha.d]# ps aux |grep nginx

nginx     4010  0.0  0.2  15804  2324 ?     S    20:02   0:00 nginx: worker process

//nginx启动了

windows客户端访问:192.168.137.100出现slave页面

[[email protected] ha.d]# curl 192.168.137.100

slave

主上打开禁ping规则

[[email protected] ha.d]#  iptables -D INPUT -p icmp -j DROP

从上:

[[email protected] ha.d]# ifconfig

//虚拟IP释放

[[email protected] ha.d]# ps aux |grep nginx

nginx进程停止

windows客户端访问192.168.137.100出现master页面

[[email protected] ha.d]# curl 192.168.137.100

master

当主上停止heartbeat时,网站切换到从上

[[email protected] ha.d]# /etc/init.d/heartbeat stop

[[email protected] ha.d]# ifconfig

[[email protected] ha.d]# ps aux |grep nginx

window客户端访问192.168.137.100出现slave页面

[[email protected] ha.d]# curl 192.168.137.100

slave

时间: 2024-10-26 06:18:54

Linux系统架构(LB—HA集群)-HA集群配置的相关文章

Linux系统架构

Linux系统架构 A. HA集群配置 1. 安装heartbeat [[email protected] ~]# vim /etc/hosts   //配置hosts 10.30.4.146  master 10.30.4.140  slave [[email protected] ~]# rpm -ivh http://www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm   //安装epel [[ema

查看Linux系统架构类型的5条常用命令

导读 很多时候我们都需要查看当前 Linux 系统是 32 位还是 64 位系统架构类型,本文中我将向大家推荐 5 条常用命令.无论你使用的是桌面版或是只装了文本界面的 Linux 环境,以下命令几乎可以通吃所有 Linux 发行版,例如:RHEL.CentOS.Fedora.Scientific Linux.Debian.Ubuntu.Linux Mint.OpenSUSE 等等. 1. uname 命令 uname -a 命令可以直接显示 Linux 系统架构的命令,安几乎可以工作在所有 L

linux系统下php oracle扩展OCI8的安装与配置

linux系统下php oracle扩展OCI8的安装与配置 实现PHP程序访问oracle DB时间:2014.09.02写作者:刘群英(qunyingliu) 环境描述:apache版本,PHP版本,oracle DB版本,linux发行版本 RPM包安装oracle-instantclient客户端 源码编译安装oci8扩展 系统环境与php配置修改:ld.so.conf.d目录配置文件与php.ini中扩展字段信息修改 重启apache使修改生效 测试链接代码,确认配置成功 环境描述:

linux系统构架 - LB集群之LVS介绍

LB 集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有 nginx.lvs.keepalived ,商业的硬件负载设备 F5.Netscale. LB 集群的架构如下图,原理也很简答,就是当用户的请求过来时,会直接发到分发器(Director Server)上,然后它把用户的请求根据预先设置好的算法,智能均衡地分发到后端的真正服务器(real server)上.如果不同的机器,可能用户请求到的数据不一样,为了避免这样的情况发生,所以用到了共享存储

Linux系统架构-(LB-HA集群)之LVS配置

LB集群之LVS ha lb load balance 负载均衡软件 nginx.lvs.keepalived 设备F5.netscale lvs有三种模式 1.NAT 2.TUN 3.DR 调度算法:rr.wrr.dh.sh 动态算法:wlc.lc.lblc.lblcr LVS的NAT模式配置: 准备三台设备.1台为转发,其他2台为提供的服务. 为区分开: 1号机为dir, 2号机为rs1, 3号机为rs2 1号机: [[email protected] ~]# hostname dir [[

Linux系统架构(LB-HA集群)-nginx负载均衡集群配置

nginx负载均衡集群配置 [[email protected] ~]# cd/usr/local/nginx/conf/vhosts/ [[email protected] vhosts]# ls default.conf  test.conf [[email protected] vhosts]# vim lb.conf upstream wang { server 192.168.137.21:80; server 192.168.137.23:80; } server { listen

linux系统构架 - LB集群之LVS的DR设置

在lvs的nat模式的基础上 1.清空ipvsadm规则 ipvsadm -C 查看 ipvsadm -ln 2.清空iptables规则 iptables -t nat -F 3.修改rs的网卡配置,修改回来网关 vi /etc/sysconfig/network-scripts/ifcfg-eth0 重启eth0 ifdown eth0; ifup eth0 4.dir网卡 ifdown eth1 dirIP:192.168.1.118  rs1IP:192.168.1.116 rs2IP:

Linux系统架构师之代码发布解决方案

我今年19了!人生有多少22K? 所有实验环境初始化: 创建本地光盘Yum源,安装tree lrzsz vim,关闭iptables和selinux. 定义别名cls='clear',ll='ls -Alh'. 代码发布解决方案: 1.安装优化软件环境 2.程序代码 3.配置变更 SVN是跨平台的开源版本控制系统.SVN会备份并记录文件每一次的修改更新的变动. SVN是通用的软件系统,常用来管理程序代码.常见的版本控制软件有:VSS.CVS.SVN.Git. Git与SVN的区别: SVN是一个

Linux系统:centos7下搭建Rocketmq4.3中间件,配置监控台

本文源码:GitHub·点这里 || GitEE·点这里 一.环境搭建 环境版本 centos7 jdk1.8 已搭建好 rocketmq4.3 1.下载安装包 网址 https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.3.2/rocketmq-all-4.3.2-bin-release.zip # We suggest the following mirror site for your download:官方建议下载地址 http://