redis
├── files
│   ├── redis6379.conf
│   ├── Redis-server-init
│   └── redis-server.service
├── handlers
├── tasks
│   └── main.yml
└── vars

第一一级目录文件

 - hosts: docker
   remote_user: root
   vars:
    epic: true
    redis_dir: /usr/local/redis
            datesoft: /data/sh
   roles:
    - redis

tasks的mail.yml文件

root@centos-mysql01:/data/sh/ansible_role# cat redis/tasks/main.yml

  • name: groupadd redis
    group: name=redis gid=2004
  • name: useradd redis
    user: name=redis uid=2004 group=redis shell=/sbin/nologin
  • user: /data/sh mkdir
    shell: mkdir -p {{datesoft}}
  • name: copy redis gz
    unarchive: src=/data/ansibel/lnmp/src/redis-4.0.10.tar.gz dest={{datesoft}} copy=yes mode=0755
  • name: install tcl
    command: apt-get install -y tcl
    when: not epic
  • name: make redis
    command: make PREFIX={{redis_dir}} install chdir={{datesoft}}/redis-4.0.10
  • name: make install
    command: make install chdir={{datesoft}}/redis-4.0.10/src
  • name: redis conf log dir
    shell: mkdir -p {{redis_dir}}/var
  • name: redis conf log dir
    shell: mkdir -p {{redis_dir}}/etc
  • name: copy redis.conf
    copy: src=redis6379.conf dest={{redis_dir}}/etc/redis.conf mode=0644
  • name: redis.conf change
    command: sh redis_conf.sh chdir={{datesoft}}
  • name: chow redis
    shell: chown -R redis:redis {{redis_dir}}
  • name: redis-server add system
    copy: src=Redis-server-init dest=/etc/init.d/redis-server mode=0761
  • name: chkconfig redis-server
    shell: update-rc.d redis-server defaults
    when: ansible_os_family == "Debian"
  • name: chkconfig redis-server
    shell: chkconfig --add redis-server; chkconfig redis-server on
    when: ansible_os_family == "Centos"
  • name: services
    service: name=redis-server state=restarted enabled=yes

    files文件

    root@centos-mysql01:/data/sh/ansible_role# ls redis/files/
    redis6379.conf Redis-server-init redis-server.service

    脚本redis_conf.sh

    redis_install_dir="/usr/local/redis"
    sed -i 's@pidfile.@pidfile /var/run/redis/redis.pid@' ${redis_install_dir}/etc/redis.conf
    sed -i "s@logfile.
    @logfile ${redis_install_dir}/var/redis.log@" ${redis_install_dir}/etc/redis.conf
    sed -i "s@^dir.*@dir ${redis_install_dir}/var@" ${redis_install_dir}/etc/redis.conf
    sed -i 's@daemonize no@daemonize yes@' ${redis_install_dir}/etc/redis.conf
    sed -i "s@^# bind 127.0.0.1@bind 127.0.0.1@" ${redis_install_dir}/etc/redis.conf
    Mem=free -m|awk -F: '{print $2}'|awk '{print $1}'|head -n2|tail -n 1
    redis_maxmemory=expr $Mem / 8000000
    sed -i "s@maxmemory @maxmemory \nmaxmemory expr $Mem / 8000000@" ${redis_install_dir}/etc/redis.conf

下载地址

链接: https://pan.baidu.com/s/1Mvg1oaoLKojtBP6BjgBCvg 提取码: rf29