准备服务器192.168.45.133,192.168.45.135
在135上执行命令yum install -y redis安装redis
yum install -y redis

源码安装方法
wget http://download.redis.io/releases/redis-2.8.13.tar.gz
tar zxf redis-2.8.13.tar.gz
cd redis-2.8.13
make PREFIX=/usr/local/redis install
cp redis.conf /usr/local/redis/
命令模拟写入磁盘数据

/dev/shm目录为Linux系统内存分出来的目录,读写速度比较快
dd if=/dev/zero of=/dev/shm/test.img bs=1M count=1000

安装完成redis后,因为redis在远程机器上,监听127.0.0.1:6379,所以连接不上,需要改写配置文件vim /etc/redis.conf,bind关键词改为0.0.0.0全网监听

启动redis服务systemctl start redis.service
查看redis进程
进入redis-cli编辑命令,keys * 查看键值
ansible和redis整合,在配置文件/etc/ansible/ansible.cfg中defaluts段中加入代码,如果redis密码为admin,则开启admin密码行:

执行命令,查看配置文件是否正确

这里报错显示redis模块异常,需要安装,执行pip install redis安装,因为ansible是python编写的所以需要python模块

也可通过命yum install -y python-redis安装

在133ansible服务器上编写配置文件

Host *
Compression yes
ServerAliveInterval 60
ServerAliveCountMax 5
ControlMaster auto
ControlPath ~/.ssh/%r@%h-%p
ControlPersist 4h
配置ssh远程会话连接配置

从133远程连接135后再133上会生成会话保持文件

这样即可加快ansible剧本演绎速度
