一健推送apache

[root@server1 minions]# cd /etc/salt/

[root@server1 salt]# vim master

[root@server1 salt]# mkdir /srv/salt

[root@server1 salt]# cd /srv/salt/

[root@server1 salt]# mkdir apache

[root@server1 salt]# cd  apache/

[root@server1 apache]# vim install.sls

apache-install:

pkg.installed:

- pkgs:

- httpd

- php

file.managed:

- name: /var/www/html/index.php

- source: salt://apache/files/index.php

- mode: 644

- user: root

- group: root

[root@server1 httpd]# salt server2 state.sls apache.install

[root@server1 apache]# vim service.sls

include:

- apache.install

apache-service:

file.managed:

- name: /etc/httpd/conf/httpd.conf

- source: salt://apache/files/httpd.conf

service.running:

- name: httpd

- enable: True

- reload: True

- watch:

- file: apache-service

[root@server1 apache]# cd  files/

[root@server1 files]# ls

httpd.conf(从server2(apache端)scp过来)  index.php

[root@server1 apache]# salt server2 state.sls apache.service

一健部署nginx

[root@server1 salt]# mkdir nginx

[root@server1 salt]# cd nginx

[root@server1 nginx]# mkdir files

[root@server1 nginx]# cd files

[root@server1 files]# ls

nginx-1.14.0.tar.gz    nginx(可以从网上找一个启动脚本) nginx.conf(从server3scp)

[root@server1 files]# cd ..

[root@server1 nginx]# vim install.sls

include:

- pkgs.make

nginx-install:

pkg.installed:

- pkgs:

- gcc

- pcre-devel

- openssl-devel

file.managed:

- name: /mnt/nginx-1.14.0.tar.gz

- source: salt://nginx/files/nginx-1.14.0.tar.gz

cmd.run:

- name: cd /mnt && tar zxf nginx-1.14.0.tar.gz && cd nginx-1.14.0 && sed -i.bak 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && sed -i.bak 's/#define NGINX_VER          "nginx\/" NGINX_VERSION/#define NGINX_VER          "nginx"/g' src/core/nginx.h && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio &> /dev/null && make &> /dev/null && make install &> /dev/null

- creates: /usr/local/nginx

[root@server1 nginx]# salt server3 state.sls nginx.install

[root@server1 nginx]# vim service.sls

include:

- nginx.install

/usr/local/nginx/conf/nginx.conf:

file.managed:

- source: salt://nginx/files/nginx.conf

nginx-service:

file.managed:

- name: /etc/init.d/nginx

- source: salt://nginx/files/nginx

- mode: 755

service.running:

- name: nginx

- enable: True

- reload: True

- watch:

- file: /usr/local/nginx/conf/nginx.conf

[root@server1 nginx]# salt server3 state.sls nginx.service

[root@server1 nginx]# cd ..

[root@server1 salt]# mkdir pkgs

[root@server1 salt]# cd pkgs/

[root@server1 pkgs]# vim make.sls

gcc:

pkg.installed:

- pkgs:

- gcc

- pcre-devel

- openssl-devel

一健推送haproxy,实现负载均衡

[root@server1 salt]# mkdir haproxy

[root@server1 haproxy]# mkdir files

[root@server1 haproxy]# cd files/

[root@server1 files]# ls

haproxy-1.6.11.tar.gz haproxy.cfg haproxy.init

[root@server1 files]# cd ..

[root@server1 haproxy]# cd ..

[root@server1 salt]# mkdir users

[root@server1 salt]# cd users/

[root@server1 users]# vim haproxy.sls

haproxy-group:

group.present:

- name: haproxy

- gid: 200

haproxy:

user.present:

- uid: 200

- gid: 200

- home: /usr/local/haproxy

- createhome: False

- shell: /sbin/nologin

[root@server1 salt]# cd /srv/salt/haproxy/

[root@server1 haproxy]# vim install.sls

include:

- pkgs.make

- users.haproxy

haproxy-install:

file.managed:

- name: /mnt/haproxy-1.6.11.tar.gz

