absible部署redis集群

1 案例1:部署redis集群

1.1 问题

具体要求如下:

  • 部署管理主机
  • 创建集群
  • 查看集群信息
  • 访问集群

1.2 方案

    IP,端口规划如下

步骤一:

登录华为云购买云主机

用ssh连接代理机

[root@ecs-proxy ~]# mkdir   redis

[root@ecs-proxy ~]# cd    redis

[root@ecs-proxy ~]# vim redis.yml

---
- name: 部署集群管理脚本
  hosts: mgm
  tasks:
     - yum:
         name: rubygems
     - copy:
         src: redis-3.2.1.gem
         dest: /root/redis-3.2.1.gem
     - shell: gem install redis-3.2.3.gem
     - copy:
         src: redis-4.0.8.tar.gz
    dest: /root/redis-4.0.8.tar.gz
   - file:
       path: /root/bin
         state: directory
         mode: '0755'
      - shell: 'tar -zxvf redis-4.0.8.tar.gz'
    - shell: 'chdir=/root/redis-4.0.8/src cp redis-trib.rb /root/bin'
       - shell: 'chmod +x /root/bin/redis-trib.rb'

  - name: 部署redis集群

     hosts: redis

     tasks:
        - yum:
            name: gcc
        - copy:
            src: redis-4.0.8.tar.gz
            dest: /root/redis-4.0.8.tar.gz
         - shell: 'tar -zxvf redis-4.0.8.tar.gz'
         - shell: 'chdir=/root/redis-4.0.8 make && make install'
         - shell: 'chdir=/root/redis-4.0.8/utils ./install_server.sh <<EOF                   # 在这里要进入交互敲回车

EOF'
         - shell: '/etc/init.d/redis_6379 stop'
         - template:
              src: 6379.conf
              dest: /etc/redis/6379.conf
         - template:

              src: redis_6379
              dest: /etc/init.d/redis_6379
         - shell: 'rm -rf /var/lib/redis/6379/*'
         - shell: '/etc/init.d/redis_6379 start'

最后创建集群

#vim create.sh

#echo '

#yes

# ' |  redis-trib.rb create --replicas 1 192.168.1.22:6351 192.168.1.23:6351 192.168.1.24:6351 192.168.1.25:6351 192.168.1.26:6351 #192.168.1.27:6351 


- name: 创建集群
  hosts: mgm
    - copy:

         src: create

         dest: /root/create.sh

    - shell: 'bash create.sh'

猜你喜欢

转载自www.cnblogs.com/mkmkmk/p/12156324.html