Saltstack批量部署apache

实验环境:

192.168.18.128 master

192.168.18.148 web01

192.168.18.145 web02

第一步:分别给三台服务器安装epel源

Master:
[[email protected] ~]# hostnamectl set-hostname master.saltstack.com
[[email protected] ~]# su
[[email protected] ~]# hostname
master.saltstack.com
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# setenforce 0
[[email protected] ~]# vim /etc/hosts
`按大写字母G到末行,按小写字母o转下行插入以下内容`
192.168.18.128 master.saltstack.com
192.168.18.148 web01.saltstack.com
192.168.18.145 web02.saltstack.com
#修改完成后按Esc退出插入模式,输入:wq保存退出
[[email protected] ~]# yum install -y epel-release
Web01:
[[email protected] ~]# hostnamectl set-hostname web01.saltstack.com
[[email protected] ~]# su
[[email protected] ~]# hostname
web01.saltstack.com
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# setenforce 0
[[email protected] ~]# vim /etc/hosts
`按大写字母G到末行,按小写字母o转下行插入以下内容`
192.168.18.128  master.saltstack.com
192.168.18.148  web01.saltstack.com
192.168.18.145  web02.saltstack.com
#修改完成后按Esc退出插入模式,输入:wq保存退出
[[email protected] ~]#  yum install -y epel-release
Web02:
[[email protected] ~]# hostnamectl set-hostname web02.saltstack.com
[[email protected] ~]# su
[[email protected] ~]# hostname
web02.saltstack.com
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# setenforce 0
[[email protected] ~]# vim /etc/hosts
`按大写字母G到末行,按小写字母o转下行插入以下内容`
192.168.18.128  master.saltstack.com
192.168.18.148  web01.saltstack.com
192.168.18.145  web02.saltstack.com
#修改完成后按Esc退出插入模式,输入:wq保存退出
[[email protected] ~]#  yum install -y epel-release

第二步:master服务器的操作

[[email protected] ~]# yum -y install salt-master
[[email protected] ~]# vim /etc/salt/master
15 interface: 192.168.18.128    #15行,删除注释,监听本机地址
215 auto_accept: True           #215行,删除注释,证书认证开启
416 file_roots:
417   base:
418     - /srv/salt             #416-418行,删除注释,saltstack文件根目录位置,目录需要创建
710 nodegroups:
711   group1: ‘web01.saltstack.com‘
712   group2: ‘web02.saltstack.com‘     #710-712行,删除注释,两个节点组服务器的名称
552 pillar_opts: True           #552行,删除注释,开启pillar功能,同步文件功能
529 pillar_roots:
530   base:
531     - /srv/pillar           #529-531行,删除注释,pillar的主目录,需要创建
#修改完成后按Esc退出插入模式,输入:wq保存退出

`查看对主配置文件做的更改`
[[email protected] ~]# cat /etc/salt/master | grep -v ^$ | grep -v ^#
interface: 192.168.18.128
auto_accept: True
file_roots:
  base:
    - /srv/salt
pillar_roots:
  base:
    - /srv/pillar
pillar_opts: True
nodegroups:
  group1: ‘web01.saltstack.com‘
  group2: ‘web02.saltstack.com‘

`创建salt与pillar文件根目录`
[[email protected] ~]# mkdir /srv/salt
[[email protected] ~]# mkdir /srv/pillar
[[email protected] ~]# ls /srv/
pillar  salt

[[email protected] ~]# systemctl start salt-master.service    #启动服务
[[email protected] ~]# systemctl enable salt-master           #设置为开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-master.service to /usr/lib/systemd/system/salt-master.service.
[[email protected] ~]# netstat -anpt | egrep ‘4505|4506‘      #查看端口开启
tcp        0      0 192.168.18.128:4505     0.0.0.0:*             LISTEN      5178/python  tcp        0      0 192.168.18.128:4506     0.0.0.0:*             LISTEN      5202/python 

第三步:节点服务器的操作

web01:
[[email protected] ~]# yum -y install salt-minion
`修改配置文件`
16 master: 192.168.18.128       #16行,删除注释,指定主控端IP
78 id: web01.saltstack.com      #78行,删除注释,指定被控端主机名
#修改完成后按Esc退出插入模式,输入:wq保存退出
[[email protected] ~]# systemctl start salt-minion.service
web02:
[[email protected] ~]# yum -y install salt-minion
`修改配置文件`
[[email protected] ~]# vim /etc/salt/minion
16 master: 192.168.18.128       #16行,删除注释,指定主控端IP
78 id: web02.saltstack.com      #78行,删除注释,指定被控端主机名
#修改完成后按Esc退出插入模式,输入:wq保存退出
[[email protected] ~]# systemctl start salt-minion.service

