ansible自动化搭建MariaDB_Galera_cluster、rabbitmq集群、kafka集群,代码简单易记,自我感觉有参考价值,这里小编只放出来MariaDB_Galera_cluste

基础环境:
修改主机名
修改hosts
[root@ansible ~]# cp /etc/hosts .
ansible节点配置yum源(从controller获取)
[root@ansible ~]# cat http.repo
[centos]
name=centos
baseurl=http://192.168.100.10/centos
gpgcheck=0
enabled=1
[openstack]
name=openstack
baseurl=http://192.168.100.10/openstack/iaas-repo
gpgcheck=0
enabled=1
[root@ansible ~]# yum install -y ansible
[root@ansible ~]# vi /etc/ansible/hosts
末尾添加
[hosts]
node1 ssh_pass=000000
node2 ssh_pass=000000
node3 ssh_pass=000000
[root@ansible ~]# vi /etc/ansible/ansible.cfg
host_key_checking = False
command_warnings = False
[root@ansible ~]# ansible all -m ping
测试通信是否成功

[root@ansible ~]# yum install -y mariadb-server mariadb-server-galera
[root@ansible ~]# cp /etc/my.cnf.d/mariadb-server.cnf .


[root@ansible ansible_work]# pwd
/root/ansible_work
[root@ansible ansible_work]# tree
.
├── cscc_install.yaml
└── roles
    └── mariadb
        └── tasks
            └── main.yaml

3 directories, 2 files

下面是编写main.yaml哦:

[root@ansible ansible_work]# cat roles/mariadb/tasks/main.yaml
- name: cp hosts
  copy: src=/root/hosts dest=/etc

- name: rm repo
  shell: rm -rf /etc/yum.repos.d/*
- name: cp repo
  copy: src=/root/ftp.repo dest=/etc/yum.repos.d/
- name: install
  shell: yum -y install mariadb-server galera
- name: start mariadb
  shell: systemctl start mariadb
- name: password
  shell: mysqladmin password 123456
- name: grant
  shell: mysql -uroot -p123456 -e "grant all privileges on *.* to 'root'@'%' identified by '123456';"
- name: vi conf
  copy: src=/root/server.cnf dest=/etc/my.cnf.d/
- name: stop
  shell: systemctl stop mariadb
- name: galera
  shell: galera_new_cluster
  when: ansible_fqdn=='node1'
- name: start
  shell: systemctl start mariadb
  when: ansible_fqdn=='node2'
- name: start
  shell: systemctl start mariadb
  when: ansible_fqdn=='node3'

以下是执行的配置文件和权限等:

[root@ansible ansible_work]# cat cscc_install.yaml 
- hosts: hosts
  remote_user: root
  roles:
    - mariadb

[root@ansible ansible_work]# vi /root/mariadb-server.cnf
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://node1,node2,node3
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

接下来就可以执行啦:

完成后进行验证

执行playbook:
[root@ansible ansible_work]# ansible-playbook cscc_install.yaml

验证:
[root@ansible ansible_work]# ansible node1 -m shell -a 'mysql -uroot -p123456 -e"show status like \"wsrep_cluster_size\";"'
node1 | SUCCESS | rc=0 >>
Variable_name   Value
wsrep_cluster_size      3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值