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

  • 相关阅读:
    单节点Redis使用 Python pipline大批量插入数据
    Redis进阶实践之十六 Redis大批量增加数据
    Redis进阶实践之十四 Redis-cli命令行工具使用详解
    Redis进阶实践之十三 Redis的Redis-trib.rb脚本文件使用详解
    (error) MOVED 5798 172.17.0.3:6379
    Redis进阶实践之十二 Redis的Cluster集群动态扩容
    [ERR] Node is not empty. Either the node already knows other nodes (check with C
    【Redis】编译错误zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
    Redis进阶实践之十一 Redis的Cluster集群搭建
    linux 安装软件各种错误集锦及解决方法
  • 原文地址:https://www.cnblogs.com/wen-kang/p/10921806.html
Copyright © 2011-2022 走看看