- source: salt://haproxy/files/haproxy-1.6.11.tar.gz

cmd.run:

- name: cd /mnt && tar zxf haproxy-1.6.11.tar.gz && cd haproxy-1.6.11 && make TARGET=linux2628 UES_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/usr/local/haproxy && make TARGET=linux2628 UES_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/usr/local/haproxy install

- creates: usr/local/haproxy

/etc/haproxy:

file.directory:

- mode: 755

/usr/sbin/haproxy:

file.symlink:

- target: /usr/local/haproxy/sbin/haproxy

[root@server1 haproxy]# salt server1 state.sls haproxy.install

没有报错即成功

[root@server1 mnt]# cd haproxy-1.6.11/examples

[root@server1 examples]# cp haproxy.init /srv/salt/haproxy/files

[root@server1 examples]# cp content-sw-sample.cfg /srv/salt/haproxy/files

[root@server1 haproxy]# cd /srv/salt/haproxy/files/

[root@server1 files]# ls

[root@server1 files]# mv content-sw-sample.cfg haproxy.cfg

[root@server1 files]# vim haproxy.cfg

global

maxconn         10000

stats socket    /var/run/haproxy.stat mode 600 level admin

log             127.0.0.1 local0

uid             200

gid             200

chroot          /var/empty

daemon

defaults

mode            http

log             global

option          httplog

option          dontlognull

monitor-uri     /monitoruri

maxconn         8000

timeout client  30s

stats uri       /admin/stats

retries         2

option redispatch

timeout connect 5s

timeout server  5s

timeout queue   30s

# The public 'www' address in the DMZ

frontend public

bind            *:80 name clear

#bind            192.168.1.10:443 ssl crt /etc/haproxy/haproxy.pem

#use_backend     static if { hdr_beg(host) -i img }

#use_backend     static if { path_beg /img /css   }

default_backend static

# The static backend backend for 'Host: img', /img and /css.

backend static

balance         roundrobin

#option httpchk  HEAD /favicon.ico

server          statsrv1 172.25.8.2:80 check inter 1000

server          statsrv2 172.25.8.3:80 check inter 1000

[root@server1 files]# cd ..

[root@server1 haproxy]# vim service.sls

include:

- haproxy.install

/etc/haproxy/haproxy.cfg:

file.managed:

- source: salt://haproxy/files/haproxy.cfg

haproxy-service:

file.managed:

- name: /etc/init.d/haproxy

- source: salt://haproxy/files/haproxy.init

- mode: 755

service.running:

- name: haproxy

- enable: True

- reload: True

- watch:

- file: /etc/haproxy/haproxy.cfg

[root@server1 haproxy]# salt server1 state.sls haproxy.service

无报错即可

一键全推送

[root@server1 haproxy]# cd ..

[root@server1 salt]# vim top.sls

base:

'server2':

- apache.service

'server3':

- nginx.service

'server1':

- haproxy.service

ot@server1 salt]# salt '*' state.highstate

一键推送高可用

[root@server1 salt]# vim /etc/salt/master

取消注释

pillar_roots:

base:

- /srv/pillar

[root@server1 salt]# /etc/init.d/salt-master restart

[root@server1 srv]# cd ..

[root@server1 srv]# mkdir pillar

[root@server1 srv]# cd pillar/

[root@server1 pillar]# vim top.sls

base:

'*':

- web.install

- keepalived.install

[root@server1 pillar]# cd /srv/salt/apache/

[root@server1 apache]# vim service.sls

include:

- apache.install

apache-service:

file.managed:

- name: /etc/httpd/conf/httpd.conf

- source: salt://apache/files/httpd.conf

- template: jinja

- context:

port: {{ pillar['port'] }}

bind: {{ pillar['bind'] }}

service.running:

- name: httpd

- enable: True

- reload: True

- watch:

- file: apache-service

[root@server1 apache]# vim /srv/pillar/web/install.sls (web目录自己创建)

{% if grains['fqdn'] == 'server2' %}

webserver: httpd

bind: 172.25.8.2

