CONFD+ETCD Complete automatic detection of the backend server

Source: Internet
Author: User

We use the front-end forwarding here is Haproxy, using LVS or nginx can essentially change the configuration file

Create a journal file for Haproxy first

Mkdir-p/var/log/haproxy

Touch Haproxy.log

Open Rsyslog's Haproxy journaling feature to add:

$ModLoad imudp

$UDPServerRun 514

Added after #save boot message aslo to Boot.log

local0.*/var/log/haproxy/haproxy.log

Modify the/etc/sysconfig/rsyslog file to modify the syslogd_options= "" to:

Syslogd_options= "-r-m 0-c 2"

Finally, add the/etc/haproxy/haproxy.cfg file

Log 127.0.0.1 Local0

Finally, restart the Rsyslog and Haproxy services to record the diary.


Here is a complete example of Haproxy:

Global

Maxconn 51200

Chroot/var/lib/haproxy

UID 99

GID 99

Daemon

Nbproc 1

Pidfile/var/run/haproxy.pid

Log 127.0.0.1 Local0

Defaults

Mode http

Log Global

Option Httplog

Option Redispatch

Option Abortonclose

Timeout Connect 5000ms

Timeout Client 50000ms

Timeout Server 50000ms

Balance Roundrobin

Listen Admin_stats

Bind 0.0.0.0:8888

Stats Refresh 30s

Stats Uri/stats

Stats Realm Haproxy Manager

Stats auth Smecloud:[email protected]

Listen Test2

Bind 172.20.176.34:19000

Server T1 192.168.206.231:80 Check

Server T2 192.168.206.239:80 Check

Start ETCD

Etcd-name etcdserver-peer-addr 127.0.0.1:7001-addr 127.0.0.1:4001-data-dir/data/etcd-peer-bind-addr 0.0.0.0:7001- Bind-addr 0.0.0.0:4001&

Curl-l http://xxxxxxxxx:4001/v2/keys/keynames-XPUT-d value= "Sdadasdad" sets the value of the key

Curl-l Http://xxxxxxxxx:4001/v2/keys/keynames

Curl-l Http://xxxxxxxxx:4001/v2/keys/keynames-XDELETE Delete key

First create two directories/ETC/CONFD/CONF.D and/etc/confd/templates

Create a new haproxy.toml in the CONF.D directory

[Template]

Src= "Haproxy.cfg.tmpl"

Dest = "/etc/haproxy/haproxy.cfg"

Keys = [

"/app/servers",

]

Reload_cmd = "Service Haproxy Reload"

To create a new template in templates:

Global

Maxconn 51200

Chroot/var/lib/haproxy

UID 99

GID 99

Daemon

Nbproc 1

Pidfile/var/run/haproxy.pid

Log 127.0.0.1 Local0

Defaults

Mode http

Log Global

Option Httplog

Option Redispatch

Option Abortonclose

Timeout Connect 5000ms

Timeout Client 50000ms

Timeout Server 50000ms

Balance Roundrobin

Listen Admin_stats

Bind 0.0.0.0:8888

Stats Refresh 30s

Stats Uri/stats

Stats Realm Haproxy Manager

Stats auth Smecloud:[email protected]

Listen Test2

Bind 172.20.176.34:19000

{{range gets '/app/servers/* '}}

server {{base. Key}} {{. Value}} Check

{{End}}

Background start CONFD and confd-verbose-interval 10-node ' 127.0.0.1:4001 '-confdir/etc/confd >/var/log/confd.log &


At this time can etcdctl Set/app/server/dsdas Sdasdad to the ETCD fill the corresponding value when the configuration file will be automatically updated, almost real-time


Just write a script when you start the service in the back-end server and call Etcd to fill in the value API.




Comments:

1 , base
     as path. The alias of the base function that gets the last segment of the path.
{{with Get "/app/servers/prickly_blackwell"}}
    server {{base. Key}} {{. Value}} Check
{{end}}


2. Get
Returns a pair of matched kv, and returns an error if it is not found.
{{with Get '/app/servers/prickly_blackwell '}}
Key: {{. Key}}
Value: {{. Value}}
{{End}}


3, gets
Returns all matching KV and returns an error if not found.
{{range gets '/app/servers/* '}}
{{. Key}} {{. Value}}
{{End}}


4, Getv
Returns a string value that matches the key and returns an error if it is not found.
{{Getv '/app/servers/cocky_morse '}}



5, Getvs
Returns the string value of all matching keys, and returns an error if it is not found.
{{range Getvs '/app/servers/* '}}
Value: {{.}}
{{End}}


6. Split
Splits the input string by splitting the string into an array by the specified delimiter.
{{$url: = Split (Getv "/app/servers/cocky_morse") ":"}}
Host: {{index $url 0}}
Port: {{index $url 1}}


7, LS
Returns all string-type child keys that are not found and returns an error.
{{range ls '/app/servers/'}}
Subkey: {{.}}
{{End}}



8, Lsdir
Returns all the string subdirectories and returns an empty list if they are not found.
{{range lsdir '/app/'}}
SubDir: {{.}}
{{End}}


This article from "East God to a dozen five" blog, declined reprint!

CONFD+ETCD Complete automatic detection of the backend server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.