群集的含义
Cluster,集群、群集
由多台主机构成,但对外只表现为一个整体
群集的类型
负载均衡(LoadBalancer)群集
高可用(HighAvailable)群集
高性能运算(HighPerformance Computer)群集
负载均衡的工作模式
地址转换:简称NAT模式,类似于防火墙的私有网络结构,负载调度器作为所有服务器节点的网关,既作为客户的访问入口,也是各个节点回应客户机的访问出口。服务器节点使用私网IP地址,与负载调度器位于同一个物理网络,安全性要优越于其他两种方式。
IP隧道:简称TUN模式,是将一个IP报文封装在另一个IP报文的技术,这可以使得目标为一个IP地址的数据报文能被封装和转发到另一个IP地址。采用开放式的网络结构,负载调度器仅作为客户机的访问入口,各个点通过各自的lnternet连接直接回应客户机,而不再经过负载调度器。服务器节点分散在互联网中的不同位置,具有独立的公网IP地址,通过专用IP隧道与负载调度器相互通信。
直接路由:简称DR模式,通过改写请求报文中的MAC地址部分来实现的。Director和RealServer必需在物理上有一个网卡通过不间断的局域网相连。采用半开放式的网络结构,与TUN模式的结构类似,但各个节点不是分散在各地,而是与调度器位于同一个网络。负载调度器与各节点服务器通过本地网络连接,不需要建立专用的IP隧道
LVS的负载调度算法
轮询(Round Robin)
加权轮询(WeightedRound Robin)
最少连接(LeastConnections)
加权最少连接(WeightedLeast Connections)
LVS主要组成部分为
负载调度器:它是整个集群对外面的前端机,负责将客户的请求发送到一组服务器上执行,而客户认为服务是来自一个IP地址(我们可称之为虚拟IP地址)上的。
服务器池:是一组真正执行客户请求的服务器,执行的服务一般有WEB、MAIL、FTP和DNS等。
共享存储:它为服务器池提供一个共享的存储区,这样很容易使得服务器池拥有相同的内容,提供相同的服务。
LVS-NAT模式
环境
调度器:IP 公网 ens33 192.168.2.168、私网 ens37 192.168.1.254
NFS共享储存服务:IP 公网 ens33 192.168.2.32、IP私网 ens37 192.168.1.250
节点服务器1:IP 公网 ens33 192.168.2.53 、IP私网 ens37 192.168.1.1
节点服务器2:IP 公网 ens33 192.168.2.62 、IP私网 ens37 192.168.1.2
配置
调度器
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# ipvsadm -v
ipvsadm v1.27 2008/5/15 (compiled with popt and IPVS v1.2.1)
NFS共享储存服务
root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# iptables -F
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# mkdir -p /opt/wwwroot/
[root@localhost ~]# vim /etc/exports
/opt/wwwroot 192.168.1.0/24(rw,sync,no_root_squash)
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# netstat -anpt | grep 111
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/wwwroot 192.168.1.0/24
[root@localhost ~]# cd /opt/wwwroot/
[root@localhost wwwroot]# echo "wo shi NFS server" > index.html
[root@localhost wwwroot]# cat index.html
wo shi NFS server
节点服务器1
[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# showmount -e 192.168.1.250
Export list for 192.168.1.250:
/opt/wwwroot 192.168.1.0/24
[root@localhost ~]# mkdir -p /var/www/html/
[root@localhost ~]# mount 192.168.1.250:/opt/wwwroot /var/www/html/
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 4.6G 14G 26% /
devtmpfs 222M 0 222M 0% /dev
tmpfs 237M 144K 237M 1% /dev/shm
tmpfs 237M 9.0M 228M 4% /run
tmpfs 237M 0 237M 0% /sys/fs/cgroup
/dev/sda1 297M 152M 146M 51% /boot
tmpfs 48M 8.0K 48M 1% /run/user/0
192.168.1.250:/opt/wwwroot 18G 4.6G 14G 26% /var/www/html
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
index.html
[root@localhost html]# cat index.html
wo shi NFS server
节点服务器2
[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# showmount -e 192.168.1.250
Export list for 192.168.1.250:
/opt/wwwroot 192.168.1.0/24
[root@localhost ~]# mkdir -p /var/www/html/
[root@localhost ~]# mount 192.168.1.250:/opt/wwwroot /var/www/html/
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 4.6G 14G 26% /
devtmpfs 222M 0 222M 0% /dev
tmpfs 237M 144K 237M 1% /dev/shm
tmpfs 237M 9.0M 228M 4% /run
tmpfs 237M 0 237M 0% /sys/fs/cgroup
/dev/sda1 297M 152M 146M 51% /boot
tmpfs 48M 8.0K 48M 1% /run/user/0
192.168.1.250:/opt/wwwroot 18G 4.6G 14G 26% /var/www/html
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
index.html
[root@localhost html]# cat index.html
wo shi NFS server