port: 80

{% elif grains['fqdn'] == 'server3' %}

webserver: nginx

{% elif grains['fqdn'] == 'server1' %}

webserver: haproxy

{% endif %}

[root@server1 apache]# vim files/httpd.conf

Listen {{ bind }}:{{ port }}

推送keepalived

server4:

[root@server1 apache]# cd ..

[root@server1 salt]# mkdir keepalived

[root@server1 salt]# cd keepalived/

[root@server1 keepalived]# mkdir files

[root@server1 keepalived]# cd files/

[root@server1 files]# ls

keepalived-2.0.6.tar.gz

[root@server1 files]# cd ..

[root@server1 keepalived]# vim install.sls

include:

- pkgs.make

kp-install:

file.managed:

- name: /mnt/keepalived-2.0.6.tar.gz

- source: salt://keepalived/files/keepalived-2.0.6.tar.gz

cmd.run:

- name: cd /mnt && tar zxf keepalived-2.0.6.tar.gz && cd keepalived-2.0.6 && ./configure --prefix=/usr/local/keepalived --with-init=SYSV &> /dev/null && make &> /dev/null && make install &> /dev/null

- creates: /usr/local/keepalived

tu

[root@server1 keepalived]# salt server4 state.sls keepalived.install

[root@server1 keepalived]# cd files/

[root@server1 files]# ls

keepalived  keepalived-2.0.6.tar.gz  keepalived.conf

[root@server1 files]# cd ..

vim service.sls

[root@server1 keepalived]# cd files/

[root@server1 files]# vim keepalived.conf

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

vrrp_skip_check_adv_addr

#vrrp_strict

vrrp_garp_interval 0

vrrp_gna_interval 0

}

vrrp_instance VI_1 {

state {{ STATE }}

interface eth0

virtual_router_id {{ VRID }}

priority {{ PRIORITY }}

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

172.25.8.100

}

}

[root@server1 salt]# cd ..

[root@server1 keepalived]# vim service.sls

[root@server1 keepalived]# cd ..

[root@server1 salt]# cd ..

[root@server1 srv]# cd pillar/

[root@server1 pillar]# mkdir keepalived

[root@server1 pillar]# cd keepalived/

[root@server1 keepalived]# vim install.sls

{% if grains['fqdn'] == 'server1' %}

state: MASTER

vrid: 88

priority: 100

{% elif grains['fqdn'] == 'server4' %}

state:  MASTER

vrid: 88

priority: 1

{% endif %}

tu

[root@server1 keepalived]# cd ..

[root@server1 salt]# vim top.sls

base:

'server4':

- haproxy.service

- keepalived.service

'server2':

- apache.service

'server3':

- nginx.service

'server1':

- haproxy.service

- keepalived.service

[root@server1 salt]# salt '*' state.highstate

