• 麒麟V10下离线部署Rancher无法打开监控


    关注 码龄 粉丝数 原力等级 -- 被采纳 被点赞 采纳率 kisshexuxia 2024-04-13 16:59 采纳率: 0% 浏览 5 首页/ 云计算 / 麒麟V10下离线部署Rancher无法打开监控 kuberneteslinux 背景: 最近适配国产化信创,使用银河麒麟SP3服务器版本,在用rancher部署K8S后,启用监控模块,无法启动,查看是命名空间: cattle-prometheus下的grafana-cluster-monitoring有异常,追踪下去是子pod grafana-proxy启动时候查看错误日志nginx: [emerg] host not found in upstream "localhost" in /nginx/nginx.conf:33 ######正常的Nginx.conf worker_processes auto; error_log /dev/stdout warn; pid /var/cache/nginx/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; log_format main '[$time_local - $status] $remote_addr - $remote_user $request ($http_referer)'; proxy_connect_timeout 10; proxy_read_timeout 180; proxy_send_timeout 5; proxy_buffering off; proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=my_zone:100m inactive=1d max_size=10g; server { listen 8080; access_log off; gzip on; gzip_min_length 1k; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript image/jpeg image/gif image/png; gzip_vary on; gzip_disable "MSIE [1-6]\."; proxy_set_header Host $host; location /api/dashboards { proxy_pass http://localhost:3000; } location /api/search { proxy_pass http://localhost:3000; sub_filter_types application/json; sub_filter_once off; sub_filter '"url":"/d' '"url":"d'; } location / { proxy_cache my_zone; proxy_cache_valid 200 302 1d; proxy_cache_valid 301 30d; proxy_cache_valid any 5m; proxy_cache_bypass $http_cache_control; add_header X-Proxy-Cache $upstream_cache_status; add_header Cache-Control "public"; proxy_pass http://localhost:3000/; sub_filter_types text/html; sub_filter_once off; sub_filter '"appSubUrl":""' '"appSubUrl":"."'; sub_filter '"url":"/' '"url":"./'; sub_filter ':"/avatar/' ':"avatar/'; if ($request_filename ~ .*\.(?:js|css|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$) { expires 90d; } } } }[rancher@rancher1 ~]$ 操作环境: 银河麒麟SP3服务器版本、软件版本:rancher2.4.5 Kubernetes 版本: v1.18.3 docker EC18.0.9和20都测了 尝试过的解决方法 和Cenos7.9部署的环境进行了比较,发现麒麟下执行kubectl命令行,cat /etc/hosts没权限,vi打开文件是空的,看错误日志应该是这个空的引起Nginx 配置localhost无法解析。 # Run kubectl commands inside here # e.g. kubectl get all > cat /etc/hosts cat: /etc/hosts: Permission denied > 在Centos7.9下执行正常 # Kubernetes-managed hosts file. 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet fe00::0 ip6-mcastprefix fe00::1 ip6-allnodes fe00::2 ip6-allrouters 10.42.1.113 grafana-cluster-monitoring-855c6cdd4-n2hhf 2个系统中的hosts的权限分别是-rw-r--r--. 1 root root 206 Oct 31 13:13 hosts(Centos)-rw-r----- 1 root root 206 Apr 12 13:38 hosts(麒麟) kubectl -n cattle-prometheus patch deployments grafana-cluster-monitoring --patch '{ "spec": { "template": { "spec": { "hostAliases": [ { "hostnames": [ "localhost" ], "ip": "127.0.0.1" } ] } } } }' 我想要达到的结果 grafana-cluster-monitoring能和Centos7.9环境一样新增pod中的hosts权限正常 展开全部 收起 写回答 好问题 0 提建议 追加酬金 关注问题 微信扫一扫 点击复制链接 分享 邀请回答 编辑 收藏 删除 结题 收藏 举报 追加酬金 (90%的用户在追加酬金后获得了解决方案) 当前问题酬金 ¥ 0 (可追加 ¥500) ¥ 15¥ 20¥ 50¥ 100¥ 200 支付方式 扫码支付 二维码出错 点击刷新 支付金额 15 元 提供问题酬金的用户不参与问题酬金结算和分配 支付即为同意 《付费问题酬金结算规则》 结题 再想想 删除 再等等

    4条回答 默认 最新

    • 专家-赤兔[在线] 全栈领域优质创作者 2024-04-13 16:59
      关注

      引自免费微信小程序:皆我百晓生

      针对你在麒麟V10环境下遇到的问题,Rancher 的 Grafana 监控模块无法启动,并且报错 nginx: [emerg] host not found in upstream "localhost",这通常是因为 Nginx 无法正确地将流量转发到本地服务,可能是由于 /etc/hosts 文件没有正确的配置。

      解决这个问题可以尝试通过为 Grafana 的 Pod 添加 Host Aliases,这样它就可以访问 localhost 而不需要依赖于 /etc/hosts 文件。下面是具体的步骤:

      1. 使用下面的 YAML 来更新 grafana-cluster-monitoring Deployment,添加一个 Host Alias 到 Pod 的配置中,使 Pod 可以通过 localhost 访问 127.0.0.1:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: grafana-cluster-monitoring
        namespace: cattle-prometheus
      spec:
        template:
          spec:
            hostAliases:
            - ip: "127.0.0.1"
              hostnames:
              - "localhost"
            containers:
            # ... (这里保留原有的 containers 配置)
      
      1. 将上面的 YAML 内容保存为一个文件,例如 update_grafana.yaml,然后应用这些更改:
      kubectl apply -f update_grafana.yaml -n cattle-prometheus
      
      1. 如果上述方法无效,可能还需要更新 Grafana 的配置本身,确保它使用的代理指向正确的地址。可以在 Grafana 的数据卷中添加一个配置文件,覆盖默认配置。创建一个名为 grafana.ini 的文件,内容如下:
      [server]
      http_port = :80
      root_url = http://localhost:3000/
      
      [proxy]
      upstream_url = http://localhost:8080/
      
      1. 然后,将此配置文件添加到 Grafana 的 Deployment 中:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: grafana-cluster-monitoring
        namespace: cattle-prometheus
      spec:
        template:
          spec:
            volumes:
            - name: grafana-config
              configMap:
                name: grafana-configmap
            containers:
            - name: grafana-proxy
              volumeMounts:
              - mountPath: /etc/grafana/conf
                name: grafana-config
            # ... (这里保留原有的 containers 配置)
      
      1. 创建一个 ConfigMap 来存储 grafana.ini 文件:
      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: grafana-configmap
      data:
        grafana.ini: |-
          [server]
          http_port = :80
          root_url = http://localhost:3000/
      
          [proxy]
          upstream_url = http://localhost:8080/
      
      1. 应用这个 ConfigMap:
      kubectl apply -f grafana-configmap.yaml -n cattle-prometheus
      
      1. 最后,更新 Grafana 的 Deployment 以应用新的 ConfigMap:
      kubectl set env deployment grafana-cluster-monitoring grafana_config_map=grafana-configmap -n cattle-prometheus
      

      完成上述操作后,Grafana 应该能够正确地使用代理并将流量转发给内部服务,从而解决监控模块无法启动的问题。如果还有任何问题,请检查 Grafana 和相关组件的日志,以便进一步排查。

      展开全部

      评论 编辑记录
      kisshexuxia 2024-04-13 19:29

      第一点修改配置文件应该执行这个代码块一个意思吧我执行了没有效果

      kubectl -n cattle-prometheus patch  deployments grafana-cluster-monitoring --patch '{
          "spec": {
              "template": {
                  "spec": {
                      "hostAliases": [
                          {
                              "hostnames":
                              [
                                  "localhost"
                              ],
                                  "ip": "127.0.0.1"
                          }
                      ]
                  }
              }
          }
      }'
       
      
      

      回复
    • Kwan的解忧杂货铺 Java领域优质创作者 2024-04-16 13:31
      关注

      下午好🌅🌅🌅
      本答案参考ChatGPT-3.5

      针对离线部署Rancher无法打开监控的问题,可以考虑以下解决方案:

      1. 检查系统环境

      首先需要检查系统环境是否满足Rancher的最小要求,包括操作系统版本、内核版本、Docker版本等。确保系统环境符合Rancher的要求,才能进行后续的操作。

      1. 检查Rancher版本和Kubernetes版本

      Rancher的版本和Kubernetes的版本需要保持兼容,否则可能会出现兼容性问题。因此,需要检查Rancher和Kubernetes的版本是否匹配。

      1. 检查监控模块

      如果监控模块无法启动,可以检查以下内容:

      • 检查Prometheus和Grafana的配置文件,确保没有错误或者遗漏;
      • 检查Prometheus和Grafana的Pod是否正常运行,查看日志文件;
      • 检查Prometheus和Grafana的Service是否正常。
      1. 修改hosts文件

      如果出现Nginx配置localhost无法解析的问题,可以考虑修改hosts文件,添加相关配置。具体操作如下:

      kubectl -n cattle-prometheus patch deployments grafana-cluster-monitoring --patch '{ "spec": { "template": { "spec": { "hostAliases": [ { "hostnames": [ "localhost" ], "ip": "127.0.0.1" } ] } } } }'

      通过修改hosts文件,确保grafana-cluster-monitoring能和Centos7.9环境一样新增pod中的hosts权限正常。

      参考文献:麒麟V10下离线部署Rancher无法打开监控

      评论
    • 专家-百锦再 全栈领域优质创作者 2024-04-13 17:00
      关注

      patch --patch "
      spec"
      "
      template"
      "
      spec"
      "
      hostAliases"
      "
      hostnames"
      "
      localhost"
      "
      ip"
      "
      127.0.0.1"
      kubectl -n cattle-prometheus deployments grafana-cluster-monitoring '{"
      spec"
      : {"
      template"
      : {"
      spec"
      : {"
      hostAliases"
      : [{"
      hostnames"
      : ["
      localhost"
      ],"
      ip"
      : "
      127.0.0.1"
      }]}}}}'

      在上面的代码中,使用kubectl命令对grafana-cluster-monitoring的部署进行了修改,新增了一个hostAliases,将localhost解析为127.0.0.1。这样可以解决麒麟系统下hosts权限不足导致Nginx配置中的localhost无法解析的问题,使得grafana-cluster-monitoring能够正常启动。


      有问题你别着急,评论留言都可以,看到马上就回复,尽量及时补充齐

      展开全部

      评论
      kisshexuxia 2024-04-13 19:27

      这个我上面写了也是这么执行的

      回复
      专家-百锦再 2024-04-13 19:30

      ```yaml
      patch --patch \"spec\" \"template\" \"spec\" \"hostAliases\" \"hostnames\" \"localhost\" \"ip\" \"127.0.0.1\"
      kubectl -n cattle-prometheus deployments grafana-cluster-monitoring '{
      \"spec\": {
      \"template\": {
      \"spec\": {
      \"hostAliases\": [
      {
      \"hostnames\": [
      \"localhost\"
      ],
      \"ip\": \"127.0.0.1\"
      }
      ]
      }
      }
      }
      }'
      ```

      回复
      专家-百锦再 2024-04-13 20:00

      ```
      kubectl -n cattle-prometheus patch deployments grafana-cluster-monitoring -p '{\"spec\":{\"template\":{\"spec\":{\"hostAliases\":[{\"hostnames\":[\"localhost\"],\"ip\":\"127.0.0.1\"}]}}}}'
      ```

      这条命令会修改grafana-cluster-monitoring下的deployment,添加一个hostAliases,将localhost映射到127.0.0.1。这样应该可以解决您遇到的问题。

      回复
      展开全部4条评论
    • GISer Liu 2024-04-13 17:03
      关注

      该回答引用自GPT-3.5,由博主GISer Liu编写:

      针对你的问题,首先需要解决权限相关的问题,然后再考虑如何修复Rancher部署的监控模块无法启动的情况。我会逐步给出解决思路和方案:

      1. 解决权限问题
      • 首先,确保在银河麒麟SP3服务器上以root权限执行kubectl命令,以便对/etc/hosts文件进行修改。
      • 执行以下命令提升/etc/hosts文件的权限:
        bashCopy code
        sudo chmod 644 /etc/hosts
        
      • 这将确保/etc/hosts文件的权限与CentOS 7.9环境下的一致,避免Nginx配置中localhost无法解析的问题。
      1. 修复Rancher部署监控模块无法启动的问题
      • 针对子pod grafana-proxy 启动时的错误日志 nginx: [emerg] host not found in upstream "localhost" in /nginx/nginx.conf:33,需要修改 grafana-cluster-monitoring 的配置。
      • 使用 kubectl 命令修改 grafana-cluster-monitoring 的配置,增加 hostAliases
        bashCopy code
        kubectl -n cattle-prometheus patch deployments grafana-cluster-monitoring --patch '{
        "spec": {
        "template": {
        "spec": {
        "hostAliases": [
        {
        "hostnames": ["localhost"],
        "ip": "127.0.0.1"
        }
        ]
        }
        }
        }
        }'
        
      • 这个命令会将 grafana-cluster-monitoring 中的 localhost 解析到 127.0.0.1,解决 Nginx 配置中 localhost 无法解析的问题。
        通过以上步骤,应该可以解决你遇到的问题。请执行这些步骤,如果还有其他问题或需要进一步的帮助,请随时告诉我。

      如果该回答解决了您的问题,请采纳!如果没有,请私信联系或评论您的疑惑

      展开全部

      评论
      kisshexuxia 2024-04-13 19:27

      这个我上面写了也是这么执行的

      回复
      GISer Liu 2024-04-14 03:17

      根据您的问题描述,您遇到了银河麒麟SP3服务器上离线部署Rancher后无法打开监控的问题。经过分析,主要涉及到两个方面:文件权限和Rancher部署的监控模块配置。以下是解决思路和方案:

      1. 解决权限问题
      • 确保在银河麒麟SP3服务器上以root权限执行 kubectl 命令,以便对 /etc/hosts 文件进行修改。
      • 执行以下命令提升 /etc/hosts 文件的权限:
        shCopy code
        sudo chmod 644 /etc/hosts
        
      • 这将确保 /etc/hosts 文件的权限与CentOS 7.9环境下的一致,避免Nginx配置中 localhost 无法解析的问题。
      1. 修复Rancher部署监控模块无法启动的问题
      • 针对子pod grafana-proxy 启动时的错误日志 nginx: [emerg] host not found in upstream "localhost" in /nginx/nginx.conf:33,需要修改 grafana-cluster-monitoring 的配置。
      • 使用 kubectl 命令修改 grafana-cluster-monitoring 的配置,增加 hostAliases
        shCopy code
        kubectl -n cattle-prometheus patch deployments grafana-cluster-monitoring --patch '{
        "spec": {
        "template": {
        "spec": {
        "hostAliases": [
        {
        "hostnames": ["localhost"],
        "ip": "127.0.0.1"
        }
        ]
        }
        }
        }
        }'
        
      • 这个命令会将 grafana-cluster-monitoring 中的 localhost 解析到 127.0.0.1,解决 Nginx 配置中 localhost 无法解析的问题。
        请按照以上步骤执行,如果问题仍然存在或者有其他问题,请随时告诉我。

      回复
    编辑
    预览

    报告相同问题?

  • 相关阅读:
    从eBPF到Rust:让内核可观测、可编程和更安全
    python-web开发[11]之css样式学习
    基于微信小程序的懒人美食帮外卖订餐设计与实现(亮点:多角色的订餐系统、最贴近现实的小程序)
    setup中的nextTick函数
    图论2023.11.12
    肽核酸(PNA)偶联穿膜肽(CCPs)(KFF)3K形成CCPs-PNA|肽核酸的使用方法
    (JAVA)P5708 【深基2.习2】三角形面积
    Python使用lxml解析XML格式化数据
    Linux-环境变量
    天龙八部服务端Public目录功能讲解
  • 原文地址:https://ask.csdn.net/questions/8087898