Istio 上的 Jgroups

如何解决Istio 上的 Jgroups

我正在尝试让 Jgroups 集群在 Istio 上工作。没有 istio 我可以让它工作。总之,下面的代码将尝试将 2 个 pod 放入一个 jgroups 集群。当他们在集群中时,我希望看到

NEIGHBORS:
    hello-0-19533
    hello-1-21469

然而,当我使用 istio 注入将相同的代码部署到命名空间时,我从未看到过这一点。我只看到单独隔离的 POD。我错过了什么?我需要进行哪些配置才能使其正常工作?可能吗?

我知道这可能与如何通过 istio-proxy 代理通信有关。

我使用以下清单部署了 istio

apiVersion: v1
kind: Service
metadata:
  name: hello
  labels:
    app: hello
spec:
  clusterIP: None
  ports:
    - name: tcp-ping
      protocol: TCP
      port: 7950
      targetPort: 7950
  selector:
    app: hello
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: hello
spec:
  serviceName: "hello"
  replicas: 2
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
        version: v1
    spec:
      containers:
      - name: hello
        image: jgroups_stu:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 7950
        - containerPort: 7951
        - containerPort: 7952

我的图片有以下代码

public class main {
    public static void main(String[] args) throws Exception {
        System.setProperty("java.net.preferIPv4Stack","true");
        
        String basePath = main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        System.out.println("PATH: ".concat(basePath));
        String inputFile = basePath.concat("test.xml");
        String outputFile = basePath.concat("test2.xml");
        Map<String,String> env = System.getenv();
        String bind_addr = env.get("HOSTNAME");
        String bind_port;
        
        if(bind_addr == null) {
            bind_addr = "localhost";
        }
        bind_port = "7950";
        if(bind_addr.contains("1")) {
            bind_addr = "172.17.0.4";
        }else {
            bind_addr = "172.17.0.3";
        }

        System.out.println("HOST: ".concat(bind_addr));
        updateXml(inputFile,inputFile,"bind_addr",bind_addr);
        updateXml(inputFile,"bind_port",bind_port);
        updateXml(inputFile,outputFile,"initial_hosts","127.0.0.1[7950],172.17.0.3[7950],172.17.0.4[7950]");
        
        JChannel ch = new JChannel(outputFile);
       
        ch.connect("TestCluster");

        final int SLEEP_TIME_IN_MILLIS = 1000;
        while (true) {
            checkNeighbors(ch);
            try {
                Thread.sleep(SLEEP_TIME_IN_MILLIS);
            } catch (InterruptedException e) {
                // Ignored
            }
        }
    }
    
    private static void updateXml(String inputFile,String outputFile,String replaceKey,String replaceVal) throws SAXException,IOException,ParserConfigurationException,XPathExpressionException,TransformerFactoryConfigurationError,TransformerException {
        // 1- Build the doc from the XML file
        org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder().parse(new InputSource(inputFile));

        // 2- Locate the node(s) with xpath
        XPath xpath = XPathFactory.newInstance().newXPath();
        NodeList nodes = (NodeList)xpath.evaluate("//*[contains(@".concat(replaceKey).concat(",'!Here')]"),doc,XPathConstants.NODESET);

        //System.out.println( nodes.getLength());
        // 3- Make the change on the selected nodes
        for (int idx = 0; idx < nodes.getLength(); idx++) {
            Node value = nodes.item(idx).getAttributes().getNamedItem(replaceKey);
            String val = value.getNodeValue();
            value.setNodeValue(val.replaceAll("!Here",replaceVal));
        }
        DOMSource domSource = new DOMSource(doc);
        StringWriter outWriter = new StringWriter();
        
  
        // 4- Save the result to a new XML doc
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.transform(domSource,new StreamResult(outWriter));
        xformer.transform(domSource,new StreamResult(new File(outputFile)));
        
        StringBuffer sb = outWriter.getBuffer(); 
        String finalstring = sb.toString();
        System.out.println(finalstring);
    }

    private static void checkNeighbors(JChannel channel) {
        View view = channel.getView();

        List<Address> addresses = view.getMembers();
        System.out.println("NEIGHBORS:");
        for (Address address : addresses) {
            System.out.println("    " + address);
        }
    }
}

测试.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="urn:org:jgroups"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
    <TCP bind_addr="!Here"
         bind_port="!Here"
         recv_buf_size="${tcp.recv_buf_size:130k}"
         send_buf_size="${tcp.send_buf_size:130k}"
         max_bundle_size="64K"
         sock_conn_timeout="300"

         thread_pool.min_threads="0"
         thread_pool.max_threads="20"
         thread_pool.keep_alive_time="30000"/>

    <TCPPING async_discovery="true"
             initial_hosts="${jgroups.tcpping.initial_hosts:!Here}"
             port_range="2"/>
    <MERGE3  min_interval="10000"
             max_interval="30000"/>
    <FD_SOCK/>
    <FD timeout="3000" max_tries="3" />
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK2 use_mcast_xmit="false"
                   discard_delivered_msgs="true"/>
    <UNICAST3 />
    <pbcast.STABLE desired_avg_gossip="50000"
                   max_bytes="4M"/>
    <pbcast.GMS print_local_addr="true" join_timeout="2000"
                view_bundling="true"/>
    <MFC max_credits="2M"
         min_threshold="0.4"/>
    <FRAG2 frag_size="60K"  />
    <!--RSVP resend_interval="2000" timeout="10000"/-->
    <pbcast.STATE_TRANSFER/>
</config>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res