验证:

`在主控端测试与被控端的通信状态`
[[email protected] ~]# salt ‘*‘ test.ping
web02.saltstack.com:
    True
web01.saltstack.com:
    True

`远程执行命令查看两个节点的挂载情况`
[[email protected] ~]# salt ‘*‘ cmd.run ‘df -h‘
web01.saltstack.com:
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        20G  3.5G   17G  18% /
    devtmpfs        898M     0  898M   0% /dev
    tmpfs           912M   12K  912M   1% /dev/shm
    tmpfs           912M   18M  895M   2% /run
    tmpfs           912M     0  912M   0% /sys/fs/cgroup
    /dev/sda1       6.0G  174M  5.9G   3% /boot
    /dev/sda5        10G   54M   10G   1% /home
    tmpfs           183M  4.0K  183M   1% /run/user/42
    tmpfs           183M   24K  183M   1% /run/user/0
    /dev/sr0        4.3G  4.3G     0 100% /run/media/root/CentOS 7 x86_64
web02.saltstack.com:
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        20G  3.5G   17G  18% /
    devtmpfs        898M     0  898M   0% /dev
    tmpfs           912M   12K  912M   1% /dev/shm
    tmpfs           912M   18M  895M   2% /run
    tmpfs           912M     0  912M   0% /sys/fs/cgroup
    /dev/sda5        10G   54M   10G   1% /home
    /dev/sda1       6.0G  174M  5.9G   3% /boot
    tmpfs           183M  4.0K  183M   1% /run/user/42
    tmpfs           183M   24K  183M   1% /run/user/0
    /dev/sr0        4.3G  4.3G     0 100% /run/media/root/CentOS 7 x86_64

`如果单独只看某一个节点的挂载情况`
[[email protected] ~]# salt ‘web02.saltstack.com‘ cmd.run ‘df -h‘
web02.saltstack.com:
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        20G  3.5G   17G  18% /
    devtmpfs        898M     0  898M   0% /dev
    tmpfs           912M   12K  912M   1% /dev/shm
    tmpfs           912M   18M  895M   2% /run
    tmpfs           912M     0  912M   0% /sys/fs/cgroup
    /dev/sda5        10G   54M   10G   1% /home
    /dev/sda1       6.0G  174M  5.9G   3% /boot
    tmpfs           183M  4.0K  183M   1% /run/user/42
    tmpfs           183M   24K  183M   1% /run/user/0
    /dev/sr0        4.3G  4.3G     0 100% /run/media/root/CentOS 7 x86_64

`显示web01的详细信息`
[[email protected] ~]# salt ‘web01.saltstack.com‘ grains.items
web01.saltstack.com:
    ----------
    SSDs:
    biosreleasedate:
        07/29/2019
    biosversion:
        6.00
    cpu_flags:
        ......此处省略多行
    host:
        web01
    hwaddr_interfaces:
        ----------
        ens33:
            00:0c:29:79:45:8e
        lo:
            00:00:00:00:00:00
        virbr0:
            52:54:00:e7:ec:25
        virbr0-nic:
            52:54:00:e7:ec:25
    id:
        web01.saltstack.com
        ......此处省略多行
    ip_interfaces:
        ----------
        ens33:
            - 192.168.18.148
            - fe80::6a0c:e6a0:7978:3543     #网卡的mac地址
        lo:
            - 127.0.0.1
            - ::1
        virbr0:
            - 192.168.122.1
        virbr0-nic:
    ipv4:
        - 127.0.0.1
        - 192.168.122.1
        - 192.168.18.148
    ipv6:
        - ::1
        - fe80::6a0c:e6a0:7978:3543
    ......此处省略多行
    virtual:
        VMware
    zmqversion:
        4.1.4

`查看动态信息`
[[email protected] ~]# salt ‘web01.saltstack.com‘ pillar.items

`查看在master上已经被接受过的客户端`
[[email protected] ~]# salt-key
Accepted Keys:      #认证过的主机名
web01.saltstack.com
web02.saltstack.com
Denied Keys:        #拒绝
Unaccepted Keys:    #未通过认证
Rejected Keys:

第四步:批量安装apache

[[email protected] ~]# cd /srv/salt/
[[email protected] salt]# ls
[[email protected] salt]# vim top.sls
base:
  ‘*‘:
    - apache
#在所有的客户端执行apache模块

[[email protected] salt]# vim apache.sls
apache-service:
  pkg.installed:
    - names:
      - httpd
      - httpd-devel
  service.running:
    - name: httpd
    - enable: True
