SaltStack 七

# salt Redis部署

/srv/salt/prod/
├── modules
│   ├── apache
│   ├── haproxy
│   ├── keepalived
│   ├── mysql
│   └── redis
│       └── redis-install.sls
└── redis-cluster
    ├── files
    │   └── redis-master.conf
    └── redis-master.sls


1. vim redis-install.sls
redis-install:
  pkg.installed:
    - name: redis
2. redis-master.sls
include:
  - modules.redis.redis-install

redis-master-config:
  file.managed:
    - name: /etc/redis.conf
    - source: salt://redis-cluster/files/redis-master.conf
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    - defaults:
      REDIS_MEM: 100M

redis-master-service:
  service.running:
    - name: redis
    - enable: True
    - watch:
      - file: redis-master-config

3. salt '*' state.sls redis-cluster.redis-master  saltenv=prod  # 默認 base環境
# 執行效果如下:
#---------------------------------------------------------------------------
192.168.2.102:
----------
          ID: redis-install
    Function: pkg.installed
        Name: redis
      Result: None
     Comment: The following packages are set to be installed/updated: redis
     Started: 00:33:34.239727
    Duration: 1015.057 ms
     Changes:   
----------
          ID: redis-master-config
    Function: file.managed
        Name: /etc/redis.conf
      Result: None
     Comment: The file /etc/redis.conf is set to be changed
     Started: 00:33:35.257619
    Duration: 288.224 ms
     Changes:   
              ----------
              newfile:
                  /etc/redis.conf
----------
          ID: redis-master-service
    Function: service.running
        Name: redis
      Result: None
     Comment: Service is set to be started
     Started: 00:33:35.601150
    Duration: 226.642 ms
     Changes:   

Summary
------------
Succeeded: 3 (unchanged=3, changed=1)
Failed:    0
------------
Total states run:     3
192.168.2.104:
----------
          ID: redis-install
    Function: pkg.installed
        Name: redis
      Result: True
     Comment: Package redis is already installed.
     Started: 06:20:39.511771
    Duration: 999.409 ms
     Changes:   
----------
          ID: redis-master-config
    Function: file.managed
        Name: /etc/redis.conf
      Result: None
     Comment: The file /etc/redis.conf is set to be changed
     Started: 06:20:40.513646
    Duration: 299.917 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -58,7 +58,7 @@
                   # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
                   # JUST COMMENT THE FOLLOWING LINE.
                   # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  -bind 127.0.0.1
                  +bind 0.0.0.0
                   
                   # Protected mode is a layer of security protection, in order to avoid that
                   # Redis instances left open on the internet are accessed and exploited.
                  @@ -125,7 +125,7 @@
                   
                   # By default Redis does not run as a daemon. Use 'yes' if you need it.
                   # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
                  -daemonize no
                  +daemonize yes
                   
                   # If you run Redis from upstart or systemd, Redis can interact with your
                   # supervision tree. Options:
                  @@ -534,7 +534,7 @@
                   # limit for maxmemory so that there is some free RAM on the system for slave
                   # output buffers (but this is not needed if the policy is 'noeviction').
                   #
                  -# maxmemory <bytes>
                  + maxmemory 100M
                   
                   # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
                   # is reached. You can select among five behaviors:
              mode:
                  0644
              user:
                  root
----------
          ID: redis-master-service
    Function: service.running
        Name: redis
      Result: None
     Comment: Service is set to be started
     Started: 06:20:41.150092
    Duration: 239.849 ms
     Changes:   

Summary
------------
Succeeded: 3 (unchanged=2, changed=1)
Failed:    0
------------
Total states run:     3
#---------------------------------------------------------------------------
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章