< span style="font-size:11pt;">Prepare two virtual machines with IP addresses 192.168.1.4 and 192.168.1.3
span> < /span> Synchronize node time , Set the time synchronization on the two virtual machines:
< span style="font-family:'Microsoft Yahei';font-size:10.5pt;line-height:1.5;"> crontab -e Open and edit to synchronize every 3 minutes; point to a reliable gateway;crontab -e /span>
*/3 * * * * /usr/sbin/ntpdate 192.168.1.1 &> /dev/null
Nodes need to communicate with each other through host names, and must resolve host to IP address, The name used in the communication must be consistent with the node name
vim /etc/hosts
/span> 192.168.1.4 hsxaou
192.168.1.3 hsxaou1
span> /span> Edit this file to modify the host name: /etc/sysconfig/network
< /p>
The establishment of root users between nodes can be based on the key Certification
< span style="font-size:11pt;"> ssh-keygen -t rsa -P”
Copy the generated public key to the corresponding node
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] .1.3
span> < span style="font-family:'Microsoft Yahei';font-size:10.5pt;line-height:1.5;"> Check whether the time of the two hosts are synchronized ;
< span style="font-size:11pt;"> date; ssh hsxaou1’date’
After preparation, start the installation program on each node, first resolve the dependent packages, libnet needs epel source;
yum install net-snmp-libs libnet PyXML span>
download the heartbeat2.rpm package to the local, and copy it to another node’s home directory;< /span>
span> /span> scp -r heartbeat2/ hsxaou1:~/
Install separately on two nodes;
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
The configuration file is in the /etc/ha.d/ directory
< span style="font-size:11pt;"> You can use IPaddr or IPaddr2 to configure the IP. The former uses the ifconfig command, and the latter uses the ip command;
span> /span> V1 version dedicated configuration interface, not not used in V1 version, the sample configuration file is in:
span> < /span> Put these 3 sample file authkeys,ha.cf,haresources copied to /etc/ha .d/ directory, and modify the permissions of authkeysneed to be modified to 400 or 600;
cp /usr/share/doc/heartbeat-2.1.4 /{ha.cf,haresources,authkeys} /etc/ha.d/
Modify the permission to 600
chmod 600 authkeys
Edit the configuration file authkeys, specify the algorithm to be enabled and enable it in this fileThe secret key of ;
When the algorithm is simple, you can generate one by yourself and put it inside;
openssl rand -base64 16
auth #: Use the first algorithm, # fill in that number
Edit the main configuration file ha.cf and start the basic functions;
span> log function, enable one of them;
The definition here is sent to local0, which needs to be defined in /etc/rsyslog.conf, and Restart the service
service rsyslog restart
span>
< span style="font-size:11pt;"> The default sending heartbeat time, the default is 2 seconds;
span> keepalive 2
Time of death;
deadtime 30
Warning time;
warntime 10
When heartbeat runs on multiple nodes, the startup time is relatively long, you can extend the time according to the situation;
initdead 120
The default port for heartbeat transmission based on UDP
udpport 694
Broadcast, use whichever you use
多播
mcast eth0 225.22.190.1 694 1 0
地址不能和别人相同,自己修改下,694端口,1为ttl值表 示只允许传递一次;0为loop值,不允许循环
ip link set eth0 multicast on|off 使用多播时需要启用;
资源转回
auto_failback on
指明高可用集群要使用的节点,节点名必须与uname -n的名字保持一致;
指明ping node,仲裁设备,探测辅助性设备
对节点之间传递的信息压缩
compression bz2
指明2kb以上的才压缩
compression_threshold 2
vim /haresources
定义集群资源
指定主节点名字,后面为资源地址,每个资源单独进行指定
设置fip(公共IP),会自动设置在某块网卡的别名上, 从左侧第一个启动,在哪个主机上前面就使用哪个主机的名字
hsxaou 192.168.1.10/24/eth0/192.168. 255.255 httpd
完成后把配置文件发送到另外一个节点,保留原来的权限
scp -p ha.cf haresources authkeys hsxaou1:/etc/ha.d/
分别在各节点上,启动heartbeat之前先要把httpd页面配置好,作为测试2个节点的页面设置不一样,作为区分并且设置为开机不自动启动;
vim /var/www/html/index.html
chkconfig httpd off
启动heartbeat服务,并查看80端口是否打开;
service heartbeat start
ss -tunl
使用浏览器访问fip192.168.1.10,完成了。 .
650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” title=”捕获.PNG” alt=”wKiom1XJZCPic_m_AACXqVupfuE446.jpg” d=”4237668″ s=”eac_e9b” t=”jpg”>
< span style="font-size:11pt;"> 基于共享文件的高可用:
在第3台主机上设置主页:
vim /web/htdocs/index.html
共享文件:vim /etc/exports
/web/htdocs *(rw,no_root_squash)
启动nfs服务:service nfs start
nfs开机自启:chkconfig nfs on
在192.168.1.4节点上挂载文件进行测试,使用浏览器访问测试
mount -t nfs 192.168.1.5:/web/htdocs /var/www/html/
设置成功后卸载掉;
umount /var/www/html/
编辑/etc/ha.d/haresoureces
/usr/lib64/heartbeat/hb_takeover 拿回资源
/usr/lib64/heartbeat/hb_standby 资源转出
/usr/lib64/heartbeat/ha_propagate 把本节点的上的ha.cf和athkeys文件自动发送到另外一个节点的/etc/ha.d/下,并显示可以设置为ha的有哪些