LVS虚拟服务器

LVS

环境准备:5台虚拟机

dns:192.168.1.66 作用:

web1:192.168.1.67 作用:

web2:192.168.1.68 作用:

nat:192.168.1.69 192.168.1.169(VIP) 作用:

客户机:192.168.1.70 作用:

web1:

root@web1 \~\]# yum -y install nginx //yum下载 \[root@web1 \~\]# nginx //启动nginx \[root@web1 \~\]# find / -name "nginx" //找nginx的配置文件 \[root@web1 \~\]# echo "i am web1" \> /usr/share/nginx/html/index.html \[root@web1 \~\]# systemctl stop firewalld \[root@web1 \~\]# systemctl disable firewalld \[root@web1 \~\]# setenforce 0 浏览器访问 web2: \[root@web2 \~\]# yum -y install nginx \[root@web2 \~\]# nginx \[root@web2 \~\]# echo "i am web2" \> /usr/share/nginx/html/index.html \[root@web2 \~\]# systemctl stop firewalld \[root@web2 \~\]# systemctl disable firewalld \[root@web2 \~\]# setenforce 0 浏览器访问 dns: \[root@localhost \~\]# yum -y install bind \[root@localhost \~\]# vim /etc/named.conf listen-on port 53 { 127.0.0.1;any; }; allow-query { localhost;any; }; \[root@localhost \~\]# vim /etc/named.rfc1912.zones zone "yu.feng" IN { type master; file "yu.feng.zone"; allow-update { none; }; }; \[root@localhost \~\]# cp -p /var/named/named.localhost /var/named/yu.feng.zone \[root@localhost \~\]# vim /var/named/yu.feng.zone nat A 192.168.1.69 ds A 192.168.1.169 web1 A 192.168.1.67 web2 A 192.168.1.68 \[root@localhost \~\]# systemctl start named \[root@dns \~\]# systemctl stop firewalld \[root@dns \~\]# systemctl disable firewalld \[root@dns \~\]# setenforce 0 客户机: \[root@client \~\]# vim /etc/resolv.conf nameserver 162.168.1.70 \[root@client \~\]# ping web2.tdr.com PING web2.tdr.com (192.168.1.68) 56(84) bytes of data. 64 bytes from 192.168.1.68 (192.168.1.68): icmp_seq=1 ttl=64 time=0.759 ms 64 bytes from 192.168.1.68 (192.168.1.68): icmp_seq=2 ttl=64 time=0.503 ms nat主机:做个时间同步,考虑到压力过大,所以不再创建新的虚拟机 \[root@nat \~\]# yum install -y ntpdate.x86_64 \[root@nat \~\]# ntpdate cn.ntp.org.cn 12 Aug 14:12:05 ntpdate\[4567\]: adjust time server 106.75.185.63 offset 0.047541 sec \[root@nat \~\]# crontab -e \* 2 \* \* \* /usr/sbin/ntpdate cn.ntp.org.cn \[root@nat \~\]# crontab -l \* 2 \* \* \* /usr/sbin/ntpdate cn.ntp.org.cn \[root@nat \~\]# yum -y install ntp \[root@nat \~\]# systemctl start ntpd //在其他主机都做下面的操作,同步时间 \[root@localhost \~\]# yum -y install ntpdate.x86_64 \[root@localhost \~\]# crontab -e 30 2 \* \* \* /usr/sbin/ntpdate 192.168.1.69 NAT模式搭建实战 \[root@nat \~\]# yum -y install ipvsadm.x86_64 -A 添加虚拟服务器 -t 设置群集地址(VIP,Virtual IP) tcp/udp -s 指定负载调度算法(rr\|wrr\|Ic\|w\|c\|sh...) -a 添加真实服务器 -d 删除真实服务器 -r 指定真实服务器(Real Server)的地址 -m 使用NAT模式;-g、-i分别对应DR、TUN模式 -w 为节点服务器设置权重,默认为1 \[root@nat \~\]# ipvsadm -A -t 192.168.1.169:80 -s rr //rr为轮询 \[root@nat \~\]# ipvsadm -L -n //查看集群规则 IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -\> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.169:80 rr \[root@nat \~\]# ipvsadm -a -t 192.168.1.169:80 -r 192.168.1.67:80 -m //添加真实服务器web1 \[root@nat \~\]# ipvsadm -a -t 192.168.1.169:80 -r 192.168.1.68:80 -m //添加真实服务器web2 \[root@nat \~\]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -\> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.169:80 rr -\> 192.168.1.67:80 Masq 1 0 0 -\> 192.168.1.68:80 Masq 1 0 0

相关推荐
斯班奇的好朋友阿法法24 分钟前
中科方德(NFSChina)离线安装 RPM 包
运维
milo.qu1 小时前
RockyLinux9.7 docker部署Jisti Meet
linux·docker·容器
GanGanGanGan_1 小时前
CentOS 7.9 glibc 2.17 源码编译升级到 glibc 2.31
linux·运维·centos·glibc
charlie1145141911 小时前
嵌入式Linux驱动开发——class 和 device 模型 - 自动创建设备节点的幕后机制
linux·运维·驱动开发
杨云龙UP3 小时前
SQL Server2022部署:Windows Server 2016下安装、SSMS配置、备份还原与1433端口放通全流程_20260508
运维·服务器·数据库·sql·sqlserver·2022
梦想与想象-广州大智汇3 小时前
自建docker加速镜像,使用 Cloudflare Workers/Pages 部署加速教程
运维·docker·容器
枳实-叶3 小时前
【Linux驱动开发】第四天:dmesg日志全解+驱动加载失败极速排查
linux·运维·驱动开发
武超杰4 小时前
Nginx从入门到精通
运维·nginx
wdfk_prog4 小时前
正常关闭虚拟机时,不要点“关机”,而要点“关闭客户机”
linux·c语言·网络·ide·vscode
weixin_704266054 小时前
Nginx 反向代理 + 6 种负载均衡策略
运维·nginx