k8s v1.18.19 二进制安装问题集锦

1、Image garbage collection failed once. Stats initialization may not have completed yet: failed to get imageFs info: unable to find data in memory cache

解决方法原地址

docker system prune
systemctl stop kubelet
systemctl stop docker
systemctl start docker
systemctl start kubelet

在使用CentOS7.9.2009(未升级内核)安装nginx对k8s 1.18.19做高可用时,在nginx.conf中使用stream模块时一直有以下提示

[root@nginx01 ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@nginx01 ~]# uname -r
3.10.0-1160.el7.x86_64
[root@nginx01 ~]# nginx -v
nginx version: nginx/1.20.1


[root@nginx01 ~]# yum -y install epel-release
[root@nginx01 ~]# yum -y install nginx keepalived 
[root@nginx01 ~]# mv /etc/nginx/nginx.conf{,.bak}


[root@nginx01 ~]# vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

#======================= 就这一段 =============================
# 四层负载均衡,为两台Master apiserver组件提供负载均衡
# stream_mudule: http://nginx.org/en/docs/stream/ngx_stream_core_module.html
stream {
    log_format  main  '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';
    access_log  /var/log/nginx/k8s-access.log  main;
    upstream k8s-apiserver {
       server 192.168.1.21:6443;
       server 192.168.1.24:6443;
    }
    server {
       listen 6443;
       proxy_pass k8s-apiserver;
    }
}
# =============================================================

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
....
    .....



[root@nginx01 ~]# nginx -t
nginx: [emerg] unknown directive "stream" in /etc/nginx/nginx.conf:15



解决:
先查看nginx现在开启了哪些模块,这些模块要复制下来
[root@nginx01 ~]# nginx -V

[root@nginx01 ~]# mv /usr/sbin/nginx{,.bak}
[root@nginx01 ~]# cp -r /etc/nginx{,.bak}
[root@nginx01 ~]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
[root@nginx01 ~]# tar -zxvf nginx-1.20.1.tar.gz
安装依赖
[root@nginx01 ~]# yum -y install libxml2 libxml2-dev libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data pcre-devel openssl openssl-devel gcc gcc-c++

[root@nginx01 ~]# cd nginx-1.20.1
检查模块是否支持
[root@nginx01 nginx-1.20.1]# ./configure --help| grep -w "\-\-with-stream"

重新编译
[root@nginx01 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-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-stream


在上面配置中,最后加上--with-stream选项并去掉下面的选项
--with-file-aio
--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-google_perftools_module


[root@nginx01 nginx-1.20.1]# make

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

[root@nginx01 nginx-1.20.1]# find / -name "objs"
/root/nginx-1.20.1/objs
[root@nginx01 nginx-1.20.1]# pwd
/root/nginx-1.20.1
[root@nginx01 nginx-1.20.1]# cd objs/
[root@nginx01 objs]# ./nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


替换Nginx文件并重启
[root@nginx01 objs]# cp /root/nginx-1.20.1/objs/nginx /usr/sbin/
[root@nginx01 objs]# cd
[root@nginx01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

验证模块是否已添加
[root@nginx01 ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --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-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-stream

注:最后一个就是重新编译后加上的

还是原来的nginx.conf,再次启动nginx就不会因为stream模块而报错
[root@nginx01 ~]# systemctl start nginx

posted @ 2021-07-08 15:13  Linux大魔王  阅读(1204)  评论(0编辑  收藏  举报