一,安装keepalived和LVS
[root@centos1 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos1 ~]# yum -y install ipvsadm keepalived
2)设置服务开机自启
[root@centos1 ~]# chkconfig --level 35 keepalived on
3)备份主配置文件
[root@centos1 ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
4)编辑主配置文件
[root@centos1 ~]# vim /etc/keepalived/keepalived.conf
5)启动服务
[root@centos1 ~]# systemctl start keepalived
4、配置双机热备备份节点
1)安装LVS和keepalived
[root@centos2 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos2 ~]# yum -y install ipvsadm keepalived
2)设置服务开机自启
[root@centos2 ~]# chkconfig --level 35 keepalived on
3)备份主配置文件
[root@centos2 ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
4)编辑主配置文件
[root@centos2 ~]# vim /etc/keepalived/keepalived.conf
5)启动服务
[root@centos2 ~]# systemctl start keepalived
安装httpd服务
[root@centos3 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos3 ~]# yum -y install httpd
[root@centos4 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos4 ~]# yum -y install httpd
2)写入测试数据
[root@centos3 ~]# echo “www.benet.com” > /var/www/html/index.html
[root@centos4 ~]# echo “www.accp.com” > /var/www/html/index.html
3)启动服务并设置开机自启
[root@centos3 ~]# systemctl start httpd
[root@centos3 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@centos4 ~]# systemctl start httpd
[root@centos4 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
生成虚拟网卡监听地址为lvs服务器的vip地址
[root@centos3 ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
[root@centos3 ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.200
NETMASK=255.255.255.255
ONBOOT=yes
重启网卡
[root@centos3 ~]# systemctl restart network
修改内核参数
[root@centos3 ~]# vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@centos4 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
6 、配置nfs
1)安装nfs系统
[root@centos5 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos5 ~]# yum -y install rpcbind nfs-utils
2)创建共享网站根目录文件
[root@centos5 ~]# mkdir /web
[root@centos5 ~]# echo “www.nfs.com” > /web/index.html
3)修改nfs主配置文件共享/web目录,允许100.10和20读取共享目录数据rw读取和写入
[root@centos5 ~]# vim /etc/exports
/web 192.168.100.10(ro) 192.168.100.20(ro)
4)启动nfs服务
[root@centos5 ~]# systemctl start rpcbind
[root@centos5 ~]# systemctl start nfs
[root@centos5 ~]# systemctl enable nfs
[root@centos5 ~]# systemctl enable rpcbind
5)查看共享目录
[root@centos5 ~]# showmount -e 192.168.100.30
Export list for 192.168.100.30:
/web 192.168.100.20,192.168.100.10
6)设置开机自动挂载
[root@centos5 ~]# vim /etc/fstab
192.168.100.30:/web /var/www/html nfs defaults 0 0
[root@centos5 ~]# reboot
[root@centos5 ~]# vim /etc/fstab
192.168.100.30:/web /var/www/html nfs defaults 0 0
[root@centos5 ~]# reboot
验证: