saltstack deployment and cases

Keywords: Apache vim PHP RPM

Case 1: rpm deployment and installation of httpd

(1) Modify the configuration file and create the base directory

[root@server4 salt]# vim /etc/salt/master
[root@server4 salt]# cd
[root@server4 ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
[root@server4 ~]# mkdir /srv/salt  
[root@server4 ~]# /etc/init.d/salt-master restart
Stopping salt-master daemon:                               [  OK  ]
Starting salt-master daemon:                               [  OK  ]
[root@server4 ~]# cd /srv/salt/
[root@server4 salt]# mkdir httpd
[root@server4 salt]# cd httpd/
[root@server4 httpd]# cd ..
[root@server4 salt]# ls
httpd

Modify / etc/salt/master to:

(2) Deployment script

[root@server4 salt]# cd httpd/
[root@server4 httpd]# vim apache.sls
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php


(3) Test, execute push.

root@server4 httpd]# salt server5 state.sls httpd.apache test=true

[root@server4 httpd]# salt server5 state.sls httpd.install    ##Official push


(4) View on minion side, installation successful

[root@server5 ~]# rpm -qa httpd php
httpd-2.2.15-29.el6_4.x86_64
php-5.3.3-26.el6.x86_64


Another way to script:

[root@server4 httpd]# vim apache.sls
httpd:
  pkg.installed
php:
  pkg.installed

Case 2: deploy installation & start httpd
(1) Deployment script

root@server4 httpd]# vim apache.sls 


(2 execute push

[root@server4 httpd]# salt server5 state.sls httpd.apache


(3) Check the minion terminal (server5), open port 80, and the startup is successful

Case 3: Install & start & configure httpd
(1) Create files directory in httpd to store httpd configuration files

[root@server4 httpd]# cd /srv/salt/httpd/
[root@server4 httpd]# ls
apache.sls
[root@server4 httpd]# mkdir files
[root@server4 httpd]# 

(2)minion passes the configuration file to the master

root@server5 ~]# scp /etc/httpd/conf/httpd.conf server1:/srv/salt/httpd/files
 scp the configuration file to the current directory from server5

(3) Change port number of httpd in master to 8080

root@server4 files]# pwd
/srv/salt/httpd/files
[root@server4 files]# vim httpd.conf 
 136        Listen 8080


(4) Deployment script

[root@server4 httpd]# vim apache.sls


(5) Execute push

[root@server4 httpd]# salt server5 state.sls httpd.apache


(6) View on minion side, the profile port of minion (server5) has been automatically changed to 8080, but the port 8080 is not opened because the service is not loaded. Only when the httpd service is restarted can the service be loaded successfully


Case 4: Install & start & configure & Load httpd
Note: the change profile operation will not take effect until it is executed
Method 1:

[root@server4 httpd]# vim apache.sls 
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php

apache-config:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://httpd/files/httpd.conf
    - mode: 644
    - user: root
    - group: root

apache-service:
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:
      - file: apache-config

Method two:

[root@server1 httpd]# vim apache.sls 
apache-install:
  pkg.installed:
    - pkgs:
      - httpd
      - php

  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:                 ##Monitoring trigger
      - file: /etc/httpd/conf/httpd.conf

/etc/httpd/conf/httpd.conf:
  file.managed:
    - source: salt://httpd/files/httpd.conf
    - mode: 644
    - user: root
    - group: root

It's done here. It's done tomorrow
https://blog.csdn.net/hannah_zh/article/details/81111646
Case 5: Installation & startup & Configuration & loading httpd -- File separation

Posted by eosinophil on Wed, 01 Jan 2020 00:36:10 -0800