#修改完成后按Esc退出插入模式,输入:wq保存退出

[[email protected] salt]# ls
apache.sls  top.sls

`重启服务`
[[email protected] salt]# systemctl restart salt-master.service

`执行批量部署命令`
[[email protected] salt]# salt ‘*‘ state.highstate
[[email protected] ~]# salt ‘*‘ state.highstate
web01.saltstack.com:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: The following packages were installed/updated: httpd
     Started: 15:04:51.323952
    Duration: 40217.299 ms
     Changes:
              ----------
              apr:
                  ----------
                  new:
                      1.4.8-5.el7
                  old:
              apr-util:
                  ----------
                  new:
                      1.5.2-6.el7
                  old:
              httpd:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              httpd-tools:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              mailcap:
                  ----------
                  new:
                      2.1.41-2.el7
                  old:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: The following packages were installed/updated: httpd-devel
     Started: 15:05:31.545046
    Duration: 16876.92 ms
     Changes:
              ----------
              apr-devel:
                  ----------
                  new:
                      1.4.8-5.el7
                  old:
              apr-util-devel:
                  ----------
                  new:
                      1.5.2-6.el7
                  old:
              cyrus-sasl:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-devel:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
              cyrus-sasl-gssapi:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-lib:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-md5:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-plain:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-scram:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              expat-devel:
                  ----------
                  new:
                      2.1.0-10.el7_3
                  old:
              httpd-devel:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              libdb:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
                      5.3.21-20.el7
              libdb-devel:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
              libdb-utils:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
                      5.3.21-20.el7
              openldap:
                  ----------
                  new:
                      2.4.44-21.el7_6
                  old:
                      2.4.44-5.el7
              openldap-devel:
                  ----------
                  new:
                      2.4.44-21.el7_6
                  old:
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd has been enabled, and is running
     Started: 15:05:48.459684
    Duration: 1822.995 ms
     Changes:
              ----------
              httpd:
                  True

Summary
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3
web02.saltstack.com:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: The following packages were installed/updated: httpd
     Started: 15:04:51.468389
    Duration: 50746.816 ms
     Changes:
              ----------
              apr:
                  ----------
                  new:
                      1.4.8-5.el7
                  old:
              apr-util:
                  ----------
                  new:
                      1.5.2-6.el7
                  old:
              httpd:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              httpd-tools:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              mailcap:
                  ----------
                  new:
                      2.1.41-2.el7
                  old:
----------
          ID: apache-service
    Function: pkg.installed
        Name: httpd-devel
      Result: True
     Comment: The following packages were installed/updated: httpd-devel
     Started: 15:05:42.221145
    Duration: 28643.51 ms
     Changes:
              ----------
              apr-devel:
                  ----------
                  new:
                      1.4.8-5.el7
                  old:
              apr-util-devel:
                  ----------
                  new:
                      1.5.2-6.el7
                  old:
              cyrus-sasl:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-devel:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
              cyrus-sasl-gssapi:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-lib:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-md5:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-plain:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              cyrus-sasl-scram:
                  ----------
                  new:
                      2.1.26-23.el7
                  old:
                      2.1.26-21.el7
              expat-devel:
                  ----------
                  new:
                      2.1.0-10.el7_3
                  old:
              httpd-devel:
                  ----------
                  new:
                      2.4.6-90.el7.centos
                  old:
              libdb:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
                      5.3.21-20.el7
              libdb-devel:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
              libdb-utils:
                  ----------
                  new:
                      5.3.21-25.el7
                  old:
                      5.3.21-20.el7
              openldap:
                  ----------
                  new:
                      2.4.44-21.el7_6
                  old:
                      2.4.44-5.el7
              openldap-devel:
                  ----------
                  new:
                      2.4.44-21.el7_6
                  old:
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: Service httpd has been enabled, and is running
     Started: 15:06:10.880454
    Duration: 1618.997 ms
     Changes:
              ----------
              httpd:
                  True

Summary
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3
#此时两台节点部署apache服务完成

验证:两台web服务器上是否成功安装了apache服务

web01:
[[email protected] ~]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64
[[email protected] ~]# netstat -ntap | grep 80
tcp6       0      0 :::80                   :::*                  LISTEN      6786/httpd 
web02:
[[email protected] ~]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64
[[email protected] ~]# netstat -ntap | grep 80
tcp6       0      0 :::80                   :::*                  LISTEN      6759/httpd 

原文地址:https://blog.51cto.com/14464303/2468687

时间: 2024-11-09 03:16:04

Saltstack批量部署apache的相关文章

