heartbeat部署初始化

2023年 7月 16日 65.9k 0

部署:假设两台服务器linuxea-1-1/linuxea-1-2,其实际IP分别为10.0.0.7(linuxea-1-1机器),10.0.0.8(linuxea-1-2机器)配置目标:要求heartbeat服务启动后,linuxea-1-1机器上初始启动VIP:10.0.0.7,linuxea-1-2机器上初始启动VIP:10.0.0.8,一旦服务器linuxea-1-1或者linuxea-1-2任意一台机器宕机,在宕机的机器上初始启动的虚拟VIP将会自动切换到在运转正常的机器上,实现了IP资源的自动接管,从而达到高可用无业务影响的目的

heartbeat通过串口线或者直接通过心跳信息对服务器进行健康检查

准备环境,两台主机分别执行初始化:修改主机名

hostname linuxea-1-1
vim /etc/syscong/network

关闭selinux

[root@linuxea-1-2 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 
[root@linuxea-1-2 ~]# grep SELINUX=disabled /etc/selinux/config 
SELINUX=disabled
[root@linuxea-1-2 ~]# setenforce 0
[root@linuxea-1-2 ~]# 

关闭防火墙

[root@linuxea-1-1 ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@linuxea-1-1 ~]# chkconfig iptables off
[root@linuxea-1-1 ~]# chkconfig --list |grep ipt
iptables           0:off    1:off    2:off    3:off    4:off    5:off    6:off
[root@linuxea-1-1 ~]# 

添加网络dns

[root@linuxea-1-2 ~]# echo servername 180.168.255.118 >> /etc/resolv.conf 
[root@linuxea-1-2 ~]# echo servername 116.228.111.18 >> /etc/resolv.conf 

保留开启的服务,其他的关闭

#b.service startup at linux startup
LANG=en
for linuxea in `chkconfig --list |grep "3:on" |awk '{print $1}' |grep -vE "crond|network|sshd|rsyslog"`;do chkconfig $linuxea off;done
chkconfig --list|grep “3:on”
unset LANG
chkconfig --list |grep "3:on"


[root@linuxea-1-2 ~]# #b.service startup at linux startup
[root@linuxea-1-2 ~]# LANG=en
[root@linuxea-1-2 ~]# for linuxea in `chkconfig --list |grep "3:on" |awk '{print $1}' |grep -vE "crond|network|sshd|rsyslog"`;do chkconfig $linuxea off;done
[root@linuxea-1-2 ~]# chkconfig --list|grep “3:on”
[root@linuxea-1-2 ~]# unset LANG
[root@linuxea-1-2 ~]# chkconfig --list |grep "3:on"
crond              0:off    1:off    2:on    3:on    4:on    5:on    6:off
network            0:off    1:off    2:on    3:on    4:on    5:on    6:off
rsyslog            0:off    1:off    2:on    3:on    4:on    5:on    6:off
sshd               0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@linuxea-1-2 ~]# unset LANG
[root@linuxea-1-2 ~]# 

字符集修改

cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
echo 'LANG="zh_CN.UTF-8"'>/etc/sysconfig/i18n
source /etc/sysconfig/i18n
 echo $LANG

[root@linuxea-1-1 ~]# cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
[root@linuxea-1-1 ~]# echo 'LANG="zh_CN.UTF-8"'>/etc/sysconfig/i18n
[root@linuxea-1-1 ~]# source /etc/sysconfig/i18n
[root@linuxea-1-1 ~]# echo $LANG
zh_CN.UTF-8
[root@linuxea-1-1 ~]# 

时间同步:

#d.time sync
/usr/sbin/ntpdate time.nist.gov
echo '#time sync by linuxea at 2010-2-1' >>/var/spool/cron/root
echo '*5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
crontab -l

[root@linuxea-1-2 ~]# #d.time sync
[root@linuxea-1-2 ~]# /usr/sbin/ntpdate time.nist.gov
 6 Dec 00:28:45 ntpdate[3701]: adjust time server 64.113.32.5 offset 0.210020 sec
