码迷,mamicode.com
首页 > 其他好文 > 详细

consul 使用

时间:2017-10-17 20:06:21      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:consul   nginx   

# 服务端安装:

 

## consul  安装


#### 依赖关系:

```

yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

```


#### 安装consul:

```bash

yum install consul -y

```

#### 启动命令(简单启动):

```bash

consul agent -server -bootstrap -data-dir /tmp/consul

```


#### 查看信息:

```

consul members

```


#### 查看当前agent状态:

```

consul info

```


#### 安装consul web UI:

```bash

unzip consul_0.6.0_web_ui.zip

mkdir /tmp/ui

mv index.html static/ /tmp/ui/

```


#### 启动命令:

``` bash

consul agent -server -bootstrap-expect=1 -data-dir=/tmp/consul -node=web1 -bind=0.0.0.0 -config-dir=/etc/consul.d -client 0.0.0.0 -ui-dir=/tmp/ui/


consul agent -server -bootstrap-expect=1 -data-dir=/tmp/consul -node=one1 -bind=0.0.0.0 -config-dir=/etc/consul.d -client 0.0.0.0 -ui-dir=/tmp/ui/



consul agent -server -bootstrap-expect=1 -data-dir=/tmp/consul -client 0.0.0.0 -bind=192.168.100.123 -ui-dir=/tmp/ui/ -node=server01 -dc=upstream


作者:cooper_zh

链接:http://www.jianshu.com/p/35b03c82f9fd

來源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

```


#### 命令行添加 机器:

```bash

curl  -X PUT http://10.19.50.111:8500/v1/kv/upstreams/test/10.19.168.73:8000

```

#### 命令行查询注册的服务:

```

curl http://localhost:8500/v1/catalog/service/web


 curl -s http://localhost:8500/v1/catalog/service/consul


 curl -s http://localhost:8500/v1/catalog/node/one1

```

#### 命令行查看键值对信息:

```bash

curl http://localhost:8500/v1/kv/?recurse

```


**** 



# 客户端安装:


## nginx +  upsync 安装:


####  下载并解压nginx-upsync:

```bash

wget https://github.com/weibocom/nginx-upsync-module/archive/master.zip

unzip master.zip

```


#### 创建upsync需要的目录:

```BASH

mkdir -p /data/nginx/conf/servers/

chmod 777 -R /data/nginx/conf/servers/


```


#### 安装nginx  (最后一个选项很重要):

```bash

wget http://nginx.org/download/nginx-1.11.5.tar.gz

groupadd nginx

useradd -g nginx -s /sbin/nologin nginx

mkdir -p /var/tmp/nginx/client/

mkdir -p /data/nginx


tar -zxvf nginx-1.11.5.tar.gzs

./configure --prefix=/data/nginx  \

--user=nginx --group=nginx \

--with-http_ssl_module \

--with-http_flv_module   --with-http_stub_status_module  \

--with-http_gzip_static_module --with-http_realip_module  \

--http-client-body-temp-path=/var/tmp/nginx/client/  \

--http-proxy-temp-path=/var/tmp/nginx/proxy/  \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi  \

--http-scgi-temp-path=/var/tmp/nginx/scgi \

--with-pcre  \

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

--add-module=../nginx-upsync-module-master

```


#### nginx 配置文件:

```bash


user  nobody;

worker_processes  1;


#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;


#pid        logs/nginx.pid;



events {

    worker_connections  1024;

}



http {

    include       mime.types;

    default_type  application/octet-stream;


    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

                      ‘$status $body_bytes_sent "$http_referer" ‘

                      ‘"$http_user_agent" "$http_x_forwarded_for"‘

               ‘$upstream_addr $upstream_status $upstream_response_time $request_time‘;


    access_log  logs/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

    keepalive_timeout  65;

    

    #gzip  on;

    #

    #vhost_traffic_status_zone;

    #proxy_cache_path /tmp/cache_backend keys_zone=cache_backend:10m;


    upstream test {

        server 127.0.0.1:11111;

        upsync 10.19.50.111:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;

        upsync_dump_path /data/nginx/conf/servers/servers_test.conf;

        #server 192.168.77.140:8080 backup;

    }


    upstream bar {

        server 192.168.77.139:80 weight=1 fail_timeout=10 max_fails=3;

    }



    server {

        listen 80;


        location = / {

        proxy_pass http://test;

          proxy_set_header  Host  $host;

          proxy_set_header  X-Real-IP  $remote_addr;

          proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;

          add_header    real $upstream_addr;

        }


        location ~ /Content|Scripts/ {

          proxy_pass http://test;

          proxy_set_header  Host  $host;

          proxy_set_header  X-Real-IP  $remote_addr;

          proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;

        } 

        

        location = /bar {

            proxy_pass http://bar;

        }   

        

        location = /upstream_show {

            upstream_show;

        }   

        

        location = /upstream_status {

            stub_status on;

            access_log off;

        }   

    }   

}   



```


***** 










































本文出自 “风满楼” 博客,谢绝转载!

consul 使用

标签:consul   nginx   

原文地址:http://zhenxing.blog.51cto.com/728846/1973202

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!