数据库
首页 > 数据库> > Ansible-Playbook实现Mysql读写分离

Ansible-Playbook实现Mysql读写分离

作者:互联网

Ansible-Playbook实现Mysql读写分离

所有主机的系统环境:

[root@maple-c8-n1 data]# cat /etc/redhat-release 
CentOS Linux release 8.3.2011

服务器共五台

Ansible控制端 10.0.0.8
mycat-server 10.0.0.18  
mysql-master 10.0.0.28  #Mariadb 10.3.17
mysql-slave  10.0.0.38  #Mariadb 10.3.17
mysql-slave  10.0.0.48 

关闭SELinux和防火墙

systemctl stop firewalld
setenforce 0

1. 环境准备

[root@maple-c8-n1 ~]# mkdir -p /data/ansible/mycat_simple/roles
[root@maple-c8-n1 ~]#cd /data/ansible/mycat_simple
[root@maple-c8-n1 mycat_simple]# cp /etc/ansible/hosts .
[root@maple-c8-n1 mycat_simple]# cp /etc/ansible/ansible.cfg .
[root@maple-c8-n1 mycat_simple]# vim ansible.cfg 
[defaults]
inventory      = /data/ansible/mycat_simple/hosts
host_key_checking = False

[root@maple-c8-n1 mycat_simple]# vim hosts
[mycatservers]
10.0.0.18

[dbservers]
10.0.0.28
10.0.0.38
10.0.0.48

#测试
[root@maple-c8-n1 mycat_simple]# ansible mycatservers -m ping
10.0.0.18 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
[root@maple-c8-n1 mycat_simple]# ansible dbservers -m ping   
10.0.0.48 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
10.0.0.38 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
10.0.0.28 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

2. playbook脚本

[root@maple-c8-n1 roles]# ansible-galaxy init mycat 
- Role mycat was created successfully
[root@maple-c8-n1 roles]# ansible-galaxy init dbmaster
- Role dbmaster was created successfully
[root@maple-c8-n1 roles]# ansible-galaxy init dbslave

具体脚本:
https://github.com/ledrsnet/my-ansible-example/tree/main/mycat_simple

标签:10.0,c8,ansible,mycat,Ansible,Playbook,Mysql,root,maple
来源: https://blog.csdn.net/ledrsnet/article/details/117328426