Playbook部署Mysql

1.把需要部署的主机添加到web组:

[web]
192.168.127.136 user=root ansible_ssh_user=root ansible_ssh_pass=1
192.168.127.148 user=root ansible_ssh_user=root ansible_ssh_pass=1
192.168.127.135 user=root ansible_ssh_user=root ansible_ssh_pass=1

#注:192.168.127.136 为管理节点

2.管理节点和被管理节点建立免密登录:

vim /etc/ansible/ansible.cfg
打开 host_key_checking = False  #禁用SSH密钥主机检查

方法1:
ls ~/.ssh/id_rsa || ssh-keygen -f ~/.ssh/id_rsa -N ""   #生成指定路径不要密码的密钥对


ansible web -m authorized_key -a "user=root state=present key={{ lookup('file', '/root/.ssh/id_rsa.pub') }}"  -e "ansible_ssh_user=root ansible_ssh_pass=1 "


ansible web -m ping   #测试是否建立免密登录

方法2:
ls ~/.ssh/id_rsa || ssh-keygen -f ~/.ssh/id_rsa -N ""

[root@slave ~]#cat a.yaml 
- name: 免密
  hosts: web
  gather_facts: no
  tasks:
    - name: web免密
      authorized_key: 
        user: "{{user}}"
        state: present
        key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"

ansible-playbook a.yaml 

3.vim deploy-mysql.yaml   

---
- name: 部署mysql
  hosts: web
  gather_facts: no
  remote_user: root
    tasks:
    #初始化服务器 关闭防火墙,selinux
    - name: 关闭selinux
      lineinfile:
        path: /etc/selinux/config
        regexp: '^SELINUX='
        line: 'SELINUX=disabled'
        state: present
    - name: 安装库,开发工具包
      yum:
        name:
          - '@Development Tools' 
          - https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
        state: present

    - name: 禁用 MySQL 8.0 仓库
      ini_file:
           path: /etc/yum.repos.d/mysql-community.repo
           section: mysql80-community
           option:  enabled
           value: '0'
    - name: 启用 MySQL 5.7 仓库
      ini_file:
           path: /etc/yum.repos.d/mysql-community.repo
           section: mysql57-community
           option: enabled
           value: '1'

    - name: 安装mysql
      yum:
        name: mysql-community-server
        state: present
    - name: start mysql
      service:
        name: mysqld
        state: started
...

ansible-playbook deploy-mysql.yaml  -vvv   #运行
 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值