Linux云计算学习笔记day49

负载均衡与keepalived

1[root@lb01 ~]# curl 10.0.0.5 2web01 www.oldboy.com 3[root@lb01 ~]# curl 10.0.0.5 4web02 www.oldboy.com 5[root@lb01 ~]# curl 10.0.0.5 6web01 www.oldboy.com 7[root@lb01 ~]# curl 10.0.0.5 8web02 www.oldboy.com 9 10 --->web01 PC 存放在web01 11 12 13LB01 判断用户客户端类型 -----> 14 | 15 --->web02 移动端 web02 16 17#web01 18echo this is PC website >/app/www/lidao.html 19 20#web02 21echo this is Mobile website >/app/www/lidao.html 22 23 24[root@lb01 ~]# curl 10.0.0.7/lidao.html 25this is PC website 26[root@lb01 ~]# curl 10.0.0.8/lidao.html 27this is Mobile website 28 29[root@lb01 ~]# curl 10.0.0.[7-8]/lidao.html 30 31[1/2]: 10.0.0.7/lidao.html --> <stdout> 32--_curl_--10.0.0.7/lidao.html 33this is PC website 34 35[2/2]: 10.0.0.8/lidao.html --> <stdout> 36--_curl_--10.0.0.8/lidao.html 37this is Mobile website 38 39 upstream default { 40 server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s; 41 } 42 upstream mobile { 43 server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s; 44 } 45 46# include /etc/nginx/conf.d/*.conf; 47 server { 48 listen 80; 49 server_name www.oldboy.com; 50 location / { 51 if ($http_user_agent ~* "Android|IOS") { 52 proxy_pass http://mobile; 53 } 54 proxy_pass http://default; 55 proxy_set_header Host $host; 56 proxy_set_header X-Forwarded-For $remote_addr; 57 } 58 } 59 60[root@lb01 /etc/nginx]# curl 10.0.0.5/lidao.html 61this is PC website 62[root@lb01 /etc/nginx]# curl -A ios 10.0.0.5/lidao.html 63this is Mobile website

根据用户的uri进行转发 动静分离

web01

1mkdir -p /app/www/upload/ 2echo this is upload >/app/www/upload/guoav.html 3 4#web02 5mkdir -p /app/www/static/ 6echo this is static >/app/www/static/guoav.html 7 8#web03 9mkdir -p /app/www/ 10echo this is default >/app/www/guoav.html 11#测试 12[root@lb01 /etc/nginx]# curl 10.0.0.7/upload/guoav.html 13this is upload 14[root@lb01 /etc/nginx]# curl 10.0.0.8/static/guoav.html 15this is static 16[root@lb01 /etc/nginx]# curl 10.0.0.9/guoav.html 17this is default 18 19 20#修改lb负载均衡配置 21 22 23nginx.conf核心配置 24 upstream upload { 25 server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s; 26 } 27 upstream static { 28 server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s; 29 } 30 upstream default { 31 server 10.0.0.9:80 weight=1 max_fails=3 fail_timeout=10s; 32 } 33 34# include /etc/nginx/conf.d/*.conf; 35 server { 36 listen 80; 37 server_name www.oldboy.com; 38 location /upload { 39 proxy_pass http://upload; 40 proxy_set_header Host $host; 41 proxy_set_header X-Forwarded-For $remote_addr; 42 } 43 location /static { 44 proxy_pass http://static; 45 proxy_set_header Host $host; 46 proxy_set_header X-Forwarded-For $remote_addr; 47 } 48 location / { 49 proxy_pass http://default; 50 proxy_set_header Host $host; 51 proxy_set_header X-Forwarded-For $remote_addr; 52 }

lb01 lb02 web01 web02

lb01 lb02

1yum install keepalived -y 2 3[root@lb01 /etc/nginx]# cat nginx.conf 4 5user nginx; 6worker_processes 1; 7 8error_log /var/log/nginx/error.log warn; 9pid /var/run/nginx.pid; 10 11 12events { 13 worker_connections 1024; 14} 15 16 17http { 18 include /etc/nginx/mime.types; 19 default_type application/octet-stream; 20 21 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 22 '$status $body_bytes_sent "$http_referer" ' 23 '"$http_user_agent" "$http_x_forwarded_for"'; 24 25 access_log /var/log/nginx/access.log main; 26 27 sendfile on; 28 #tcp_nopush on; 29 30 keepalive_timeout 65; 31 32 #gzip on; 33 34 upstream web_pools { 35 ip_hash; 36 server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s; 37 server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s; 38 } 39# include /etc/nginx/conf.d/*.conf; 40 server { 41 listen 80; 42 server_name www.oldboy.com; 43 location / { 44 proxy_pass http://web_pools; 45 proxy_set_header Host $host; 46 proxy_set_header X-Forwarded-For $remote_addr; 47 } 48 } 49 50 server { 51 listen 80; 52 server_name blog.oldboy.com; 53 location / { 54 proxy_pass http://web_pools; 55 proxy_set_header Host $host; 56 proxy_set_header X-Forwarded-For $remote_addr; 57 } 58 } 59} 60

cookie session(会话)

共同点:
存放用户信息
key value类型 变量和变量内容

区别
cookie
存放在浏览器
存放钥匙
开发设置
响应服务器给你设置

1session 2 存放在服务器 redis中 3 存放敏感 4 锁头

1)VRRP协议,全称Virtual Router Redundancy Protocol,中文名为虚拟路由冗余协议,VRRP的出现是为了解决静态路由的单点故障。
3)VRRP是用过IP多播的方式(默认多播地址(224.0.0.18))实现高可用对之间通信的。
4)工作时主节点发包,备节点接包,当备节点接收不到主节点发的数据包的时候,就启动接管程序接管主节点的资源。备节点可以有多个,通过优先级竞选,但一般Keepalived系统运维工作中都是一对。

1! Configuration File for keepalived 2 3global_defs { 4 router_id LVS_DEVEL 5} 6 7vrrp_instance VI_1 { 8 state MASTER 9 interface eth0 10 virtual_router_id 51 11 priority 150 12 advert_int 1 13 authentication { 14 auth_type PASS 15 auth_pass 1111 16 } 17 virtual_ipaddress { 18 10.0.0.3/24 dev eth0 label eth0:1 19 } 20}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )