Review:
1 Installing ETCD
[[Email protected] ~]# pip install PYTHON-ETCD install ETCD software
2 Modify Salt-master configuration file, add configuration, and restart Salt-master
[Email protected] ~]# 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/
3 Adding nodes
[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
4 Change Haproxy-outside.sls file add Jinja template flag
[Email protected] ~]# Vim/srv/salt/prod/cluster/haproxy-outside.sls
-Template:jinja
5 Modifying a configuration file
[Email protected] ~]# 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 15 rise fall
{% ENDFOR%}
The script implementation automatically adds the machine:
[email protected] ~]# cat auto.sh
#!/bin/bash
Main_add_host=$1
Create_host () {
echo "Create host OK"
}
Deploy_service () {
#salt ' linux-node2.example.com ' State.sls nginx.install env=prod
add_host_port= "8080"
}
Deploy_code () {
echo "Deploy code OK"
}
Service_check () {
status=$ (curl-s--head/http "$ADD _host": "$ADD _host_port"/| grep ' OK ')
If [-N "$STATUS"];then
echo "OK"
Else
echo "Not OK"
Exit
Fi
}
Etcd_key () {
Add_host=$1
Curl http://10.0.0.7:2379/v2/keys/salt/haproxy/backend_www_oldboyedu_com/$ADD _host-xput-d value= "10.0.0.8:${add_ Host_port} "
}
Sync_state () {
Salt ' linux-node1.example.com ' State.sls cluster.haproxy-outside env=prod
}
Main () {
Create_host;
Deploy_service;
Deploy_code;
Etcd_key $MAIN _add_host;
Sync_state;
}
Main $
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/1714341
Automating operations-simple implementation with shell scripts