Ansible 之 自动化部署redis主从(单机)
16lz
2021-01-22
一、playbook文件redis.yaml
---- hosts: test vars_files: - vars.yml remote_user: "{{user}}" become: yes tasks: - name: "安装epel源" command: yum -y install epel-release - name: "安装redis" yum: name: redis state: latest - name: "修改redis配置文件监听IP为本机" lineinfile: path: /etc/redis.conf regexp: '^bind 127' line: bind {{master_redis}} - name: "设置开机启动" service: name: redis enabled: yes - name: "启动主库redis6379端口" service: name: redis state: started - name: "制作从库配置文件" command: cp /etc/redis.conf /etc/redis_slave.conf - name: "创建从库的数据存放位置" command: mkdir -p /var/lib/redis_slave - name: "编辑从库配置文件的绑定IP" lineinfile: path: /etc/redis_slave.conf regexp: '^bind 127' line: bind {{master_redis}} - name: "编辑从库配置文件的数据存放位置" lineinfile: path: /etc/redis_slave.conf regexp: '^dir /var/lib/redis' line: dir /var/lib/redis_slave - name: "编辑从库配置文件的监听端口" lineinfile: path: /etc/redis_slave.conf regexp: '^port 6379' line: port 7777 - name: "编辑从库的配置文件,设置为从库" lineinfile: path: /etc/redis_slave.conf line: slaveof "{{master_redis}}" 6379 - name: "启动从库" shell: nohup redis-server /etc/redis_slave.conf &
二、外部变量文件vars.yml
[root@Ansible playbook]# cat vars.yml user: cedarmaster_redis: 10.3.153.8
三、安装结果
[root@Ansible playbook]# ansible-playbook redis.yaml PLAY [test] *****************************************************************************************************************************************************TASK [Gathering Facts] ******************************************************************************************************************************************ok: [10.3.153.8]TASK [安装epel源] **************************************************************************************************************************************************[WARNING]: Consider using the yum module rather than running 'yum'. If you need to use command because yum is insufficient you can add 'warn: false' to thiscommand task or set 'command_warnings=False' in ansible.cfg to get rid of this message.changed: [10.3.153.8]TASK [安装redis] **************************************************************************************************************************************************ok: [10.3.153.8]TASK [修改redis配置文件监听IP为本机] ***************************************************************************************************************************************ok: [10.3.153.8]TASK [设置开机启动] ***************************************************************************************************************************************************ok: [10.3.153.8]TASK [启动主库redis6379端口] ******************************************************************************************************************************************ok: [10.3.153.8]TASK [制作从库配置文件] *************************************************************************************************************************************************changed: [10.3.153.8]TASK [创建从库的数据存放位置] **********************************************************************************************************************************************[WARNING]: Consider using the file module with state=directory rather than running 'mkdir'. If you need to use command because file is insufficient you can add'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.changed: [10.3.153.8]TASK [编辑从库配置文件的绑定IP] ********************************************************************************************************************************************ok: [10.3.153.8]TASK [编辑从库配置文件的数据存放位置] ******************************************************************************************************************************************changed: [10.3.153.8]TASK [编辑从库配置文件的监听端口] ********************************************************************************************************************************************changed: [10.3.153.8]TASK [编辑从库的配置文件,设置为从库] ******************************************************************************************************************************************changed: [10.3.153.8]TASK [启动从库] *****************************************************************************************************************************************************changed: [10.3.153.8]PLAY RECAP ******************************************************************************************************************************************************10.3.153.8 : ok=13 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
四、验证部署情况
©著作权归作者所有:来自51CTO博客作者wx592bc92b285c7的原创作品,如需转载,请注明出处,否则将追究法律责任每一份赞赏源于懂得
赞赏
0人进行了赞赏支持
更多相关文章
- 使用Nginx 代理应用服务的端口,以及ssh连接系统,连接mysql pgsql
- VUE~~~table编辑列功能
- 在 Pycharm 等编辑器下使用 Python 可视化神器 Plotly Express
- 动画:散列表 | 文本编辑器是如何检查英文单词出错的?
- 利用端口扫描进行终端合规性检查的一个示例
- 2021最常用的8个代码编辑器推荐
- php怎么改端口
- Docker服务开放了这个端口,服务器分分钟变肉机!
- ssh 多端口监听或修改默认22端口