基于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 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
primitiveclass: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.comnode2
10.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.51
service 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 2
#1 crc
2 sha1 password
#3 md5 Hello!vim ha.cf
debugfile /var/log/ha-debug
#logfacility 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
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1YsoNjymWesAACCVn04Vds870.jpg
停止第一个节点
# 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
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1YsoP-QkXGrAACDm_MKk0U599.jpg
重新开启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 配置nfs
vim /etc/exports
/home/data 10.10.10.0/24(rw,no_root_squash)
exportfs -arv 启动nfs
systemctl 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 start 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: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
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1YsofCjzSzmAAB_7YgkQR8509.jpg
停止第一个节点
# 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
http://s3.运维网.com/wyfs02/M01/74/DA/wKioL1YsomTi1gINAAB_7YgkQR8748.jpg
重新开启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
# 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-gui
yum 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 创建密码
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1YsoxziPK_vAAG1Dese07Q332.jpg
连接成功后如图显示
http://s3.运维网.com/wyfs02/M00/74/DA/wKioL1Yso1Gze6EWAAKZHObjP-8602.jpg
开始添加资源 ,些次添加资源组 名为wordpress
http://s3.运维网.com/wyfs02/M02/74/DA/wKioL1Yso1WA6w8AAAJpcTfpwKw005.jpg
添加第一个资源名为 ha_ip
类型为IPaddr参数为ip10.10.10.5
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1YsoyfCSILOAAQaKD0P0tA867.jpg
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1YsoyqiGShhAAIk0hGXwNw067.jpg
添加第二个资源名为ha_nfs_mysql ,和我们之前测试时使用的参数一至,为mysql的共享存储
类型为Filesystem
参数为device 10.10.10.60:/home/data/mysql
directory /data
fstype nfs
http://s3.运维网.com/wyfs02/M01/74/DA/wKioL1Yso17yIBRiAARvpsiH7pQ984.jpg
添加第三个资源名为ha_nfs_httpd ,和我们之前测试时使用的参数一至,为httpd的共享存储
类型为Filesystem
参数为device 10.10.10.60:/home/data/html
directory /var/www/html
fstype nfs
http://s3.运维网.com/wyfs02/M00/74/DA/wKioL1Yso2LiIBaZAARvaIyiVr8613.jpg
添加第四个资源名为ha_mysql
类型为我们安装的mysqld ,不需要参数
http://s3.运维网.com/wyfs02/M02/74/DE/wKiom1YsozfCG7MVAAQEVpUbnLw372.jpg
添加第五个资源名为ha_httpd
类型为我们安装的httpd ,不需要参数
http://s3.运维网.com/wyfs02/M02/74/DA/wKioL1Yso2ri9PPCAAQ-PoG5mnI153.jpg
添加主机colocations ,为资源起动所有的位置
第一个为,ha_ipha_nfs_mysql 必须在同一个node上
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1Ysoz3AF8SXAAQtBOHztsI613.jpg
第一个为,ha_ipha_nfs_httpd 必须在同一个node上
http://s3.运维网.com/wyfs02/M02/74/DE/wKiom1Yso0LwQQDeAAQg6v5yRSQ728.jpg
第一个为,ha_mysqlha_nfs_mysql 必须在同一个node上
http://s3.运维网.com/wyfs02/M00/74/DA/wKioL1Yso3bgQ1FFAAQ2QqZ4r_w649.jpg
第一个为,ha_httpdha_nfs_httpd 必须在同一个node上
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1Yso0zxY1QzAARRt1jSgag706.jpg
以上设置保证所有资源启动在同一个node上,根据需要修改。
添加资源order,意为资源的启动顺序
第一个为, ha_ip 比ha_nfs_mysql先启动
如果不能启动ha_ip ,则不启动ha_nfs_mysql
停止时,先停止ha_nfs_mysql ,后停止ha_ip
如果不能停止ha_nfs_mysql,则不停止ha_ip
http://s3.运维网.com/wyfs02/M01/74/DA/wKioL1Yso4PjvHfNAAQndpj25o0458.jpg
第二个为, ha_ip 比ha_nfs_httpd先启动
如果不能启动ha_ip ,则不启动ha_nfs_httpd
停止时,先停止ha_nfs_httpd ,后停止ha_ip
如果不能停止ha_nfs_httpd,则不停止ha_ip
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1Yso1qC6cy7AAQFxMY6NAs185.jpg
第三个为, ha_nfs_mysql 比ha_mysql先启动
如果不能启动ha_nfs_mysql ,则不启动ha_mysql
停止时,先停止ha_mysql ,后停止ha_nfs_mysql
如果不能停止ha_mysql,则不停止ha_nfs_mysql
http://s3.运维网.com/wyfs02/M02/74/DE/wKiom1Yso1-SsAM5AAREJ6BdY-E178.jpg
第四个为, ha_nfs_httpd 比ha_httpd先启动
如果不能启动ha_nfs_httpd ,则不启动ha_httpd
停止时,先停止ha_httpd,后停止ha_nfs_httpd
如果不能停止ha_httpd,则不停止ha_nfs_httpd
http://s3.运维网.com/wyfs02/M02/74/DA/wKioL1Yso5byjxfXAAQqzJw8jaA468.jpg
右键ha_wordpress ,start 启动ha_wordpress资源
以上配置启动顺序为 ha_ip --> ha_nfs_mysql --> ha_mysql
ha_ip --> ha_nfs_httpd--> ha_httpd
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1Yso2qi74xjAANvdP-Zk1w833.jpg
http://s3.运维网.com/wyfs02/M02/74/DB/wKioL1Yso52j1VozAAOXNQybBvU544.jpg
右键节点node2 standby
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1Yso3HSq1HRAAOhYyT1uLo785.jpg
资源全部转移动node1
http://s3.运维网.com/wyfs02/M00/74/DB/wKioL1Yso6iQ7f0lAAOqPxmcIVM717.jpg
安装wordpress
wgethttps://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
http://s3.运维网.com/wyfs02/M02/74/DE/wKiom1Ysp-qQaPlHAALhjCQT9F4273.jpg
http://s3.运维网.com/wyfs02/M02/74/DB/wKioL1YsqB7DM1q9AAI1S0gY4uY534.jpg
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1Ysp-_zV5ooAAM9bVTaDz0507.jpg
如果没有设置权限 ,
cd /var/www/html/
vim wp-config.php
复制上图中生成的代码,然后点击进行安装。
http://s3.运维网.com/wyfs02/M00/74/DB/wKioL1YsqCDydrbvAAJkqo0TxcI291.jpg
http://s3.运维网.com/wyfs02/M01/74/DE/wKiom1Ysp_LjhICLAAFpSo-n7Ug547.jpg
http://s3.运维网.com/wyfs02/M01/74/DB/wKioL1YsqCfRL9_hAANKK9ZqbWs458.jpg
发表一个博客
http://s3.运维网.com/wyfs02/M02/74/DE/wKiom1Ysp_ngqq80AAHYSk2kANc849.jpg
设置node2 为 standby
http://s3.运维网.com/wyfs02/M02/74/DB/wKioL1YsqDCwoDjWAAOiaNfR-h4189.jpg
http://s3.运维网.com/wyfs02/M00/74/DE/wKiom1YsqAei5EZtAAOLGbaA4Vs223.jpg
结果刷新后发表的内容也可以显示
页:
[1]