Bootstrap

解决nginx stream无法使用问题

错误代码

[root@xxx nginx]# ./sbin/nginx -t
nginx: [emerg] unknown directive "stream" in /usr/local/nginx//conf/nginx.conf:118
nginx: configuration file /usr/local/nginx//conf/nginx.conf test failed

#或者这种
[root@xxx nginx]# ./sbin/nginx -t
nginx: [emerg] dlopen() "/usr/lib64/nginx/modules/ngx_stream_module.so" failed (/usr/lib64/nginx/modules/ngx_stream_module.so: undefined symbol: ngx_ssl_session_cache_init) in /usr/local/nginx/conf/nginx.conf:2
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

解决办法

  1. 先删除原有的nginx
  2. 重新构建nginx
# 添加使用--with-stream=dynamic 配置
./configure --prefix=/usr/local/nginx/ --with-stream=dynamic
# 然后make  make install
make
make install
  1. 到/usr/local/nginx/ 中发现多了modules文件夹
[root@fhd nginx]# ll
total 0
drwxr-xr-x 2 root root 333 Mar  9 11:10 conf
drwxr-xr-x 2 root root  40 Mar  9 11:09 html
drwxr-xr-x 2 root root   6 Mar  9 11:09 logs
drwxr-xr-x 2 root root  34 Mar  9 11:09 modules
drwxr-xr-x 2 root root  19 Mar  9 11:09 sbin
  1. 修改nginx.conf文件, 在首行添加 load_module /usr/local/nginx/modules/ngx_stream_module.so;
load_module /usr/local/nginx/modules/ngx_stream_module.so;
  1. 再次使用stream
stream {
	upstream kube-apiserver {
	       server 192.168.10.64:6443     max_fails=3 fail_timeout=30s;
	       server 192.168.10.65:6443     max_fails=3 fail_timeout=30s;
       }
        server {
	        listen 7443;
	        proxy_connect_timeout 2s;
	        proxy_timeout 900s;
	        proxy_pass kube-apiserver;
	}
}
  1. 保存配置文件, 并测试配置文件
[root@fhd nginx]# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
  1. 此时发现测试配置文件通过, 可以成功启动nginx
;