标签:自动化扩容 etcd
[root@linux-node1 ~]# vim /etc/salt/master =============>在配置文件最底部加上如下内容
etcd_pillar_config:
etcd.host: 10.0.0.7
etcd.port: 4001
ext_pillar:
- etcd: etcd_pillar_config root=/salt/haproxy/
[root@linux-node1 ~]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [确定]
Starting salt-master daemon: [确定]
此处设置一个key:
[root@linux-node1 ~]# 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"
}
}
获取key:
[root@linux-node1 ~]# 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
此处没有获取到:
查看日志:
[root@linux-node1 ~]# tailf /var/log/salt/master
CommandExecutionError: (unable to import etcd, module most likely not installed) 不能导入etcd,需要安装一个依赖包
[root@linux-node1 ~]# yum install python-pip -y 需要安装python-pip
[root@linux-node1 ~]# pip install python-etcd 安装etcd软件
[root@linux-node1 ~]# 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
此处获取到值了:
backend_www_oldboyedu_com:
----------
web-node1:
10.0.0.7:8080
[root@linux-node1 ~]# vim /srv/salt/prod/cluster/files/haproxy-outside.cfg
配置文件最底部添加:
{% for web,web_ip in pillar.backend_www_oldboyedu_com.iteritems() -%}
server {{ web }} {{ web_ip }} check inter 2000 rise 30 fall 15
{% endfor %}
[root@linux-node1 ~]# vim /srv/salt/prod/cluster/haproxy-outside.sls ====================>在文件里面指定为jinja模版
- template: jinja
修改之后执行高级模块:
[root@linux-node1 ~]# salt ‘*‘ state.highstate
[root@linux-node1 ~]# 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
两个节点都获取到了key value:
backend_www_oldboyedu_com:
----------
web-node1:
10.0.0.7:8080
例子:
[root@linux-node1 ~]# 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"
}
}
[root@linux-node1 ~]# 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"
}
}
[root@linux-node1 ~]# 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"
}
}
[root@linux-node1 ~]# 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"
}
}
[root@linux-node1 ~]# 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"
}
}
[root@linux-node1 ~]# salt ‘*‘ state.highstate =================>执行高级状态
再次查看获取的数值:
[root@linux-node1 ~]# 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
此时在浏览器中查看已添加了N个节点
老男孩网址:http://www.etiantian.org
qq:406564728
欢迎交流
本文出自 “linux” 博客,请务必保留此出处http://chenjisong.blog.51cto.com/7858025/1714340
标签:自动化扩容 etcd
原文地址:http://chenjisong.blog.51cto.com/7858025/1714340