Automating operations-simple implementation with shell scripts

Source: Internet
Author: User
Tags curl haproxy etcd

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

Related Article

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.