Heartbeat是什么?
构建规划:
实验部署
#安装nginx-->两天服务器都需要操作#准备好nginx的源码包-->使用源码安装
[root@node1 ~]# ls nginx-1.16.1.tar.gz
nginx-1.16.1.tar.gz
[root@node1 ~]# #创建nginx的用户
[root@node1 ~]# useradd -s /sbin/nologin -M nginx#安装必要的依赖工具
[root@node1 nginx-1.16.1]# yum -y install gcc gcc-c++ zlib zlib-devel pcre pcre-devel openssl openssl-devel#解压包-->预编译、编译、安装nginx#这里指定nginx的用户是nginx
[root@node1 ~]# tar -xf nginx-1.16.1.tar.gz
[root@node1 ~]# cd nginx-1.16.1
[root@node1 nginx-1.16.1]#
[root@node1 nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install#创建各自的页面
[root@node1 nginx-1.16.1]# cd /usr/local/nginx/html/
[root@node1 html]# vim index.html
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaa#另外一个网页信息
[root@node2 ~]# vim /usr/local/nginx/html/index.html
BBBBBBBBBBBBBBBB
-->node1为ntp服务器-->node1配置如下
#直接安装ntp
[root@node1 ~]# yum -y install ntp#这里是以node1来作为时间服务器
[root@node1 ~]# cp /etc/ntp.conf{,.bak}
[root@node1 ~]# vim /etc/ntp.conf
...........#指定自己的网段15 restrict 192.168.75.0 mask 255.255.255.0 nomodify notrap
.......#注释系统默认的23 #server 0.centos.pool.ntp.org24 #server 1.centos.pool.ntp.org25 #server 2.centos.pool.ntp.org#手工添加这两行26 server 127.127.1.027 fudge 127.127.1.0 stratum 10#启动服务
[root@node1 ~]# /etc/init.d/ntpd start
[root@node1 ~]# date
Thu Feb 9 10:51:03 CST 2023--->node2配置如下#直接安装ntp
[root@node2 ~]# yum -y install ntp#先查看一下时间
[root@node2 ~]# date
Tue Feb 7 02:56:39 CST 2023#然后直接使用命令同步
[root@node2 ~]# ntpdate 192.168.75.11#然后检查时间
[root@node2 ~]# date
Thu Feb 9 10:55:15 CST 2023
#把域名和ip写入hosts文件
[root@node1 ~]# vim /etc/hosts
........
192.168.75.11 www.node1.net
192.168.75.12 www.node2.com
两台服务器都安装heartbeat
#准备好heartbeat-3.0的版本
[root@localhost ~]# ls heartbeat.tar.gz
heartbeat.tar.gz#解压-->直接安装
[root@localhost ~]# tar -xf heartbeat.tar.gz
[root@localhost ~]# cd heartbeat
[root@localhost heartbeat]# ls
...........#然后直接安装
[root@localhost heartbeat]# yum -y install *#准备好配置文件到/etc/ha.d/目录下
[root@localhost heartbeat]# cd /usr/share/doc/heartbeat-3.0.4/
[root@localhost heartbeat-3.0.4]# cp -a ha.cf authkeys haresources /etc/ha.d/#先生成密钥的随机数
[root@localhost heartbeat-3.0.4]# dd if=/dev/random bs=512 count=1 | openssl md5
0+1 records in
0+1 records out
78 bytes (78 B) copied, 2.9833e-05 s, 2.6 MB/s
(stdin)= 806d2d668b7a72f65506bcde2b09c3b2#修改一下authkeys文件#在node0上面修改-->#注意一下路劲
[root@localhost heartbeat-3.0.4]# pwd
/usr/share/doc/heartbeat-3.0.4#修改authkeys文件
[root@localhost heartbeat-3.0.4]# vim authkeys #在文件的末尾添加以下的内容-->那一串的密钥是上面生成的密钥
auth 3
3 md5 806d2d668b7a72f65506bcde2b09c3b2#最后修改一下文件的权限
[root@localhost heartbeat-3.0.4]# chmod 600 authkeys #验证一下主机名和ip的对应关系-->保证能够访问#这里就可以顺势起来nginx
[root@localhost heartbeat-3.0.4]# /usr/local/nginx/sbin/nginx
[root@localhost heartbeat-3.0.4]# curl www.node1.net
bbbbbbbbbb
[root@localhost heartbeat-3.0.4]# curl www.node0.net
aaaaaaaaaa#修改主配置文件-->修改/etc/ha.d/ha.cf
[root@localhost heartbeat-3.0.4]# vim /etc/ha.d/ha.cf
............#添加一下三行92 bcast eth0 # Linux93 node www.node0.net94 node www.node1.net#在node0上面对haresources文件进行修改#等于切换到VIP的ip
[root@localhost heartbeat-3.0.4]# vim /etc/ha.d/haresources
.............#在末行添加如下信息
www.node0.net IPaddr::192.168.75.100/24:/eth0:0#操作完成之后吧配置文件都给到node1上面
[root@localhost ha.d]# cd /etc/ha.d/
[root@localhost ha.d]# scp ha.cf haresources authkeys root@www.node1.net:/etc/ha.d/#然后启动服务器验证
[root@www ~]# service heartbeat start
上一篇:Python练习系统
下一篇:JavaScript 代码规范