saltstack一键部署高可用的更多相关文章

  1. 基于saltstack自动化部署高可用kubernetes集群

    SaltStack自动化部署HA-Kubernetes 本项目在GitHub上,会不定期更新,大家也可以提交ISSUE,地址为:https://github.com/skymyyang/salt-k8 ...

  2. kubernetes实战(二十):k8s一键部署高可用Prometheus并实现邮件告警

    1.基本概念 本次部署使用的是CoreOS的prometheus-operator. 本次部署包含监控etcd集群. 本次部署适用于二进制和kubeadm安装方式. 本次部署适用于k8s v1.10版 ...

  3. kubernetes kubeadm部署高可用集群

    k8s kubeadm部署高可用集群 kubeadm是官方推出的部署工具,旨在降低kubernetes使用门槛与提高集群部署的便捷性. 同时越来越多的官方文档,围绕kubernetes容器化部署为环境 ...

  4. kubernetes部署高可用Harbor

    前言 本文Harbor高可用依照Harbor官网部署,主要思路如下,大家可以根据具体情况选择搭建. 部署Postgresql高可用集群.(本文选用Stolon进行管理,请查看文章<kuberne ...

  5. k8s部署高可用Ingress

    部署高可用Ingress 官网地址https://kubernetes.github.io/ingress-nginx/deploy/ 获取ingress的编排文件 wget https://raw. ...

  6. 附012.Kubeadm部署高可用Kubernetes

    一 kubeadm介绍 1.1 概述 参考<附003.Kubeadm部署Kubernetes>. 1.2 kubeadm功能 参考<附003.Kubeadm部署Kubernetes& ...

  7. Quartz学习笔记:集群部署&高可用

    Quartz学习笔记:集群部署&高可用 集群部署 一个Quartz集群中的每个节点是一个独立的Quartz应用,它又管理着其他的节点.这就意味着你必须对每个节点分别启动或停止.Quartz集群 ...

  8. 企业运维实践-还不会部署高可用的kubernetes集群?使用kubeadm方式安装高可用k8s集群v1.23.7

    关注「WeiyiGeek」公众号 设为「特别关注」每天带你玩转网络安全运维.应用开发.物联网IOT学习! 希望各位看友[关注.点赞.评论.收藏.投币],助力每一个梦想. 文章目录: 0x00 前言简述 ...

  9. SaltStack一键部署负载均衡和高可用

    一.负载均衡的部署 server1    haproxy (调度器) server2    apache server3    nginx 1)在server1上首先安装salt-minion服务.并 ...

随机推荐

  1. MyBatis总结三:使用动态代理实现dao接口

    由于我们上一篇实现MyBatis的增删改查的接口实现类的方法都是通过sqlsession调用方法,参数也都类似,所以我们使用动态代理的方式来完善这一点 MyBatis动态代理生成dao的步骤: 编写数 ...

  2. Visual Studio Command Prompt 工具配置方法

    有时候,我们无法找到Visual Studio Command Prompt,需要手动配置 打开 Visual studio2015,选择  "工具"—>"外部工具 ...

  3. 把文档转化为PDF再用PS处理PDF

    最近工作中遇到类似下面这样的一个文档. 文档当前设置的是A4 横版打印,可以明显的看到打印的分界线,这样直接打印出来,是没有下面那行“bbbbbbbbbbbbbbbbbb”的,怎么办?可以通过 页面布 ...

  4. WOJ 41 约数统计

    只会写60分算法QuQ 考虑到一个数$x$大于$\sqrt{x}$的质因数最多只有一个,我们可以筛出小于$\sqrt{r}$范围内的所有质因数然后直接用这些取分解质因数. 最后扫一遍发现还没有分解完的 ...

  5. Mysql--连接查询

    内连接查询 意义:找到表和表之间的关系或者是桥梁.连接查询是查询两个或者两个以上的表时使用的. JOIN|CROSS JOIN| INNER JOIN    通过ON  连接条件(这三个方式都行)一般 ...

  6. C# 中窗口AutoScaleMode属性

    C# 窗体中有一个AutoScaleMode 这个属性,我们大家可能用的比较少. 它的作用是:当屏幕分辨率或字体发生改变时,窗体和控件是如何发生变化的.

  7. C#和.NET Framework简介

    注:本文大部分借鉴了<果壳中的C#5.0权威指南>,小编也想根据这本书好好梳理一下C#. 序言:C#是一种通用的类型安全且面向对象的编程语言.这种语言的目标是提高程序员的生产力,为此,需要 ...

  8. android studio中使用x5 webview来读写cookies的问题

    本人新手,刚接触AS也没有多久,记录下两个问题. 1. 怎么在android studio中写入cookies 把写入cookies的动作放在了主界面的onCreate事件中了,看了腾讯的说明,说是要 ...

  9. Puppeteer入门初探

    本文来自网易云社区 作者:唐钊 最近在看 node 爬虫相关的一些东西,我记得还是很久以前常用的 node 爬虫工具还是 superagengt+cherrio,他们的思路是通过发起 http 请求然 ...

  10. meta标签使用

    META标签分两大部分:HTTP标题信息(HTTP-EQUIV)和页面描述信息(NAME). ★HTTP-EQUIV HTTP-EQUIV类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助 ...