Automatic expansion based on ETCD plus Saltstack

Source: Internet
Author: User
Tags haproxy etcd saltstack

[[email protected] ~]# Vim/etc/salt/master =============> at the bottom of the configuration file, add the following content

Etcd_pillar_config:

etcd.host:10.0.0.7

etcd.port:4001


Ext_pillar:

-Etcd:etcd_pillar_config root=/salt/haproxy/


[Email protected] ~]#/etc/init.d/salt-master restart

Stopping salt-master daemon: [OK]

Starting Salt-master daemon: [OK]



Set a key here:

[Email protected] ~]# curl-s http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/web-node1-XPUT-d Value= "10.0.0.7:8080" | Python-m Json.tool

{

"Action": "Set",

"Node": {

"Createdindex": 15,

"Key": "/salt/haproxy/backend_www_oldboyedu_com/web-node1",

"Modifiedindex": 15,

"Value": "10.0.0.7:8080"

}

}


Get key:

[[email protected] ~]# Salt ' * ' Pillar.items

Linux-node1.example.com:

----------

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Linux-node2.example.com:

----------

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Not available here:

To view logs:

[Email protected] ~]# Tailf/var/log/salt/master

Commandexecutionerror: (Unable to import ETCD, module most likely not installed) cannot import ETCD, need to install a dependency package


[[email protected] ~]# Yum install python-pip-y need to be installed Python-pip


[[Email protected] ~]# pip install PYTHON-ETCD install ETCD software


[[email protected] ~]# Salt ' * ' Pillar.items

Linux-node1.example.com:

----------

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Linux-node2.example.com:

----------

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Here you get the value:

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080


[Email protected] ~]# vim/srv/salt/prod/cluster/files/haproxy-outside.cfg

At the bottom of the configuration file, add:

{% for web,web_ip in Pillar.backend_www_oldboyedu_com.iteritems ()-%}

server {{web}} {{web_ip}} Check inter 15 rise fall

{% ENDFOR%}


[[email protected] ~]# Vim/srv/salt/prod/cluster/haproxy-outside.sls ====================> designated as Jinja template in the file

-Template:jinja


After modifying, execute the Advanced module:

[[email protected] ~]# Salt ' * ' state.highstate


[[email protected] ~]# Salt ' * ' Pillar.items

Linux-node2.example.com:

----------

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Linux-node1.example.com:

----------

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Two nodes have been obtained the key value:

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080


Example:

[Email protected] ~]# curl-s http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/web-node2-XPUT-d Value= "10.0.0.7:8080" | Python-m Json.tool

{

"Action": "Set",

"Node": {

"Createdindex": 16,

"Key": "/salt/haproxy/backend_www_oldboyedu_com/web-node2",

"Modifiedindex": 16,

"Value": "10.0.0.7:8080"

}

}

[Email protected] ~]# curl-s http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/web-node3-XPUT-d Value= "10.0.0.7:8080" | Python-m Json.tool

{

"Action": "Set",

"Node": {

"Createdindex": 17,

"Key": "/salt/haproxy/backend_www_oldboyedu_com/web-node3",

"Modifiedindex": 17,

"Value": "10.0.0.7:8080"

}

}

[Email protected] ~]# curl-s http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/web-node4-XPUT-d Value= "10.0.0.7:8080" | Python-m Json.tool

{

"Action": "Set",

"Node": {

"Createdindex": 18,

"Key": "/salt/haproxy/backend_www_oldboyedu_com/web-node4",

"Modifiedindex": 18,

"Value": "10.0.0.7:8080"

}

}

[Email protected] ~]# curl-s http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/web-node5-XPUT-d Value= "10.0.0.7:8080" | Python-m Json.tool

{

"Action": "Set",

"Node": {

"Createdindex": 19,

"Key": "/salt/haproxy/backend_www_oldboyedu_com/web-node5",

"Modifiedindex": 19,

"Value": "10.0.0.7:8080"

}

}

[Email protected] ~]# curl-s Http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/web-node55-XPUT- D value= "10.0.0.7:8080" | Python-m Json.tool

{

"Action": "Set",

"Node": {

"Createdindex": 34,

"Key": "/salt/haproxy/backend_www_oldboyedu_com/web-node55",

"Modifiedindex": 34,

"Value": "10.0.0.7:8080"

}

}


[[email protected] ~]# Salt ' * ' state.highstate =================> perform advanced status


Review the obtained values again:

[[email protected] ~]# Salt ' * ' Pillar.items

Linux-node1.example.com:

----------

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080

Web-node2:

10.0.0.7:8080

WEB-NODE3:

10.0.0.7:8080

WEB-NODE4:

10.0.0.7:8080

WEB-NODE5:

10.0.0.7:8080

Web-node55:

10.0.0.7:8080

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7

Linux-node2.example.com:

----------

Backend_www_oldboyedu_com:

----------

Web-node1:

10.0.0.7:8080

Web-node2:

10.0.0.7:8080

WEB-NODE3:

10.0.0.7:8080

WEB-NODE4:

10.0.0.7:8080

WEB-NODE5:

10.0.0.7:8080

Web-node55:

10.0.0.7:8080

Zabbix-agent:

----------

Zabbix_server:

10.0.0.7


At this point in the browser to see that n nodes have been added

Old boy Website: http://www.etiantian.org

qq:406564728

Welcome to Exchange

This article is from the "Linux" blog, so be sure to keep this source http://chenjisong.blog.51cto.com/7858025/1714340

Automatic expansion based on ETCD plus Saltstack

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.