在/root目录下创建example目录作为Ansible工作目录,部署的入口文件命名为cscc_install.yaml,对其他两台云主机进行安装高可用数据库集群(MariaDB_Galera_cluster,数据库密码设置为123456)的操作
# 设置免密认证,多节点执行
yum -y install /opt/python-keyczar-0.71c-2.el7.noarch.rpm
yum -y install /opt/sshpass-1.05-5.el7.x86_64.rpm
yum -y install ansible
vi /etc/ansible/hosts
[controller]
192.168.200.72
[compute]
192.168.200.92
ssh-keygen
ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.200.72
ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.200.92
mkdir example
vi example/cscc_install.yaml
---
- hosts: all
tasks:
- name: inatell packages
yum:
name: "{{ packages }}"
vars:
packages:
- mariadb
- mariadb-server
- galera
- net-tools
- name: start mariadb
service: name=mariadb state=started
- name: init mariadb
script: mysql_init.sh
- name: stop mariadb
service: name=mariadb state=stopped
- name: use template
template:
src: mariadb-server.cnf.j2
dest: /etc/my.cnf.d/mariadb-server.cnf
- hosts: cluster1
tasks:
- name: start cluster1
shell: "nohup /usr/libexec/mysqld --wsrep-new-cluster --user=mysql &"
async: 10
poll: 0
- wait_for: port=4567 state=started
- hosts: cluster2
tasks:
- name: start cluster2
service: name=mariadb state=started
vi mariadb-server.cnf.j2
[server]
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
[galera]
wsrep_on=ON #节点已经开启
wsrep_provider=/usr/lib64/galera/libgalera_smm.so #启用galera模块
wsrep_cluster_address=gcomm://192.168.200.72,192.168.200.92 #指定集群中节点的IP
binlog_format=row #二进制日志格式必须为行
default_storage_engine=InnoDB #存储引擎(只支持InnoDB)
innodb_autoinc_lock_mode=2 #总结点数量(视自己情况而定,算上主节点)
bind-address=0.0.0.0 #绑定本机的所有IP
wsrep_cluster_name="Mariadb_Galera_Cluster" #集群的名字
wsrep_node_address="{{ ansible_default_ipv4.address }}" #节点的IP
wsrep_node_name = "{{ ansible_hostname }}" #节点的名称
wsrep_sst_method=rsync #集群使用rsync同步方式
[embedded]
[mariadb]
[mariadb-10.1]
vi mysql_init.sh
mysqladmin -uroot password 123456
mysql -uroot -p123456 -e 'grant all privileges on *.* to root@"%" identified by "123456";'
mysql -uroot -p123456 -e 'flush privileges;'
验证
#查看节点数
show status like "wsrep_cluster_size";
#查看加入的节点ip
show global status like 'wsrep_incoming_addresses';
创建4台虚拟机,一台ansible母鸡,三台node,解压部署zookeeper和kafka集群高可靠