定位 发表于 2019-9-7 09:44:50

saltstack自动化安装编译redis

环境:centos6.7
172.31.225.250 node1.example.com (salt-master运行的地方)
172.31.225.252 node3.example.com (salt-minion运行的地方)
172.31.225.254 node4.example.com (salt-minion运行的地方)

我们所需要用到的相关文件都在 /srv/salt/prod/files/ 这个目录下面,大家直接下载即可:


master相关配置:(/etc/salt/master)
file_roots:
  base:
    - /srv/salt/base
  dev:
    - /srv/salt/dev
  prod:
    - /srv/salt/prod

pillar_roots:
  base:
    - /srv/salt/base/pillar
  dev:
    - /srv/salt/dev/pillar
  prod:
    - /srv/salt/prod/pillar1、部署keepalived(这里个人是编译安装)
首先下载源码包:
wget http://download.redis.io/redis-stable.tar.gz
redis所依赖的相关包我已经yum安装过了,这里就不做yum安装了,比如:autoconf组件等,下面直接redis安装

redis安装:(/srv/salt/prod/redis/redis.sls)redis-source:
  file.managed:
    - name: /usr/local/src/redis-stable.tar.gz
    - source: salt://redis/files/redis-stable.tar.gz
    - user: root
    - group: root
    - mode: 644

redis-install:
  cmd.run:
    - name: cd /usr/local/src/ && tar xf redis-stable.tar.gz && cd redis-stable && make && make install
    - unless: test -f /usr/local/bin/redis-server
    - require:
      - file: redis-source

redis-persistent:
  file.directory:
    - name: /var/redis/data
    - watch_in:
      - service: redis-service

redis-conf-directory:
  file.directory:
    - name: /etc/redis
    - watch_in:
      - service: redis-service

redis-conf:
  file.managed:
    - name: /etc/redis/redis.conf
    - source: salt://redis/files/redis.conf
    - user: root
    - group: root
    - mode: 644
    - require:
      - file: redis-conf-directory
      - cmd: redis-install

redis-init:
  file.managed:
    - name: /etc/init.d/redis
    - source: salt://redis/files/redis_init_script
    - user: root
    - group: root
    - mode: 755
    - require_in:
      - service: redis-service

redis-chkconfig:
  cmd.run:
    - name: chkconfig --add redis
    - unless: chkconfig --list | grep redis
    - require:
      - file: redis-init

redis-service:
  service.running:
    - name: redis
    - enable: True
    - watch:
      - file: redis-conf

下面正式安装:
安装之前最好先进行测试安装,检查有没有错误,因为在生产环境下直接执行安装错误,会导致对外服务的相关组件有可能出现问题,所以先进性测试安装salt '*' state.sls redis.redis env=prod test=True这里我测试没有问题,就直接安装了salt '*' state.sls redis.redis env=prod查看redis服务,或者查看端口号有没有在机器上(这里自己是在172.31.225.251这台机器上安装的)




至此就结束了。原创不易,转载请注明原创来处,谢谢!

页: [1]
查看完整版本: saltstack自动化安装编译redis