linux,centos7上搭建LVS负载均衡
在linux,centos7上搭建LVS负载均衡实前准备
[*]准备五台虚拟机
[*]四台centos7
[*]一台做调度 一台做nfs缓存
[*]两台做wed群集
[*]一台windows7
开始逐个配置
[*]配置nfs服务器(centos7在用的时候是在线下载源代码包但是为了做实验先把源代码用yum安装好后改为仅主机模式)
[*]IP:192.168.10.174
[*]用rpm -q nfs-utils查看有没有安装
[*]rpcbind (远程过程调用)
[*]编辑配置文件
# vim /etc/exports
# cat /etc/exports
/usr/share *(ro,sync) #*所有 ro只读 sync同步
/opt/benet 192.168.10.0/24(rw,sync) #rw可读可写sync同步
/opt/accp 192.168.10.0/24(rw,sync) #rw可读可写sync同步
# mkdir /opt/accp #创建目录
# mkdir /opt/bent
# chmod 777 /opt/bent
# chmod 777 /opt/accp
# exportfs -rv #发布出去让其可见
exporting 192.168.10.0/24:/opt/bent
exporting 192.168.10.0/24:/opt/accp
exporting *:/usr/share
# systemctl start nfs.service
# systemctl start rpcbind.service
# systemctl stop #关闭防火钱 firewalld.service
# setenforce 0 #关闭安全模块
2.配置 192.168.10.173 节点服务器
[*]IP 192.168.10.173
[*]IP 192.168.10.172(与192.168.10.173同样配置)
[*]安装httpd服务
# yum install http -y
# showmount -e 192.168.10.174 #查看共享的存储空间
Export list for 192.168.10.174:
/usr/share *
/opt/bent192.168.10.0/24
/opt/accp192.168.10.0/24
# mount.nfs 192.168.10.174:/opt/accp /var/www/html/ #把共享的存储空间挂载到本站点网站首页
# vim /etc/httpd/conf/httpd.conf
# cat /etc/httpd/conf/httpd.conf #查看一下修改的端口和域名 | grep 80
Listen 192.168.10.173:80
#Listen 80
ServerName www.accp.com:80
# systemctl start httpd.service#开启服务
# systemctl stop firewalld.service
# setenforce 0
自测
http://i2.运维网.com/images/blog/201806/21/5b6ea6e9a677e3a35c5fe65d5f1b0f00.png
http://i2.运维网.com/images/blog/201806/21/a92143679a08e2ba6ac4def6714a139a.png
3.配置调度服务器 192.168.10.171
[*]配置双网卡作为网关
[*]IP 192.168.10.1
[*]IP 12.0.0.1
[*]在虚拟机右下角右击设置——>添加——>网络适配器——>点击确定
1):调度服务器做路由转发
# vim /etc/sysctl.conf #路由转发的配置文件
# cat /etc/sysctl.conf |grep net
net.ipv4.ip_forward=1 #在最后一行添加路由转发语句
# sysctl -p #重新加载让其生效
# iptables -t nat -F #清空防火墙
# iptables -F #清空iptables转发表
# iptables -t nat -A PROSTROUTING -o ens36 -s
192.168.10.0/24 -j SNAT --to-source 12.0.0.1 #做SNAT规则
[*]验证转发
[*]把windows7上面网址改为外网网址12.0.0.12用内网网址ping12.0.0.12外网网址看是否能ping通
http://i2.运维网.com/images/blog/201806/21/c1da960cf360085d9834a7057ff502bb.png
[*]做调度服务器
# modprobe ip_vs
# cat /proc/net/ip_vs #查看ip_vs模块有没有加载
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm #安装管理工具
# systemctl start ipvsadm.service #在centos7上面直接启动会有一个报错没有保存
ob for ipvsadm service failed because the control process exitd with error code. See "systemctl start ipvsadm.service" and "journalctl - xe" for details
# ipvsadm --save > /etc/sysconfig/ipvsadm #开启管理工具时把规则做保存(唯一和6不同之处)
# systemctl start ipvsadm.service
# systemctl status ipvsadm.service #查看状态显示绿色证明开启成功
# vim net.sh#用脚本做iptables防火墙规则
# cat net.sh
#!/bin/bash
ipvsadm -C #清除历史记录
ipvsadm -A -t 12.0.0.1:80 -s rr #添加虚拟服务器用-A -t 指定ip端口 -s 指定算法(轮询算法)
ipvsadm -a -t 12.0.0.1:80 -r 192.168.100.101:80 -m # -a 指定真实的节点服务器 -t制定端口 -r 指定真实的节点服务器的ip地址 -m 指定nat模式
ipvsadm -a -t 12.0.0.1:80 -r 192.168.100.102:80 -m
ipvsadm #启用
source net.sh #没给执行权限用source 给了权限用./启动
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCPlocalhost.localdomain:http rr
-> 192.168.10.172:http Masq 1 0 0
-> 192.168.10.173:http Masq 1 0 0
测试用windows终端查看
http://i2.运维网.com/images/blog/201806/21/483b2ff44d544937ce195756f00efeb6.png
http://i2.运维网.com/images/blog/201806/21/383cc5c75ee7a8363ce82edb0ba4bc7a.png
页:
[1]