zoukankan      html  css  js  c++  java
  • 京东云上centos8.2 安装 consul1.11.1

    做个笔记下

    --

    前言

    部分内容有参考网友的,但是地址不记得了!

    安装内容基本参考官网的和上一个网友的

    官网地址:

    https://www.consul.io/downloads

    以下是使用root方式安装的。

    如果是consul,则建议先创建consul用户,再以consul登录

    安装

    sudo yum install -y yum-utils
    sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
    sudo yum -y install consul
    注意:root用户,省略sudu

    配置


    启动服务配置-修改启动文件consul.service
    [Unit]
    Description="HashiCorp Consul - A service mesh solution"
    Documentation=https://www.consul.io/
    Requires=network-online.target
    After=network-online.target
    ConditionFileNotEmpty=/etc/consul.d/consul.hcl

    [Service]
    EnvironmentFile=/etc/consul.d/consul.env
    User=root
    Group=root
    ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/
    #不持久化 -dev
    #ExecStart=/usr/bin/consul agent -dev  -config-dir=/etc/consul.d/
    ExecReload=/bin/kill --signal HUP $MAINPID
    KillMode=process
    KillSignal=SIGTERM
    Restart=on-failure
    LimitNOFILE=65536

    [Install]
    WantedBy=multi-user.target

    --

    consul参数配置

    具体可以看 https://www.consul.io/docs/agent/options

    可以命令行,可以是json,hcl之类的,主要是为了兼容老习惯


    添加额外的参数文件(在/etc/consul.d/下添加sever.json,注意只要是json结尾即可,叫啥无所谓)
    {
      "datacenter": "dc1",
      "data_dir": "/data/data/consul",
      "log_level": "INFO",
      "node_name": "foobar",
      "server": true,
      "ports": {
            "http": 8500,
            "https": -1,
            "dns": 8600,
            "grpc": -1,
            "serf_lan": 8001,
            "serf_wan": 8002,
            "server": 8003
        }  
    }

    另外,这个版本中,有个默认的 /etc/consul.d/consul.hcl
    修改几个参数:

    # 任意客户端都可以链接--2021
    client_addr = "0.0.0.0"
    # 启动内置ui-web管理--2021dd
    ui_config{
      enabled = true
    }
    bind_addr = "0.0.0.0"
    advertise_addr = "127.0.0.1"

    # 指定只有一个节点,否则总是会提示 No cluster leader
    bootstrap_expect=1

    这些配置的大体意思就是 使用server模式(单节点)启动,web端口为8500,任意客户端可以连接!

    最后看下启动后的界面

     看下管理界面

    最后,能不能用,还得通过springboot来验证:https://www.cnblogs.com/MrSi/p/13961890.html

    --- 根据以上的提示

    Springboot工程验证

    1.使用sts创建一个springboot工程,pom配置如下

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.6.2</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>org.lzf</groupId>
        <artifactId>vehicle-base</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>consul-test</name>
        <description>Demo project for Spring Boot</description>
        <properties>
            <java.version>1.8</java.version>
            <spring-cloud.version>2021.0.0</spring-cloud.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-bootstrap</artifactId>
            </dependency>
            <!--  添加热部署 -->
            <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-devtools</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-config</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-discovery</artifactId>
            </dependency>
             <!-- 引入 Spring Boot Actuator 组件,因为需要通过它提供健康检查的接口给 Consul -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    2.创建一个application.properties

    #开发-热部署
    spring.devtools.restart.enabled=true
    server.port=8762
    # Spring
    spring.application.name=customer-service
    
    #actuator监控信息
    info.app.name=应用服务器-8762
    info.company.name=org.lzf
    info.build.artifactId=cloud-customer
    info.build.version=1.0-SNAPSHOT
    #其余省略

    3.创建一个boostrap.yml

    spring:
      cloud:
        consul:
          config:
            enabled: true
            format: YAML
            data-key: data
            watch:
              enabled: true
            prefix: config
          discovery:
            enabled: true
            heartbeat:
              enabled: true
            health-check-interval: 5s
            health-check-path: /actuator/health
            instance-id: customer-service.8762
            prefer-ip-address: true
          enabled: true
          host: 114.67.246.199
          port: 8500    

    4.启动类记得加注解 @EnableDiscoveryClient

    最后检测是ok的:

  • 相关阅读:
    github创建repo,本地导入git项目到github
    成功的GIT开发分支模型和策略
    示例可重用的web component方式组织angular应用模块
    git deployment strategy
    如何在linux中从源代码编译安装nodejs?
    some resource favor
    学而习之,成就学习
    C# 去掉代码前边空格(格式化代码)
    mvc重定向
    mvc cshtml 中赋值
  • 原文地址:https://www.cnblogs.com/lzfhope/p/15721004.html
Copyright © 2011-2022 走看看