k8s-4 nginx yum安装无法使用四层负载均衡-无法使用stream模块

在centos7 用yum 安装的nginx无法使用stream功能得,需要重新编译安装

1,查看系统之前安装参数

]# nginx -V 可以查看到系统安装nginx时得配置参数configure arguments:

2,下载一个跟系统用yum 安装版本相同得二进制包

]# rpm -qa nginx
nginx-1.20.1-2.el7.x86_64
]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
]# tar xf nginx-1.20.1.tar.gz && cd nginx-1.20.1

3, 备份原Nginx文件

]# mv /usr/sbin/nginx /usr/sbin/nginx.bak
]# cp -r /etc/nginx /etc/nginx.bak

4,安装依赖

]# yum -y install libxml2 libxml2-dev libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data
]# yum -y install --skip-broken gcc gcc-c++ autoconf automake gperftools
]# yum -y install --skip-broken zlib zlib-devel openssl-devel pcre-devel
]# yum -y install redhat-rpm-config.noarch
yum -y install --skip-broken gcc gcc-c++ autoconf automake gperftools zlib zlib-devel openssl-devel pcre-devel redhat-rpm-config.noarch

5,编译,加上本次需新增的模块: --with-stream

cd nginx-1.20.1

./configure  --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --with-stream
6,编译通过,继续验证

继续输入:make
make完成后不要继续输入“make install”,以免现在的nginx出现问题
以上完成后,会在objs目录下生成一个nginx文件,先验证:
nginx-1.12.2/objs/nginx -t
nginx-1.12.2/objs/nginx -V

7,替换Nginx文件并重启:

cd ./nginx-1.12.2/objs/nginx /usr/sbin/
nginx -s reload
重新启动nginx服务,nginx安装stream模块已生效。

8,编译安装时出错:

]# ./configure: error: the invalid value in --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"

]# yum -y install redhat-rpm-config.noarch

9,添加stream配置信息:

注意: stream 与 http 是同级
]# vi /etc/nginx/nginx.conf
stream {
upstream kube-apiserver {
server 10.4.7.21:6443 max_fails=3 fail_timeout=30s;
server 10.4.7.22:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 7443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}

10,检查配置并启动

]# nginx -t
]# systemctl restart nginx

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值