(1)7层协议
OSI(Open System Interconnection)是一个定义的非常好的协议规范,共包含七层协议,物理层,数据链路层,网络层,传输层,会话层,表示层,应用层。
(2)4层协议
TCP/IP协议
之所以说TCP/IP是一个协议族,是因为TCP/IP协议包括TCP、IP、UDP、ICMP、RIP、TELNETFTP、SMTP、ARP、TFTP等许多协议,这些协议一起称为TCP/IP协议。
从协议分层模型方面来讲,TCP/IP由四个层次组成:网络接口层、网络层、传输层、应用层。
配置:
准备三台机器:
代理服务IP:10.0.105.201 --配置本地host解析域名;
后端服务器IP:nginx-a :10.0.105.199
nginx-b:10.0.105.202(yum安装)后端服务器将nginx服务启动
配置代理服务器的nginx配置文件
worker_processes 4;
worker_rlimit_nofile 102400;
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;
keepalive_timeout 65;
gzip on;
upstream testweb {
ip_hash;
server 10.0.105.199:80 weight=2 max_fails=2 fail_timeout=2s;
server 10.0.105.202:80 weight=2 max_fails=2 fail_timeout=2s;
}
server {
listen 80;
server_name www.test.com;
charset utf-8;
#access_log logs/host.access.log main;
location / {
proxy_pass http://testweb;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
}
测试访问
10.0.105.202 10.0.105.199服务器yum安装的创建新的配置文件:
[root@nginx-server ~]# cd /etc/nginx/conf.d/
[root@nginx-server conf.d]# cp default.conf test.conf
[root@nginx-server conf.d]# cat test.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
[root@nginx-server ~]# nginx -s reload
4层tcp负载
stream {
upstream myweb {
hash $remote_addr consistent;
server 172.17.14.2:8080;
server 172.17.14.3:8080;
}
server {
listen 80;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass myweb;
}
}