centos7实现负载均衡

目录

一、基于 CentOS 7 构建 LVS-DR 集群。

1.1 配置lvs负载均衡服务

1.1.1 下载ipvsadm

 1.1.2 增加vip

1.1.3 配置ipvsadm

1.2 配置rs1

1.2.1  编写测试页面

1.2.2 手工在RS端绑定VIP、添加路由        

1.2.3 抑制arp响应

1.3 配置rs2

 1.4 测试

二、配置nginx负载均衡。

2.1 配置好环境

2.2  web服务器上添加测试页面

2.3 配置负载均衡器

2.4  开启nginx服务和web服务

2.5 测试


一、基于 CentOS 7 构建 LVS-DR 集群。

环境:

 作用环境
windows测试 
192.168.33.158LVS负载均衡centos7
192.168.33.157web服务器1--rs1nginx:1.22,centos7
192.168.33.156web服务器2--rs2Apache:2.4 , redhat9

1.1 配置lvs负载均衡服务

1.1.1 下载ipvsadm


 1.1.2 增加vip

ifconfig ens33:110 192.168.33.100

 注意:增加的IP和本机的IP需要在同一个网段。


1.1.3 配置ipvsadm


1.2 配置rs1

1.2.1  编写测试页面


1.2.2 手工在RS端绑定VIP、添加路由        


1.2.3 抑制arp响应


1.3 配置rs2

配置和rs1一样,省略。

注意:调整内核参数,关闭arp响应的时候,redhat和centos的网络设备名称是不一样的。


 1.4 测试


二、配置nginx负载均衡。

2.1 配置好环境

作用环境
windows测试
192.168.33.158nginx负载均衡nginx:1.22,centos7
192.168.33.157web服务器1--web1nginx:1.22,centos7
192.168.33.156web服务器2--web2Apache:2.4 , redhat9

确保所有的防火墙和selinx都是关闭的。 


2.2  web服务器上添加测试页面

web1:

 web2:


2.3 配置负载均衡器

主配置文件:/usr/local/nginx/conf/nginx.conf

user nginx;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#location / {#   root /data/web2;#   index index.html index.htm;#   auth_basic "Restricted";#   auth_basic_user_file /data/web2/webpass;#}location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include	fastcgi_params;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

子配置文件:/etc/nginx/conf.d/vhost.conf

server {listen 80;server_name test.ng.test;location / {proxy_pass http://web_server;}}upstream web_server {server 192.168.33.157;server 192.168.33.156;
}


2.4  开启nginx服务和web服务

systemctl  start nginx

systemctl  start httpd


2.5 测试

用windows测试的时候,需要修改本地的hosts文件。路径:C:\Windows\System32\drivers\etc

windows 浏览器的测试

 因为是一般轮询负载均衡,所以不断刷新页面,页面会在192.168.33.157和192.168.33.156之间交替出现。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/58429.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

机器学习深度学习—语言模型和数据集

👨‍🎓作者简介:一位即将上大四,正专攻机器学习的保研er 🌌上期文章:机器学习&&深度学习——文本预处理 📚订阅专栏:机器学习&&深度学习 希望文章对你们有所帮助 语…

ASP.NET Core学习路线图

说明 1. 先决条件 - [C#](https://www.pluralsight.com/paths/csharp) - [Entity Framework](https://www.pluralsight.com/search?qentity%20framework%20core) - [ASP.NET Core](https://www.pluralsight.com/search?qasp.net%20core) - SQL基础知识 2. 通用开发技能 -…

Android 数据库之GreenDAO

GreenDAO 是一款开源的面向 Android 的轻便、快捷的 ORM 框架,将 Java 对象映射到 SQLite 数据库中,我们操作数据库的时候,不再需要编写复杂的 SQL语句, 在性能方面,greenDAO 针对 Android 进行了高度优化,…

MySQL的查询方法

单表查询 素材: 表名:worker-- 表中字段均为中文,比如 部门号 工资 职工号 参加工作 要求: 1、显示所有职工的基本信息。 2、查询所有职工所属部门的部门号,不显示重复的部门号。 3、求出所有职工的人数。 4、…

java动态生成excel并且需要合并单元格

java动态生成excel并且需要合并单元格 先上图看一下预期效果 集成poi <dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>4.0.0</version> </dependency> <dependency><…

docker部署jenkins且jenkins中使用docker去部署项目

docker部署jenkins且jenkins中使用docker去部署项目 1、确定版本 2.346.1是最后一个支持jdk8的 2、编写docker-compose.yml并执行 在这个目录中新增data文件夹&#xff0c;注意data是用来跟docker中的文件进行映射的 docker-compose.yml version: "3.1" service…

leetcode 746. 使用最小花费爬楼梯

2023.8.8 昨天爽玩一天&#xff0c;在家就是舒服。 今天继续刷动态规划题。 动态规划题最重要的就是搞清楚dp[i] 的定义&#xff0c;本题dp[i] 的含义是&#xff1a;到达第i层&#xff0c;所需的最小花费。 那么由于起始台阶可以是0或者1&#xff0c;那么dp[0]和dp[1]都初始化…

QT笔记——QT自定义事件

我们有时候想发送自定义事件 1&#xff1a;创建自定义事件&#xff0c;首先我们需要知道它的条件 1&#xff1a;自定义事件需要继承QEvent 2&#xff1a;事件的类型需要在 QEvent::User 和 QEvent::MaxUser 范围之间&#xff0c;在QEvent::User之前 是预留给系统的事件 3&#…

一零六七、JVM梳理

JVM&#xff1f; Java虚拟机&#xff0c;可以理解为Java程序的运行环境&#xff0c;可以执行Java字节码&#xff08;Java bytecode&#xff09;并提供了内存管理、垃圾回收、线程管理等功能 java内存区域划分?每块内存中都对应什么? 方法区&#xff1a;类的结构信息、常量池、…

享元模式(C++)

定义 运用共享技术有效地支持大量细粒度的对象。 使用场景 在软件系统采用纯粹对象方案的问题在于大量细粒度的对象会很快充斥在系统中&#xff0c;从而带来很高的运行时代价——主要指内存需求方面的代价。如何在避免大量细粒度对象问题的同时&#xff0c;让外部客户程序仍…

【C++】多态的底层原理(虚函数表)

文章目录 前言一、虚函数表二、派生类中虚函数表1.原理2.例子&#xff1a; 三、虚函数的存放位置四 、单继承中的虚函数表五、多继承中的虚函数表六、问答题 前言 一、虚函数表 通过观察测试我们发现b对象是8bytes&#xff0c;除了_b成员&#xff0c;还多一个__vfptr放在对象的…

常量池-JVM(十九)

上篇文章说gc日志以及arthas。 Arthas & GC日志-JVM&#xff08;十八&#xff09; 一、常量池 常量池主要放两大类&#xff1a;字面量和符号引用。 字面量就是由字母、数字等构成的字符串或者数值常量。 符号引用主要包含三类常量。 类和接口的全限定名。字段的名称和…