实验目的:实现linux系统集群并发处理某项服务(这里以web服务为例)。
实验材料:8g内存、酷睿i5-3230m、英伟达720m的win10主机。Centos6.4完整版镜像,安装好的vmware11,三台安装好的纯净的centos6.4虚拟机。
实验原理:
Lvs不需要安装,因为linux2.6内核内包涵了,名字叫ipvsadm
实验步骤:
第一步安装支持包:
yum -y install PyXML net-snmp-libs libnetrpm
但是centos没有提供libnet的包需要到epel上下载libnet的包下载后安装:rpm-ivh libnet-1.1.6-7.el6.x86_64.rpm
第二步还是安装支持包:
yum -y install ipvsadm perl-MailTools perl-TimeDate
第三步:按顺序安装heartbeat:
rpm -ivh heartbeat-pils-2.1.4-12.el6.x86_64.rpm rpm -ivhheartbeat-stonith-2.1.4-12.el6.x86_64.rpm rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm rpm -ivhheartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
永久更改主机名:vim/etc/sysconfig/network
Node1.lw.com
Node2.lw.com
Node3.lw.com
暂时更改主机名:hostname xxxxxxx
永久更改主机名:vim/etc/sysconfig/network
node1.lw.com
node2.lw.com
暂时更改主机名:hostname xxxxxxx
更改/etc/hosts
添加
192.168.6.104 node1.lw.com
192.168.6.105 node2.lw.com
下一步建立双机互信通信:这里以bode2为例
1.生成一对密钥
[root@node2 ~]# ssh-keygen -t rsa -P '' -f .ssh/id_rsa Generating public/private rsa key pair. Your identification has been saved in.ssh/id_rsa. Your public key has been saved in.ssh/id_rsa.pub. The key fingerprint is: a6:cc:09:67:e3:45:81:59:aa:3b:7d:61:93:38:4b:[email protected] The key's randomart image is: +--[ RSA 2048]----+ | +o | | o. . | | . . | | . o . | | E B S | | & X o | | o O . | | . . | | | +-----------------+
(若是没有ssh到过其他主机,root目录下就没.ssh目录,方法。。。)
2.把公钥传到其他主机上:
[root@node2 ~]# ssh-copy-id -i .ssh/[email protected] The authenticity of host 'node1.lw.com(192.168.6.104)' can't be established. RSA key fingerprint isc9:17:0b:0f:a3:0e:d8:8d:a8:06:ad:2b:ba:d7:7c:1a. Are you sure you want to continueconnecting (yes/no)? yes Warning: Permanently added 'node1.lw.com'(RSA) to the list of known hosts. [email protected]'s password: Now try logging into the machine, with"ssh '[email protected]'", and check in: .ssh/authorized_keys to make sure we haven't added extra keysthat you weren't expecting.
测试一下:
[root@node2 ~]# ssh 192.168.6.104'ifconfig' eth1 Link encap:Ethernet HWaddr00:0C:29:12:62:A0 inet addr:192.168.6.104 Bcast:192.168.6.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe12:62a0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1977 errors:0 dropped:0 overruns:0 frame:0 TX packets:1371 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:195441 (190.8 KiB) TXbytes:169856 (165.8 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:184 errors:0 dropped:0 overruns:0 frame:0 TX packets:184 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:25686 (25.0 KiB) TXbytes:25686 (25.0 KiB)
到另外一台主机上重复步骤:
把公钥发到node2.lw.com
查看:安装好的heartbeat的文件在哪里
[root@node2 ~]# rpm -ql heartbeat |less
复制三个重要文件
cp/usr/share/heartbeat2.1.4/{ha.cf,authkeys,haresource} /etc/ha.d/ [root@node3 ha.d]# vim haresources
在最后面添加一行,
node3.lw.com IPaddr::192.168.6.108/24/eth1httpd
其中node3.lw.com是设置的默认主节点。
[root@node3 ha.d]# vim ha.cf
其中的这几行去掉#
debugfile /var/log/ha-debug
logfacility local0
keepalive 2
bcast eth1
auto_failback on
ping 192.168.6.103
其他的用默认就好
接下来注意是定义有哪些主机是ha节点的:
#node ken3
#node kathy
node node2.lw.com
node node3.lw.com
[root@node3 ha.d]# vim authkeys
添加两行
auth 1
1 md5 051322a335b4106681e9b78079a288f6
其中md5后面是MD5加密的掺杂的杂质
生成随机杂质的方法
[root@node3 ha.d]# dd if=/dev/randomcount=1 bs=512 |md5sum
记录了0+1 的读入
记录了0+1 的写出
128字节(128 B)已复制,6.974e-05秒,1.8 MB/秒
e13b8264a0810373e5dd3bdc3e6a4e7a -
[root@node3 ha.d]#
第一个节点配置好后复制到第二个节点:
[root@node3 ha.d]# scp authkeys haresourcesha.cf node2.lw.com:/etc/ha.d/ authkeys 100% 693 0.7KB/s 00:00 haresources 100% 5948 5.8KB/s 00:00 ha.cf 100% 10KB 10.3KB/s 00:00 [root@node3 ha.d]# service heartbeatrestart Stopping High-Availability services: Done. Waiting to allow resource takeover tocomplete: ^[[A^[[B^[[BDone. Starting High-Availability services: 2015/11/12_19:09:07 INFO: Resource is stopped Done. [root@node3 ha.d]# ssh node2.lw.com'service heartbeat restart' Stopping High-Availability services: Done. Waiting to allow resource takeover tocomplete: Done. Starting High-Availability services: 2015/11/12_19:09:33 INFO: Resource is stopped Done. [root@node2 ~]# ifconfig eth1 Link encap:Ethernet HWaddr00:0C:29:7A:7C:A8 inet addr:192.168.6.105 Bcast:192.168.6.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe7a:7ca8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8667 errors:0 dropped:0 overruns:0 frame:0 TX packets:6828 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2398319 (2.2 MiB) TX bytes:933830 (911.9 KiB) eth1:0 Link encap:Ethernet HWaddr00:0C:29:7A:7C:A8 inet addr:192.168.6.108 Bcast:192.168.6.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:358 (358.0 b) TXbytes:358 (358.0 b)
看eth1有了别名了吧。有了说明已经成功,到浏览器上
访问192.168.6.108