zoukankan      html  css  js  c++  java
  • 用ansible模块化脚本安装redis(多机同步)

    利用ansible脚本模块化安装redis数据库,实现同步安装多台主机。

    从安全角度出发,会对Redis配置文件进行修改,所以,会先在控制端主机直接安装,从而获取Redis.conf配置文件

    vim /etc/redis.conf 打开并编辑配置文件:

    修改默认端口号6379为其他端口号。

    关于访问ip,不能直接设置为0.0.0.0 因为若主机处在公网私网共存环境下,则无法限制外部网络的访问,非常危险

    可以直接通过脚本获取当前本机的ip,从而避免这些问题 >>> bind 当前ip

    bind {{ ansible_default_ipv4.address }}

    配置文件修改完成,准备安装redis的剧本,playbook   r1.yml

    ---------------------------------------------------------------------------------

    - hosts: web

      tasks: 

      - name: installredis                                      安装redis

     yum: name=redis                                       调用yum模块安装

      - name: copyconf       

     template: src=/etc/redis.conf dest=/etc/redis.conf     调用template模块实现拷贝指定文件

      - name: start                       启动Redis

     service: name=redis state=started

    注意:此处应该使用template而不是copy.  template可以替代参数,copy不能

             若使用copy,则配置文件中的ip是   bind {{ ansible_default_ipv4.address }},而不是取出这个ip的值

             template:bind 192.168.13.21 这才是想要的结果

    -------------------------------------------------------------------------------------------------

    handlers的使用:(修改配置文件时使用)

    - hosts: web

      tasks: 

      - name: installredis                                      安装redis

     yum: name=redis                                       调用yum模块安装

      - name: copyconf       

     template: src=/etc/redis.conf dest=/etc/redis.conf     调用template模块实现拷贝指定文件

     tags: copyfile

     notify: restart

      - name: restart                       启动Redis

     service: name=redis state=started

      handlers:

      - name: restart

        service: name=redis state=restarted

    ----------------------------------------------------------------------------------

    setenforce 0  用于临时关闭Selinux

    iptable -F  临时关闭防火墙

    永久关闭则要去配置文件修改: /etc/selinux/config

  • 相关阅读:
    极速安装JumpServer
    高并发限流策略
    JDK1.8源码分析:Future和FutureTask-任务异步执行结果
    nginx 转发 header 数据丢失
    zookpeer 和 redis 集群内一致性协议 及 选举 对比
    Spring Boot 中 Druid 的监控页面配置
    eclipse使用正则表达式查找替换
    jvm 线程状态
    Redis做分布式锁
    Dubbo的异常处理
  • 原文地址:https://www.cnblogs.com/wen-kang/p/10921806.html
Copyright © 2011-2022 走看看