HA_高可用集群

1


HA高可用集群,

high available heartbeat =>HA

准备两台机,开启。

主:192.168.1.106    [root@yiqiang ~]

从:192.168.1.107 [root@luciLlinux ~]

更改主机名字

主:[root@yiqiang ~]# hostname master       

[root@yiqiang ~]# hostname master
[root@yiqiang ~]# bash

[root@master ~]# getenforce

[root@master ~]#iptables -nvL

[root@master ~] # vim /etc/hosts 在最后加入这两行

192.168.1.106 master
192.168.1.107 slave

保存退出

[root@master ~]# yum list |grep heartbeat 搜索有无此包

扩展源安装:rpm -ivh源下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm 

[root@master ~]# yum install -y heartbeat

[root@master ~]# yum install -y libnet  需要用的包都装上



从:

[root@luciLlinux ~]# hostname slave
[root@luciLlinux ~]# bash
[root@slave ~]#getenforce

[root@slave ~]# iptables -nvL

都需要看到Disabled的值,如果没有 vim /etc/selinux/config 将enforcing改成disabled #service iptables save即可。

[root@slave ~]# vim /etc/hosts 在最后加入这两行

192.168.1.106 master
192.168.1.107 slav

保存退出

[root@slave ~]# yum list |grep heartbeat 搜索有无此包

扩展源安装:源下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm 

[root@slave ~]# yum install -y heartbeat

[root@slave ~]# yum install -y libnet   需要用的包都装上



mysql可以做主、备,都可以使用HA,接下做主从了HA.

主:

[root@master ~]# cd /usr/share/doc/heartbeat-3.0.4/
[root@master heartbeat-3.0.4]# ls

[root@master heartbeat-3.0.4]# cp authkeys  ha.cf haresources /etc/ha.d/

[root@master heartbeat-3.0.4]# cd /etc/ha.d/

[root@master ha.d]# vim authkeys 编辑如下:打开注释第一和第四俩机内部通讯存活刺激交流通讯,加密级别为3最高

auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!

保存退出。

[root@master ha.d]# chmod 600 authkeys

[root@master ha.d]# vim haresources 编辑如下:

找到 #node1  10.0.0.170 Filesystem::/dev/sda1::/data1::ext2  整行替换掉

改成 master   192.168.1.110/24/eth0:0  nginx         这里模仿设置ip,Win上写入hosts

保存退出


系统下一块网卡配置多个ip地址方法:


[root@master ha.d]# cd /etc/sysconfig/network-scripts/
[root@master network-scripts]# ls

[root@master network-scripts]# cp ifcfg-eth0 ifcfg-eth0\:1
[root@master network-scripts]# vim ifcfg-eth0:1 编辑内容

DEVICE=eth0
HWADDR=00:0C:29:65:D0:27
TYPE=Ethernet
UUID=d4c70197-8a17-4233-a2ac-859e0e1b0536
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.106
NETMASK =255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DNS2=8.8.8.8

更改如下:
DEVICE=eth0:1          #这里是设备,需要修改成为eht0:1
BOOTPROTO=none
HWADDR="00:0C:29:65:D0:27"  #网卡的Mac地址,不需要修改
IPV6INIT=yes
IPV6_AUTOCONF=yes
ONBOOT=yes
TYPE=Ethernet
PEERDNS=yes
USERCTL=no
GATEWAY=192.168.1.1        #网关地址,对应即可,路由器地址
NETMASK=255.255.255.0       #子网掩码,对应即可
NETWORK=192.168.1.0          #网络地址,对应即可,route查看的到。
IPADDR=192.168.1.100       #IP地址,改成你想要的
BROADCAST=192.168.1.255     #IP地址的广播地址,对应即可,ifconfig查看的

保存退出,[root@master network-scripts]# /etc/init.d/network restart 重启网卡。

ifconfig 就可以看到地址了。

表示成功。

网卡被称为eth0,eth1,eth2.....,所有网卡的配置文,以此类推。

先放着△这步在这里不需要做▽





 cd /etc/ha.d/

[root@master ha.d]# vim ha.cf 编辑如下,先清空里面在加入:
debugfile /var/log/ha-debug   #排障log
logfile /var/log/ha-log
logfacility local0    #日志级别
keepalive 2     #多长时间探测一次
deadtime 30    #如果30秒ping不通了,就认为死掉了
warntime 10    #10秒ping不通会发出警告
initdead 60    #防止对方服务器 重启预留 一段时间
udpport 694    #心跳线通讯端口
ucast eth0 192.168.11.23 #配置对方指定的IP      当台机器的第一块网卡
auto_failback on
node master #主
node slave #从
ping 192.168.11.1 #中裁者ip,永活
respawn hacluster /usr/lib/heartbeat/ipfail  #检测网络连通性的,不同重启

保存退出,

[root@master ha.d]# ls

编辑好三个文件,把他拷贝到从上去:

[root@master ha.d]# scp authkeys  ha.cf haresources slave:/etc/ha.d/
The authenticity of host 'slave (192.168.1.107)' can't be established.
RSA key fingerprint is 14:a5:a2:cb:3e:6e:95:60:59:6c:b9:ec:bc:72:97:68.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave,192.168.1.107' (RSA) to the list of known hosts.
root@slave's password:      root密码
authkeys                                       100%  643     0.6KB/s   00:00
ha.cf                                         100%  555     0.5KB/s   00:00
haresources                                     100% 5888     5.8KB/s   00:00


从:

[root@slave ~]# cd /etc/ha.d
[root@slave ha.d]#  ls

[root@slave ha.d]# vim ha.cf 更改文件中的对方ip 保存退出

[root@slave ha.d]# yum install -y nginx

主:

[root@master ha.d]#yum install -y nginx


启动测试:先启动: 主 再启动: 从


主:

[root@master ha.d]# /etc/init.d/heartbeat start (需要稍等一哈,如果没启动,或者看错误信息,查看进程stop)

[root@master ha.d]# ifconfig  (需要看到eth0:0的网卡)

[root@master ha.d]#ps aux|grep nginx  (自动开启的进程)

[root@master ha.d]# echo "111111111111111111master" > /usr/share/nginx/html/index.html 编辑默认页面

可以在浏览器上看到,192.168.1.120  刷新页面就变成11111111master 


从:

[root@slave ha.d]# /etc/init.d/heartbeat start 

[root@slave ha.d]# echo "222222222222222222222slave" > /usr/share/nginx/html/index.html


主:

[root@master ha.d]# iptables -A INPUT -p icmp -j DROP 关闭禁ping功能
[root@master ha.d]# tail /var/log/ha-log

[root@master ha.d]# tail -f /var/log/ha-log 查看动态日志

从:

[root@slave ha.d]# less /var/log/ha-log

192.168.1.120 刷新页面就变成2222的页面了

主:

[root@master ha.d]# iptables -D INPUT -p icmp -j DROP  打开规则

稍等片刻

用ifconfig 查看主从,发现 从没有监听ech0:0网卡了,主反而监视浏览了

主: [root@master ha.d]# /etc/init.d/heartbeat stop

用ifconfig 查看主、从、恢复很快ech0:0网卡消失和在现两台机器,这就是HA高可用。









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值