自动化运维系列之SaltStack批量部署Apache服务

自动化运维系列之SaltStack批量部署Apache服务 saltstack原理 SalStack由master和minion构成,master是服务端,表示一台服务器:minion是客户端,表示多台服务器.在Master上发送命令给符合条件的minion,Minion就会执行相应的命令.Master和Minion之间是通过ZeroMQ(消息队列)进行通信的. SaltStack的Master端的监听端口是4505和4506,4505端口是Master和Minion认证通信端口:4506端口是

基于Saltstack批量部署apache

什么是SaltStack SaltStack管理工具允许管理员对多个操作系统创建一个一致的管理系统 实验环境准备 名称 角色 地址 centos7-min master 192.168.142.172 centos7-min2 client 192.168.142.110 实验步骤 一.主服务器--控制节点 安装epel源并安装控制端 yum install -y epel-release //安装epel源 yum -y install salt-master //安装控制端 修改控制端主配置

CentOS 6.3下CHEF批量部署APACHE

之前的博文我介绍了如何搭建CHEF环境以及创建编写cookbook,resipes用来批量将cookbook下发到客户端执行相应的部署操作. NOW,本篇文档我们会详细介绍如何利用CHEF独有的框架语言来批量部署安装APACHE,并加载其HTTPS模块等功能. 相信如果你看了本篇文档,利用CHEF实现一个批量自动化部署将不是什么难事. CHEF环境部署详见: http://showerlee.blog.51cto.com/2047005/1408467 操作系统:CentOS-6.3-x86-6

Saltstack批量部署tomcat(多实例)

上一篇讲解了如何批量部署nginx,这篇说一说如何批量部署tomcat,其实方式上都差不多,tomcat多了个java必须配置,以及需要多个实例一起部署.方式方法上可能不是最优方案,功能上是都可以实现基本需求的. 环境介绍: Centos 6.5 tomcat 7.0.68 java 1.7.0_80 实例3个,site.aaa.com|boss.aaa.com|mobile.aaa.com minion:test 1.修改主入口文件,如何你看不懂其中没标注的一些行,请参考<Saltstack批

saltstack自动部署apache实例

1.配置pillar的top.sls: base:  nova:    - match: nodegroup    - nova   neutron:    - match: nodegroup    - neutron 2.pillar的nova和neutron的配置: apache:  name: httpd  ip: 172.16.171.120   root: /var/www/neutronapache:  name: httpd  ip: 172.16.171.110   root:

saltstack详解+部署apache服务

saltstack介绍 1. saltstack是使用python语言开发的:2. 轻量级的管理工具,批量执行命令:3.常用模块:pkg(包).file(文件).cmd(执行命令或脚本).user. service.cron4.saltstack数据系统Grains (静态数据)pillar (动态数据) saltstack三大功能,远程执行,配置管理,云管理 SaltStack是一个服务器基础架构集中化管理平台,具备配置管理.远程执行.监控等功能,基于Python语言实现,结合轻量级消息队列(

自动化运维工具---SaltStack安装部署及简单案例

SaltStack原理 SaltStack由Master(服务端)和Minion(客户端)组成,Master和Minion之间通过ZeroMQ(消息队列)进行通讯,Master和Minion分别监听4505与4506端口,4505为master与minion认证通信端口,4506为master用来发送或者接受minion的命令执行返回信息. 当客户端启动后,会主动链接master端注册,然后一直保持该TCP连接,而master通过这条TCP连接对客户端进行控制,如果连接断开,master将对客户

Saltstack快速部署

Saltstack 批量部署工具     关于Saltstack是什么东西?有什么作用?我们在这里就不做介绍了,如果有不懂的同学们可以去网络搜索下:了解相关的技术信息. 本次们的主机分部为:    1.Master:192.168.30.131    2.Slave-1:192.168.30.132    3.Slave-2:192.168.30.133 首先,在安装Saltstack之前,我们先来初始我们使用的CentOS环境,及安装所需的基础软件: 以下操作在三台主机上都要操作:1.安装编译

Saltstack批量编译部署nginx(多模块)

最近一直在研究saltstack的同步文件和批量执行命令,随着架构的变大,批量部署的需求也变得明显起来了,我需要用一条命令就部署好nginx和tomcat,并且符合我所有的环境需求,可以直接投入生产环境使用,这就需要用到saltstack的批量安装部署功能了.这篇文章主要介绍nginx的批量部署,下篇讲解tomcat多实例的批量部署方法. 环境介绍: Centos 6.5 salt 2015.5.10 nginx 1.12.0 minion:test 1.修改master配置文件,修改后重启服务