consul consul-template nginx springboot集成

1 consul安装 

准备目录

mkdir -p /opt/consul/web

 mkdir -p /opt/consul/data

 mkdir -p /opt/consul/conf

 mkdir -p /opt/consul/run/

每个阶段欺服务

consul agent -server -bootstrap -syslog \

    -ui-dir=/opt/consul/web \

    -data-dir=/opt/consul/data \

    -config-dir=/opt/consul/conf \

    -pid-file=/opt/consul/run/consul.pid \

    -client=x.x.x.x \

    -bind=x.x.x.x \

    -node=hostname \

    -disable-host-node-id

组成集群 

consul join --http-addr  x.x.x.x:8500  x.x.x.x  

springboot集成consul

     

        org.springframework.boot 

        spring-boot-actuator 

        1.3.5.RELEASE 

     

     

        org.springframework.cloud 

        spring-cloud-starter-consul-discovery 

     

spring.cloud.consul.discovery.port=${server.port}

spring.cloud.consul.discovery.healthCheckUrl=url/health 

spring.cloud.consul.discovery.healthCheckInterval=10s 


consul-template nginx集成

nginx配置增加

include /usr/local/nginx/consul/*.conf;

nginx.ctmpl 文件

upstream  backend1 {

    {{range service "consul服务名称"}}

    server {{ .Address }}:{{ .Port }};

    {{ end }}

}

server {

    server_name test1.xcar.com.cn;

    location / {

    proxy_pass http://backend1;

    }

}

consul-tempalte命令

nohup  consul-template --consul-addr  x.x.x.x:8500 --template "/usr/local/nginx/consul/nginx.ctmpl:/usr/local/nginx/consul/vhost.conf:/usr/local/nginx/sbin/nginx -s reload" --log-level=info &

你可能感兴趣的:(consul consul-template nginx springboot集成)