首页 > 系统相关 >yum安装支持四层代理的nginx

yum安装支持四层代理的nginx

时间:2022-12-09 17:04:55浏览次数:77  
标签:负载 log 四层 nginx yum conf 均衡

四层负载均衡的特点

  • 四层负载均衡仅能转发TCP/IP协议、UDP协议、通常用来转发端口,如:tcp/22、udp/53;
  • 四层负载均衡可以用来解决七层负载均衡端口限制问题;(七层负载均衡最大使用65535个端口号)
  • 四层负载均衡可以解决七层负载均衡高可用问题;(多台后端七层负载均衡能同时的使用)
  • 四层的转发效率比七层的高得多,但仅支持tcp/ip协议,不支持http和https协议;
  • 通常大并发场景通常会选择使用在七层负载前面增加四层负载均衡。

nginx部署

本次使用yum安装的方式。

配置yum源

cat > nginx-upstream.repo << EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
## 清理缓存
yum clean all
## 生成缓存
yum makecache fast

安装nginx

yum install nginx -y

创建用户:

groupadd www -g 666 && useradd www -u 666 -g 666 -s /sbin/nologin -M

配置nginx:

vim /etc/nginx/nginx.conf 
user  www;

启动nginx:

systemctl start nginx && systemctl enable nginx && systemctl status nginx

配置四层代理

首先,配置nginx主配置文件:

vim /etc/nginx/nginx.conf
#注释http层所有内容
user  www;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
#添加一个包含文件
include /etc/nginx/conf.c/*.conf;
#http {
#    include       /etc/nginx/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  /var/log/nginx/access.log  main;
#    sendfile        on;
#    #tcp_nopush     on;
#    keepalive_timeout  65;
#    #gzip  on;
#    include /etc/nginx/conf.d/*.conf;
#}

配置四层负载均衡,这里提供一个示例:

# cat veos-baidu-mongo.conf
# TCP MongoDB
stream {
    server {
        listen 23000;
        proxy_pass veos-baidu-mongocluster;
        proxy_connect_timeout 60s;
        proxy_timeout 60m;
    }
    upstream veos-baidu-mongocluster {
        server 10.x.x.x:23000 max_fails=3 fail_timeout=10;
        server 10.x.x.x:23000 max_fails=3 fail_timeout=10;
        server 10.x.x.x:23000 max_fails=3 fail_timeout=10;
    }
}

平滑重启nginx:

nginx -t
nginx -s reload

参考文档

yum安装支持四层代理的nginx.md

标签:负载,log,四层,nginx,yum,conf,均衡
From: https://blog.51cto.com/wutengfei/5926271

相关文章

  • nginx 代理配置
     测试nginx 生产nginx   前端访问地址  ......
  • nginx中server_name的作用
    转:nginx中server_name的作用  先上例子nginx部署在局域网中192.168.2.4的服务器上,修改nginx.conf配置文件,添加3个server,然后执行命令nginx-sreload重新加载nginx......
  • Nginx 反向代理如何获取真实的ip
    问题出现的环境:本地(H)postMan 请求nginx(A服务器)--转到两台应用服务器(B,C);预期是应用服务器接口请求的时候,拿到的是本地的H的服务器,但是拿到的是A服务器的IP; 转:nginx......
  • nginx + graylog 对于日志进行管理的一个实践
    以下整理一个自己结合ngin+graylog进行日志处理的实践,可以参考日志参考玩法   参考配置logformat参考如下,可以配置一些符合自己业务的logformat不同业务......
  • 在nginx配置jenkins反向代理
    配置文件如下server{listen80;listen[::]:80;server_nameci.10086z.cn;location/{rewrite(.*)https://ci.10086z.cn$1permanent;try_files$uri$......
  • 【Centos7】安装mongodb 使用yum源
    根据mongodb官网提供的教程安装:1.创建mongdb-org-3.4.repo2.使得selinux的config为disabled3.yum-yinstallmongodbxxxxxx4.配置/etc/mongod.conf5.servicemongodstart[......
  • 宝塔严重未知安全性漏洞(宝塔面板或Nginx异常)
    问题简述论坛上的帖子https://www.bt.cn/bbs/thread-105054-1-1.htmlhttps://www.bt.cn/bbs/thread-105085-1-1.htmlhttps://hostloc.com/thread-1111691-1-1.html......
  • 解决:-bash: wget: 未找到命令,yum -y install wget却又报没有可用软件包
    在终端执行yum-yinstallwget时,终端提示:[root@master1-2redis]#yuminstallwget-y已加载插件:fastestmirrorLoadingmirrorspeedsfromcachedhostfilehttp://v......
  • Nginx的Keepalive的简单学习
    摘要最近发现某项目的Nginx负载服务器上面有很多Time_wait的TCP连接可以使用命令netstat-n|awk'/^tcp/{++S[$NF]}END{for(ainS)printa,S[a]}'当时反馈过......
  • k8s 1.19.11 Ingress-nginx 的部署
    官网地址:https://kubernetes.github.io/ingress-nginx/github:https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx参考文档:使用ingress......