[root@linuxea-1-2 ~]# echo '#time sync by linuxea at 2010-2-1' >>/var/spool/cron/root
[root@linuxea-1-2 ~]# echo '*5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root[root@linuxea-1-2 ~]# crontab -l
#time sync by linuxea at 2010-2-1
*5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
[root@linuxea-1-2 ~]# 

文件描述符

echo  '*    -    nofile    65535' >> /etc/security/limits.conf

使用setup新曾一个网卡,填写ip和掩码即可使用ifup eth2启动网卡。10.0.0.7的eth2 是10.0.10.710.0.0.8的eth2 是10.0.10.8

[root@linuxea-1-2 ~]# setup
[root@linuxea-1-2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth2 
[root@linuxea-1-2 ~]# ifup eth2

设备 etj2 似乎不存在, 初始化操作将被延迟。[

root@linuxea-1-2 ~]# setup
[root@linuxea-1-2 ~]# ifup eth2
Determining if ip address 10.0.10.8 is already in use for device eth2...
[root@linuxea-1-2 ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:77:C1:93  
          inet addr:10.0.0.8  Bcast:10.0.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe77:c193/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:405 errors:0 dropped:0 overruns:0 frame:0
          TX packets:319 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:35252 (34.4 KiB)  TX bytes:70093 (68.4 KiB)

eth2      Link encap:Ethernet  HWaddr 00:0C:29:77:C1:9D  
          inet addr:10.0.10.8  Bcast:10.0.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe77:c19d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:120 (120.0 b)  TX bytes:406 (406.0 b)
[root@linuxea-1-2 ~]# ping 10.0.10.7
PING 10.0.10.7 (10.0.10.7) 56(84) bytes of data.
64 bytes from 10.0.10.7: icmp_seq=1 ttl=64 time=2.67 ms
64 bytes from 10.0.10.7: icmp_seq=2 ttl=64 time=0.405 ms
^C
--- 10.0.10.7 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1713ms
rtt min/avg/max/mdev = 0.405/1.539/2.674/1.135 ms
[root@linuxea-1-2 ~]# 

两台机器的ip分别为:

[root@linuxea-1-2 ~]# ping 10.0.10.7
eth1      Link encap:Ethernet  HWaddr 00:0C:29:C4:E4:30  
          inet addr:10.0.0.7  Bcast:10.0.255.255  Mask:255.255.0.0
eth2      Link encap:Ethernet  HWaddr 00:0C:29:C4:E4:3A  
          inet addr:10.0.10.7  Bcast:10.0.10.255  Mask:255.255.255.0
eth3      Link encap:Ethernet  HWaddr 00:0C:29:C4:E4:44  
          inet addr:10.0.20.7  Bcast:10.0.20.255  Mask:255.255.255.0
[root@linuxea-1-2 ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:77:C1:93  
          inet addr:10.0.0.8  Bcast:10.0.255.255  Mask:255.255.0.0
eth2      Link encap:Ethernet  HWaddr 00:0C:29:77:C1:9D  
          inet addr:10.0.10.8  Bcast:10.0.10.255  Mask:255.255.255.0
eth3      Link encap:Ethernet  HWaddr 00:0C:29:77:C1:A7  
          inet addr:10.0.20.8  Bcast:10.0.20.255  Mask:255.255.255.0

配置hosts:

/bin/cp /etc/hosts /etc/hosts.bak
sed -i '/^10.0.0/d' /etc/hosts
cat >>/etc/hosts<<eof
10.0.10.7 linuxea-1-1
10.0.10.8 linuxea-1-2
eof
tail -2 /etc/hosts

分别在linuxea-1-1和linuxea-1-2上面分别添加对方的vip的路由

[root@linuxea-1-1 ~]# route add -host 10.0.10.8 dev eth2
[root@linuxea-1-2 ~]# route add -host 10.0.10.7 dev eth2

请输入图片描述

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论