• consul 集群搭建


    consul 集群搭建

    一、三台机器

    基本信息

    192.168.80.128
    192.168.80.129
    192.168.80.130
    

    二、下载consul

    wget https://releases.hashicorp.com/consul/1.9.5/consul_1.9.5_linux_amd64.zip
    # 解压出来就是一个二进制文件
    

    三、三台机器分别创建目录和文件

    mkdir /opt/consul/bin/
    # 拷贝解压的二进制文件至 /opt/consul/bin/
    mkdir /opt/consul/data/
    mkdir /opt/consul/logs/
    mkdir /opt/consul/conf/
    

    四、配置

    192.168.80.128 机器配置 consul.json

    {
        "datacenter": "djx-test",           
        "data_dir": "/opt/consul/data",     
        "log_level": "INFO",                
        "node_name": "192.168.80.128",        
        "server": true,                     
        "ui": true,                         
        "bootstrap_expect": 1,              
        "bind_addr": "192.168.80.128",        
        "client_addr": "0.0.0.0",           
        "retry_join": ["192.168.80.129","192.168.80.130"],  
        "retry_interval": "3s",             
        "raft_protocol": 3,                 
        "enable_debug": false,              
        "rejoin_after_leave": true,       
        "enable_syslog": false,
        "telemetry": {
          "statsite_address": "127.0.0.1:9125"
        } 
    }
    

    192.168.80.129 配置 consul.json

    {
        "datacenter": "djx-test",           
        "data_dir": "/opt/consul/data",     
        "log_level": "INFO",                
        "node_name": "192.168.80.129",        
        "server": true,                     
        "ui": true,                         
        "bootstrap_expect": 1,              
        "bind_addr": "192.168.80.129",        
        "client_addr": "0.0.0.0",           
        "retry_join": ["192.168.80.128","192.168.80.130"],  
        "retry_interval": "3s",             
        "raft_protocol": 3,                 
        "enable_debug": false,              
        "rejoin_after_leave": true,       
        "enable_syslog": false,
        "telemetry": {
          "statsite_address": "127.0.0.1:9125"
        } 
    }
    

    192.168.80.130 配置 consul.json

    {
        "datacenter": "djx-test",           
        "data_dir": "/opt/consul/data",     
        "log_level": "INFO",                
        "node_name": "192.168.80.130",        
        "server": true,                     
        "ui": true,                         
        "bootstrap_expect": 1,              
        "bind_addr": "192.168.80.130",        
        "client_addr": "0.0.0.0",           
        "retry_join": ["192.168.80.128","192.168.80.129"],  
        "retry_interval": "3s",             
        "raft_protocol": 3,                 
        "enable_debug": false,              
        "rejoin_after_leave": true,       
        "enable_syslog": false,
        "telemetry": {
          "statsite_address": "127.0.0.1:9125"
        } 
    }
    

    五、三台机器都配置成系统服务

    /usr/lib/systemd/system/consul.service

    [Unit]
    Description=consul
    After=network.target
    
    [Service]
    LimitNOFILE=32768
    Type=simple
    Restart=on-failure
    ExecStart=/opt/consul/bin/consul agent -config-dir /opt/consul/conf/ -http-port=8500 -log-file=/opt/consul/logs/consul.log
    
    [Install]
    WantedBy=multi-user.target
    

    六、启动服务并添加到系统服务

    systemctl start consul
    systemctl enable consul
    

    七、查看集群节点

    consul  members
    
    / # consul  members
    Node                     Address             Status  Type    Build  Protocol  DC     Segment
    192.168.80.130               192.168.80.130:8301     alive   server  1.3.1  2         djx-test  <all>
    192.168.80.129                192.168.80.129:8301     alive   server  1.3.1  2         djx-test  <all>
    192.168.80.128                192.168.80.128:8301     alive   server  1.3.1  2         djx-test <all>
    
    作者:理想三旬
    出处:
    如果觉得文章写得不错,或者帮助到您了,请点个赞,加个关注哦。运维学习交流群:544692191
    本文版权归作者所有,欢迎转载,如果文章有写的不足的地方,或者是写得错误的地方,请你一定要指出,因为这样不光是对我写文章的一种促进,也是一份对后面看此文章的人的责任。谢谢。
  • 相关阅读:
    web移动开发最佳实践之js篇
    ubuntu升级到12.10
    C语言生成随机数
    终于签约了
    这个2012不寻常
    awk练习(实战)
    数据恢复的教训
    职业发展的一些随想
    diy谷蜂Y5刷机包基于官方0207稳定版
    web移动开发最佳实践之html篇
  • 原文地址:https://www.cnblogs.com/operationhome/p/14830677.html
Copyright © 2020-2023  润新知