基于heartbeat v2 crm实现HA高可用性的 LAMP+wordpress
一 Heartbeat 基本理论 提供冗余系统:HA Cluster:为提升系统调用性,组合多台主机构建成为的集群; split brain, partitioned cluster vote system:投票系统
HA中的各节点无法探测彼此的心跳信息时,必须无法协调工作;此种状态即为partitioned cluster; 少数服从多数的原则:quorum
with quorum > total/2
without quorum <= total/2 仲裁设备:
quorum disk = qdisk
ping node failover: 失效转移,故障转移
failback:失效转回,故障转回 资源类型:
HA-aware:资源自身可直接调用HA集群底层的HA功能;
非HA-aware:必须借助于CRM完成在HA集群上实现HA功能; 资源的约束关系:
location:位置约束,定义资源对节点的倾向性;用数值来表示,-oo, +oo;
colocation:排列约束,定义资源彼此间“在一起”倾向性;-oo, +oo
分组:亦能实现将多个资源绑定在一起;
order:顺序约束,定义资源在同一个节点上启动时的先后顺序; 资源类型:
primitive:主资源,只能运行于集群内的某单个节点;(也称作native);
group:组资源,容器,包含一个或多个资源,这些资源可通过“组”这个资源统一进行调度;
clone:克隆资源,可以在同一个集群内的多个节点运行多份克隆;
master/slave:主从资源,在同一个集群内部于两个节点运行两份资源,其中一个主,一个为从; 资源隔离:
级别
节点:STONITH (Shooting The Other Node In The Head)
power switch
资源:fencing
FC SAN switch 解决方案:
Messaging Layer:
heartbeat
v1, v2, v3
corosync
cman (RedHat, RHCS)
keepalived (完全不同上述三种) CRM:
heartbeat v1 haresources (配置接口:配置文件,文件名为haresources)
heartbeat v2 crm (在各节点运行一个crmd进程,配置接口:命令行客户端程序crmsh,GUI客户端:hb_gui);
heartbeat v3, pacemaker (pacemaker可以以插件或独立方式运行;配置接口,CLI接口:crmsh, pcs; GUI: hawk(webgui), LCMC, pacemaker-mgmt);
rgmanager (配置接口,CLI:clustat, cman_tool; GUI: Conga(luci+ricci)) 组合方式:
heartbeat v1
heartbeat v2
heartbeat v3 + pacemaker
corosync + pacemaker
cman + rgmanager (RHCS)
cman + pacemaker LRM: Local Resource Manager, 由CRM通过子程序提供;
RA: Resouce Agent
heartbeat legacy:heartbeat传统类型的RA,通常位于/etc/ha.d/haresources.d/目录下;
LSB:Linux Standard Base, /etc/rc.d/init.d目录下的脚本,至少接受4个参数:{start|stop|restart|status};
OCF:Open Cluster Framework
子类别:provider
STONITH:专用于实现调用STONITH设备功能的资源;通常为clone类型; Heartbeat:心跳信息传递机制
serail cable:作用范围有限,不建议使用;
ethernet cable:
UDP Unicast
UDP Multicast
UDP Broadcast 组播地址:用于标识一个IP组播域;IANA(Internet Assigned number authority)把D类地址空间分配给IP组播使用;其范围是:224.0.0.0-239.255.255.255;
永久组播地址:224.0.0.0-224.0.0.255;
临时组播地址:224.0.1.0-238.255.255.255;
本地组播地址:239.0.0.0-239.255.255.255, 仅在特定本地范围内有效; HA案例:ha web services
资源有三个:
ip, httpd, filesystem fip: floating ip,172.16.100.17
daemon: httpd 约束关系:使用“组”资源,或通过排列约束让资源运行于同一节点;
顺序约束:有次序地启动资源; 程序选型:
heartbeat v2 + haresources
heartbeat v2 + crm (hb_gui) 配置HA集群的前提:
(1) 节点间时间必须同步:使用ntp协议实现;
(2) 节点间需要通过主机名互相通信,必须解析主机至IP地址;
(a) 建议名称解析功能使用hosts文件来实现;
(b) 通信中使用的名字与节点名字必须保持一致:“uname -n”命令,或“hostname”展示出的名字保持一致;
(3) 考虑仲裁设备是否会用到;
(4) 建立各节点之间的root用户能够基于密钥认证;
# ssh-keygen -t rsa -P ''
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@HOSTNAME 注意:定义成为集群服务中的资源,一定不能开机自动启动;因为它们将由crm管理; HA Cluster的工作模型:
A/P:两节点集群,active, passive;工作于主备模型;
HA Service通常只有一个:HA resources可能会有多个;
A/A:两节点集群,active/active,工作于双方模型;
N-M: N个节点,M个服务;通常N>M;
N-N:N个节点,N个服务; 资源运行的倾向性:
rgmanager:
failover domain, node priority
pacemaker:
资源黏性:运行于当前节点的倾向性;
资源约束:
位置约束:资源对运行于某节点的倾向性
inf: 正无穷
-inf: 负无穷
n:
-n:
排列约束:资源运行于一处的倾向性
inf
-inf
n
-n
顺序约束:启动的先后顺序
A --> B --> C
C --> B --> A DC: Designated Coordinator corosync:
AIS: Application Interface Standard, SA Forum: OpenAIS OpenAIS: 提供了一种集群模式,包含集群框架、集群成员管理、通信方式、集群监测,但没有集群资源管理功能; 组件包括:AMF, CLM, CPKT, EVT等;分支不同,包含的组件略有区别; 分支:picacho, whitetank, wilson,
corosync (集群管理引擎)
只是openais的一个子组件; 分裂成为两个项目:
corosync, wilson(ais的接口标准) CentOS 5:
cman + rgmanager
CentOS 6:
cman + rgmanager
corosync + pacemaker 命令行管理工具:
crmsh: suse, CentOS 6.4-
pcs: RedHat, CentOS 6.5+ crm的常用子命令:
status
node
configure
ra
resource configure常用的子命令:
primitive
group
clone
ms
location
colocation
order
show
property primitive <rsc_id> class:provider:ra params param1=value1 param2=value2 op op1 param1=value op op2 parma1=value1 二 测试heartbeat+httpd基本环境设置
10.10.10.50/24 node1.test.comnode1
10.10.10.51/24 node2.test.comnode210.10.10.5/24 vip
关闭iptables
service iptables stop
chkconfig iptables off关闭selinx
vim /etc/selinux/config
SELINUX=disabled修改主机名
vim /etc/sysconfig/network
HOSTNAME=node2.test.com
vim /etc/hosts
10.10.10.50 node1.test.comnode1
10.10.10.51 node2.test.comnode2
reboot# uname -n
node1.test.com
# uname -n
node2.test.com安装httpd
yum install httpd
# vim /var/www/html/index.html
node1.test.com 10.10.10.50
# vim /var/www/html/index.html
node2.test.com 10.10.10.51
service httpd start测试打开 http://10.10.10.50 http://10.10.10.51service httpd stop准备ssh 信任(不用输账号密码进入系统)
cd ~
ssh-keygen -t rsa
ssh-copy-id localhost
ssh node2 cat ~/.ssh/id_rsa.pub >>.ssh/authorized_keys
scp .ssh/authorized_keysnode2:~/.ssh/
安装heartbeat
设置epel源libnet在epel
wget http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install net-snmp-libs libnet PyXML libtool-ltdl
rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm配置heartbeat
cd /etc/ha.d/
cp -r /usr/share/doc/heartbeat-2.1.4//etc/ha.d/
cp ./heartbeat-2.1.4/{ha.cf,authkeys,haresources} ./
chmod 600 authkeysvim authkeys
auth 21 crc
2 sha1 password3 md5 Hello!vim ha.cf
debugfile /var/log/ha-debuglogfacility local0
keepalive 2
deadtime 30
warntime 10
udpport 694
mcast eth0 225.10.0.1 694 1 0
auto_failback on
node node1.test.com
node node2.test.com
ping 10.10.10.2
compression bz2
compression_threshold 2vim haresources
node1.test.com 10.10.10.5/24/eth0/10.10.10.254 httpdscp -p ha.cf haresources authkeys node2:/etc/ha.d/
service heartbeat start;ssh node2 service heartbeat start查看实时生成的日志tail -f /var/log/ha-debug检测运行状态,所有资源在node1上 ,node2 上只有heartbeat服务# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.50Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:1469 errors:0 dropped:0 overruns:0 frame:0
TX packets:1324 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:178040 (173.8 KiB)TX bytes:235325 (229.8 KiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.5Bcast:10.10.10.254Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12332 (12.0 KiB)TX bytes:12332 (12.0 KiB) # netstat -nlptu|grep 80
tcp 0 0 :::80 ::: LISTEN 3056/httpd
# ps aux |grep http
root 30560.00.3 1752763736 ? Ss 20:00 0:00 /usr/sbin/httpd
apache 30600.00.2 1752762460 ? S 20:00 0:00 /usr/sbin/httpd
apache 30610.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
apache 30620.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
apache 30630.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
apache 30640.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
apache 30650.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
apache 30660.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
apache 30670.00.2 1752762444 ? S 20:00 0:00 /usr/sbin/httpd
root 31110.00.0 103304 896 pts/0 S+ 20:01 0:00 grep http
# ps aux |grep heartbeat
root 26620.01.465496 14348 ? SLs19:59 0:00 heartbeat: master control process
nobody 26660.00.7587647616 ? SL 19:59 0:00 heartbeat: FIFO reader
nobody 26670.00.7588927744 ? SL 19:59 0:00 heartbeat: write: mcast eth0
nobody 26680.00.7588927744 ? SL 19:59 0:00 heartbeat: read: mcast eth0
nobody 26690.00.7588927744 ? SL 19:59 0:00 heartbeat: write: ping 10.10.10.2
nobody 26700.00.7588927744 ? SL 19:59 0:00 heartbeat: read: ping 10.10.10.2
root 31140.00.0 103304 896 pts/0 S+ 20:01 0:00 grep heartbeat
# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:05:71:E9
inet addr:10.10.10.51Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:22144 errors:0 dropped:0 overruns:0 frame:0
TX packets:16634 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24037006 (22.9 MiB)TX bytes:7355584 (7.0 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26550 (25.9 KiB)TX bytes:26550 (25.9 KiB) # netstat -nlptu|grep 80
# ps aux |grep http
root 28230.00.0 103308 856 pts/0 S+ 20:02 0:00 grep http
# ps aux |grep heartbeat
root 27330.01.465496 14348 ? SLs19:59 0:00 heartbeat: master control process
nobody 27380.00.7587647616 ? SL 19:59 0:00 heartbeat: FIFO reader
nobody 27390.00.7588927744 ? SL 19:59 0:00 heartbeat: write: mcast eth0
nobody 27400.00.7588927744 ? SL 19:59 0:00 heartbeat: read: mcast eth0
nobody 27410.00.7588927744 ? SL 19:59 0:00 heartbeat: write: ping 10.10.10.2
nobody 27420.00.7588927744 ? SL 19:59 0:00 heartbeat: read: ping 10.10.10.2
root 28250.00.0 103308 856 pts/0 S+ 20:02 0:00 grep heartbeat打开网页 http://10.10.10.5停止第一个节点# service heartbeat stop
Stopping High-Availability services:
Done.node1节点服务器全部停止 ,所有服务转移到node2
# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:05:71:E9
inet addr:10.10.10.51Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:22411 errors:0 dropped:0 overruns:0 frame:0
TX packets:16943 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24082852 (22.9 MiB)TX bytes:7416808 (7.0 MiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:05:71:E9
inet addr:10.10.10.5Bcast:10.10.10.254Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26550 (25.9 KiB)TX bytes:26550 (25.9 KiB) # netstat -nlptu|grep 80
tcp 0 0 :::80 ::: LISTEN 3139/httpd
# ps aux |grep http
root 31390.00.3 1752763736 ? Ss 20:05 0:00 /usr/sbin/httpd
apache 31410.00.2 1752762460 ? S 20:05 0:00 /usr/sbin/httpd
apache 31430.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
apache 31450.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
apache 31460.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
apache 31490.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
apache 31510.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
apache 31530.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
apache 31570.00.2 1752762444 ? S 20:05 0:00 /usr/sbin/httpd
root 31680.00.0 103308 856 pts/0 S+ 20:06 0:00 grep http
# ps aux |grep heartbeat
root 27330.01.465496 14348 ? SLs19:59 0:00 heartbeat: master control process
nobody 27380.00.7587647616 ? SL 19:59 0:00 heartbeat: FIFO reader
nobody 27390.00.7588927744 ? SL 19:59 0:00 heartbeat: write: mcast eth0
nobody 27400.00.7588927744 ? SL 19:59 0:00 heartbeat: read: mcast eth0
nobody 27410.00.7588927744 ? SL 19:59 0:00 heartbeat: write: ping 10.10.10.2
nobody 27420.00.7588927744 ? SL 19:59 0:00 heartbeat: read: ping 10.10.10.2
root 31700.00.0 103308 852 pts/0 S+ 20:06 0:00 grep heartbeat打开网页 http://10.10.10.5重新开启node1# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.50Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:2457 errors:0 dropped:0 overruns:0 frame:0
TX packets:2066 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:299678 (292.6 KiB)TX bytes:365721 (357.1 KiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.5Bcast:10.10.10.254Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12332 (12.0 KiB)TX bytes:12332 (12.0 KiB) # ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.50Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:2465 errors:0 dropped:0 overruns:0 frame:0
TX packets:2071 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:300586 (293.5 KiB)TX bytes:367585 (358.9 KiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.5Bcast:10.10.10.254Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12332 (12.0 KiB)TX bytes:12332 (12.0 KiB) # netstat -nlptu|grep 80
tcp 0 0 :::80 :::* LISTEN 3693/httpd
# ps aux |grep http
root 36930.00.3 1752763728 ? Ss 20:07 0:00 /usr/sbin/httpd
apache 36950.00.2 1752762460 ? S 20:07 0:00 /usr/sbin/httpd
apache 36960.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
apache 36980.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
apache 37000.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
apache 37010.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
apache 37020.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
apache 37030.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
apache 37040.00.2 1752762444 ? S 20:07 0:00 /usr/sbin/httpd
root 37130.00.0 103304 896 pts/0 S+ 20:07 0:00 grep http
# ps aux |grep heartbeat
root 34050.01.465496 14348 ? SLs20:07 0:00 heartbeat: master control process
nobody 34100.00.7587647616 ? SL 20:07 0:00 heartbeat: FIFO reader
nobody 34110.00.7588927744 ? SL 20:07 0:00 heartbeat: write: mcast eth0
nobody 34120.00.7588927744 ? SL 20:07 0:00 heartbeat: read: mcast eth0
nobody 34130.00.7588927744 ? SL 20:07 0:00 heartbeat: write: ping 10.10.10.2
nobody 34140.00.7588927744 ? SL 20:07 0:00 heartbeat: read: ping 10.10.10.2
root 37150.00.0 103308 896 pts/0 S+ 20:07 0:00 grep heartbeat所有资源又全部转移到node1
三 测试heartbeat+httpd+nfs开启新的服务器,版本为cenos 7.1 ip地址为10.10.10.60
关闭iptables
systemctl stop firewalld
systemctl disable firewalld关闭selinx
vim /etc/selinux/config
SELINUX=disabled安装nfs
m install nfs创建nfs共享文件目录和文件mkdir -p /home/data/html
vim /home/data/html/index.html
html on nfs server 10.10.10.60配置nfsvim /etc/exports
/home/data 10.10.10.0/24(rw,no_root_squash)
exportfs -arv启动nfssystemctl start nfs-server
systemctl status nfs-server在node1 node2 上手动挂载测试
# mount -t nfs 10.10.10.60:/home/data/html /var/www/html
# cat /var/www/html/index.html
html on nfs server 10.10.10.60
# umount /var/www/html# mount -t nfs 10.10.10.60:/home/data/html /var/www/html
# cat /var/www/html/index.html
html on nfs server 10.10.10.60
# umount /var/www/html修改heartbeat 设置
# vim haresources
node1.test.com 10.10.10.5/24 Filesystem::10.10.10.60:/home/data/html::/var/www/html::nfshttpd复制到node2并启动服务scp haresources node2:/etc/ha.d/
service heartbeat start;ssh node2 service heartbeat startnode1节点 检查
# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.50Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:4330 errors:0 dropped:0 overruns:0 frame:0
TX packets:3581 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:561109 (547.9 KiB)TX bytes:658645 (643.2 KiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.5Bcast:10.10.10.255Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12332 (12.0 KiB)TX bytes:12332 (12.0 KiB) # netstat -nlptu|grep 80
tcp 0 0 :::80 ::: LISTEN 4808/httpd
# ps aux |grep http
root 48080.00.3 1752763736 ? Ss 20:24 0:00 /usr/sbin/httpd
apache 48100.00.2 1752762460 ? S 20:24 0:00 /usr/sbin/httpd
apache 48110.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
apache 48140.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
apache 48150.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
apache 48160.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
apache 48170.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
apache 48180.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
apache 48190.00.2 1752762444 ? S 20:24 0:00 /usr/sbin/httpd
root 48260.00.0 103304 896 pts/0 S+ 20:25 0:00 grep http
# ps aux |grep heartbeat
root 42720.01.465496 14348 ? SLs20:24 0:00 heartbeat: master control process
nobody 42780.00.7587647616 ? SL 20:24 0:00 heartbeat: FIFO reader
nobody 42790.00.7588927744 ? SL 20:24 0:00 heartbeat: write: mcast eth0
nobody 42800.00.7588927744 ? SL 20:24 0:00 heartbeat: read: mcast eth0
nobody 42810.00.7588927744 ? SL 20:24 0:00 heartbeat: write: ping 10.10.10.2
nobody 42820.00.7588927744 ? SL 20:24 0:00 heartbeat: read: ping 10.10.10.2
root 48280.00.0 103304 896 pts/0 S+ 20:25 0:00 grep heartbeat
node2节点
# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:05:71:E9
inet addr:10.10.10.51Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:23901 errors:0 dropped:0 overruns:0 frame:0
TX packets:18324 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24337685 (23.2 MiB)TX bytes:7683518 (7.3 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26550 (25.9 KiB)TX bytes:26550 (25.9 KiB) # netstat -nlptu|grep 80
# ps aux |grep http
root 37350.00.0 103308 852 pts/0 S+ 20:26 0:00 grep http
# ps aux |grep heartbeat
root 36840.01.465496 14348 ? SLs20:24 0:00 heartbeat: master control process
nobody 36890.00.7587647616 ? SL 20:24 0:00 heartbeat: FIFO reader
nobody 36900.00.7588927744 ? SL 20:24 0:00 heartbeat: write: mcast eth0
nobody 36910.00.7588927744 ? SL 20:24 0:00 heartbeat: read: mcast eth0
nobody 36920.00.7588927744 ? SL 20:24 0:00 heartbeat: write: ping 10.10.10.2
nobody 36930.00.7588927744 ? SL 20:24 0:00 heartbeat: read: ping 10.10.10.2
root 37390.00.0 103308 852 pts/0 S+ 20:27 0:00 grep heartbeat打开网页 http://10.10.10.5 停止第一个节点
# service heartbeat stop
Stopping High-Availability services:
Done.node1节点服务器全部停止 ,所有服务转移到node2
# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:05:71:E9
inet addr:10.10.10.51Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:24306 errors:0 dropped:0 overruns:0 frame:0
TX packets:18704 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24389056 (23.2 MiB)TX bytes:7747299 (7.3 MiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:05:71:E9
inet addr:10.10.10.5Bcast:10.10.10.255Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:26550 (25.9 KiB)TX bytes:26550 (25.9 KiB) # netstat -nlptu|grep 80
tcp 0 0 :::80 :::* LISTEN 4197/httpd
# ps aux |grep http
root 41970.00.3 1752763728 ? Ss 20:27 0:00 /usr/sbin/httpd
apache 41990.00.2 1752762460 ? S 20:27 0:00 /usr/sbin/httpd
apache 42020.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
apache 42030.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
apache 42050.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
apache 42070.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
apache 42100.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
apache 42140.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
apache 42170.00.2 1752762444 ? S 20:27 0:00 /usr/sbin/httpd
root 42240.00.0 103308 856 pts/0 S+ 20:28 0:00 grep http
# ps aux |grep heartbeat
root 36840.01.465496 14348 ? SLs20:24 0:00 heartbeat: master control process
nobody 36890.00.7587647616 ? SL 20:24 0:00 heartbeat: FIFO reader
nobody 36900.00.7588927744 ? SL 20:24 0:00 heartbeat: write: mcast eth0
nobody 36910.00.7588927744 ? SL 20:24 0:00 heartbeat: read: mcast eth0
nobody 36920.00.7588927744 ? SL 20:24 0:00 heartbeat: write: ping 10.10.10.2
nobody 36930.00.7588927744 ? SL 20:24 0:00 heartbeat: read: ping 10.10.10.2
root 42260.00.0 103308 856 pts/0 S+ 20:28 0:00 grep heartbeat刷新网页 http://10.10.10.5重新开启node1# ifconfig
eth0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.50Bcast:10.10.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:5051 errors:0 dropped:0 overruns:0 frame:0
TX packets:4184 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:656248 (640.8 KiB)TX bytes:765685 (747.7 KiB) eth0:0 Link encap:EthernetHWaddr 00:0C:29:9F:AE:0D
inet addr:10.10.10.5Bcast:10.10.10.255Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:65536Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12332 (12.0 KiB)TX bytes:12332 (12.0 KiB) # netstat -nlptu|grep 80
tcp 0 0 :::80 :::* LISTEN 5614/httpd
# ps aux |grep http
root 56140.00.3 1752763724 ? Ss 20:29 0:00 /usr/sbin/httpd
apache 56160.00.2 1752762456 ? S 20:29 0:00 /usr/sbin/httpd
apache 56170.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
apache 56190.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
apache 56210.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
apache 56220.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
apache 56230.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
apache 56240.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
apache 56250.00.2 1752762440 ? S 20:29 0:00 /usr/sbin/httpd
root 56320.00.0 103304 896 pts/0 S+ 20:29 0:00 grep http
# ps aux |grep heartbeat
root 51850.01.465496 14348 ? SLs20:29 0:00 heartbeat: master control process
nobody 51880.00.7587647616 ? SL 20:29 0:00 heartbeat: FIFO reader
nobody 51890.00.7588927744 ? SL 20:29 0:00 heartbeat: write: mcast eth0
nobody 51900.00.7588927744 ? SL 20:29 0:00 heartbeat: read: mcast eth0
nobody 51910.00.7588927744 ? SL 20:29 0:00 heartbeat: write: ping 10.10.10.2
nobody 51920.00.7588927744 ? SL 20:29 0:00 heartbeat: read: ping 10.10.10.2
root 56340.00.0 103304 896 pts/0 S+ 20:29 0:00 grep heartbeat所有资源又全部转移到node1四 测试heartbeat CRM LAMP Wordpress安装mysql 和php
m install mysql-server phpphp-mysql测试php
# vim /var/www/html/info.php
<?php
phpinfo();
?>
# service httpd start打开http://10.10.10.50/info.php 测试PHP 信息# service httpd stop测试mysql
# service mysqld start
# mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> exit
Bye
# service mysqld stop设置mysql data on nfs
在nfs 服务器mkdir /home/data/mysql在节点1
mkdir /data
vim /etc/my.cnf
datadir=/data/
mount -t nfs 10.10.10.60:/home/data/mysql /data
/usr/bin/mysql_install_db --user=mysql --datadir=/data/
# service mysqld start
# mysql
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| wordpress |
+--------------------+
4 rows in set (0.01 sec)
mysql> exit
Bye
# service mysqld stop
# umount /data在节点2
# mkdir /data
# vim /etc/my.cnf
datadir=/data/
# mount -t nfs 10.10.10.60:/home/data/mysql /data
# /usr/bin/mysql_install_db --user=mysql --datadir=/data/
#service mysqld start
# mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| wordpress |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
# service mysqld stop
# umount /data安装 heartbeat-guiyum install pygtk2-libglade xorg-x11-xauth
rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpmecho "password" | passwd --stdin haclusteryum install xorg-x11-xauth #如果未安装图型系统,要安装此组件,要不xshell报错
vim /etc/ha.d/ha.cf
crm on
service heartbeat start;ssh node2 service heartbeat start在xshell 执行hb_gui&连接127.0.0.1 安装gui默认生成hacluster 用户, 默认无密码请使用echo "password" | passwd --stdin hacluster 创建密码连接成功后如图显示开始添加资源 ,些次添加资源组 名为wordpress添加第一个资源名为 ha_ip类型为IPaddr参数为ip10.10.10.5添加第二个资源名为ha_nfs_mysql ,和我们之前测试时使用的参数一至,为mysql的共享存储类型为Filesystem参数为device 10.10.10.60:/home/data/mysql directory /data fstype nfs添加第三个资源名为ha_nfs_httpd ,和我们之前测试时使用的参数一至,为httpd的共享存储类型为Filesystem参数为device 10.10.10.60:/home/data/html directory /var/www/html fstype nfs添加第四个资源名为ha_mysql类型为我们安装的mysqld ,不需要参数添加第五个资源名为ha_httpd类型为我们安装的httpd ,不需要参数 添加主机colocations ,为资源起动所有的位置第一个为,ha_ipha_nfs_mysql 必须在同一个node上第一个为,ha_ipha_nfs_httpd 必须在同一个node上第一个为,ha_mysqlha_nfs_mysql 必须在同一个node上第一个为,ha_httpdha_nfs_httpd 必须在同一个node上以上设置保证所有资源启动在同一个node上,根据需要修改。 添加资源order,意为资源的启动顺序第一个为, ha_ip 比ha_nfs_mysql先启动如果不能启动ha_ip ,则不启动ha_nfs_mysql停止时,先停止ha_nfs_mysql ,后停止ha_ip如果不能停止ha_nfs_mysql,则不停止ha_ip第二个为, ha_ip 比ha_nfs_httpd先启动如果不能启动ha_ip ,则不启动ha_nfs_httpd停止时,先停止ha_nfs_httpd ,后停止ha_ip如果不能停止ha_nfs_httpd,则不停止ha_ip第三个为, ha_nfs_mysql 比ha_mysql先启动如果不能启动ha_nfs_mysql ,则不启动ha_mysql停止时,先停止ha_mysql ,后停止ha_nfs_mysql如果不能停止ha_mysql,则不停止ha_nfs_mysql 第四个为, ha_nfs_httpd 比ha_httpd先启动如果不能启动ha_nfs_httpd ,则不启动ha_httpd停止时,先停止ha_httpd,后停止ha_nfs_httpd如果不能停止ha_httpd,则不停止ha_nfs_httpd右键ha_wordpress ,start 启动ha_wordpress资源以上配置启动顺序为 ha_ip --> ha_nfs_mysql --> ha_mysql ha_ip --> ha_nfs_httpd--> ha_httpd右键节点node2 standby资源全部转移动node1 安装wordpresswgethttps://cn.wordpress.org/wordpress-4.3.1-zh_CN.zip
unzip wordpress-4.3.1-zh_CN.zip
cp -rfwordpress/ /var/www/html/
http://10.10.10.5/wordpress/wp-admin/setup-config.php如果没有设置权限 ,cd /var/www/html/
vim wp-config.php复制上图中生成的代码,然后点击进行安装。发表一个博客设置node2 为 standby结果刷新后发表的内容也可以显示
页:
[1]