最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java通過證書訪問etcd的實(shí)現(xiàn)步驟

 更新時間:2024年05月08日 09:52:10   作者:amadeus_liu2  
Etcd提供了多種語言的客戶端庫,本文主要介紹了java通過證書訪問etcd的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

一、首先,要使用cfssl生成etcd證書相關(guān)的文件(ca.pem server.pem server-key.pem ),然后把server-key.pem進(jìn)行轉(zhuǎn)換:

openssl pkcs8 -topk8 -nocrypt -in server-key.pem -out server.key

二、帶證書啟動etcd

./etcd --name infra0   --cert-file=/root/server.pem --key-file=/root/server-key.pem   --advertise-client-urls=https://0.0.0.0:2379 --listen-client-urls=https://0.0.0.0:2379

可通過etcdctl 進(jìn)行連接驗(yàn)證

./etcdctl --cacert=/root/ca.pem --cert=/root/server.pem --key=/root/server-key.pem --endpoints="https://10.180.23.10:2379" get Elon

三、在java項(xiàng)目中添加相關(guān)依賴,完整依賴類似如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>springbootetcd3</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencies>


        <dependency>
            <groupId>io.etcd</groupId>
            <artifactId>jetcd-core</artifactId>
            <version>0.7.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.coreos/jetcd-core -->
<!--        <dependency>
            <groupId>com.coreos</groupId>
            <artifactId>jetcd-core</artifactId>
            <version>0.0.2</version>
        </dependency>-->



        <!--                <dependency>
                            <groupId>io.etcd</groupId>
                            <artifactId>jetcd-core</artifactId>
                            <version>0.5.0</version>
                        </dependency>-->

<!--        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty-shaded</artifactId>
            <version>1.50.0</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.90.Final</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.netty/netty-tcnative -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-tcnative</artifactId>
            <version>2.0.65.Final</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-tcnative-boringssl-static</artifactId>
            <version>2.0.65.Final</version>
        </dependency>




        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>



    </dependencies>

</project>

四、創(chuàng)建客戶端,訪問etcd

package cn.edu.tju;


import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.api.PutResponse;
import io.grpc.netty.GrpcSslContexts;
import io.netty.handler.ssl.SslContext;


import java.io.File;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class EtcdExample {
    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

        File cert = new File("d:\\ca.pem");
        File keyCertChainFile = new File("d:\\server.pem");
        File keyFile = new File("d:\\server.key");
        SslContext context = GrpcSslContexts.forClient()
                .trustManager(cert)
                .keyManager(keyCertChainFile, keyFile)
                .build();
        Client client = Client.builder()
                .endpoints("https://xx.xx.xx.xx:2379")
                .sslContext(context)
                .build();

        ByteSequence key = ByteSequence.from("Elon".getBytes());
        ByteSequence value = ByteSequence.from("Musk".getBytes());
        // put the key-value
        client.getKVClient().put(key,value).get();
        System.out.println("ok");

    }
}

到此這篇關(guān)于java通過證書訪問etcd的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)java 證書訪問etcd內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • jedis獲取redis中二進(jìn)制圖片轉(zhuǎn)Base64方式

    jedis獲取redis中二進(jìn)制圖片轉(zhuǎn)Base64方式

    這篇文章主要介紹了jedis獲取redis中二進(jìn)制圖片轉(zhuǎn)Base64方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • springBoot整合shiro如何解決讀取不到@value值問題

    springBoot整合shiro如何解決讀取不到@value值問題

    這篇文章主要介紹了springBoot整合shiro如何解決讀取不到@value值問題,具有很好的參考價值,希望對大家有所幫助,
    2023-08-08
  • 簡單了解Spring Framework5.0新特性

    簡單了解Spring Framework5.0新特性

    這篇文章主要介紹了簡單了解Spring Framework5.0新特性,涉及了核心框架修訂,核心容器更新,使用Kotlin進(jìn)行函數(shù)式編程等幾個方面的介紹,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • 解析spring加載bean流程的方法

    解析spring加載bean流程的方法

    這篇文章主要介紹了解析spring加載bean流程的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Java如何根據(jù)實(shí)體指定字段值對其List進(jìn)行排序詳解

    Java如何根據(jù)實(shí)體指定字段值對其List進(jìn)行排序詳解

    在Java項(xiàng)目中可能會遇到給出一些條件,將List元素按照給定條件進(jìn)行排序的情況,這篇文章主要給大家介紹了關(guān)于Java如何根據(jù)實(shí)體指定字段值對其List進(jìn)行排序的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-07-07
  • Swing常用組件之文本框和文本區(qū)

    Swing常用組件之文本框和文本區(qū)

    這篇文章主要為大家詳細(xì)介紹了Swing常用組件之文本框(JTestField)和文本區(qū)(JTextArea),Swing是一個用于開發(fā)Java應(yīng)用程序用戶界面的開發(fā)工具包,本文開始帶大家學(xué)習(xí)Swing
    2016-05-05
  • SpringBoot整合Thymeleaf的方法

    SpringBoot整合Thymeleaf的方法

    這篇文章主要介紹了SpringBoot整合Thymeleaf的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-02-02
  • JAVA 16位ID生成工具類含16位不重復(fù)的隨機(jī)數(shù)數(shù)字+大小寫

    JAVA 16位ID生成工具類含16位不重復(fù)的隨機(jī)數(shù)數(shù)字+大小寫

    這篇文章主要介紹了JAVA 16位ID生成工具類含16位不重復(fù)的隨機(jī)數(shù)數(shù)字+大小寫,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • Spring?Cloud?Stream消息驅(qū)動組件使用方法介紹

    Spring?Cloud?Stream消息驅(qū)動組件使用方法介紹

    Spring?Cloud?Stream?消息驅(qū)動組件幫助我們更快速,更方便,更友好的去構(gòu)建消息驅(qū)動微服務(wù)的。當(dāng)時定時任務(wù)和消息驅(qū)動的?個對比。消息驅(qū)動:基于消息機(jī)制做一些事情
    2022-09-09
  • java?String.join()方法實(shí)例詳解

    java?String.join()方法實(shí)例詳解

    String.join()是Java提供的一個實(shí)用方法,用于將多個字符串按照指定的分隔符連接成一個字符串,這一方法是Java8中引入的,極大地簡化了字符串拼接的操作,本文給大家介紹java?String.join()方法,感興趣的朋友一起看看吧
    2025-06-06

最新評論

周宁县| 安达市| 岐山县| 灵宝市| 甘南县| 江口县| 会泽县| 元谋县| 和政县| 黄浦区| 浑源县| 会昌县| 乐陵市| 辉县市| 交口县| 南昌市| 东乡族自治县| 海南省| 瑞昌市| 眉山市| 泉州市| 顺平县| 潜山县| 方山县| 桐乡市| 犍为县| 蓬安县| 岳池县| 日土县| 安化县| 邻水| 治多县| 扎鲁特旗| 竹山县| 临沧市| 合江县| 繁昌县| 蒲江县| 沾化县| 唐河县| 浑源县|