MariaDB Galera Cluster部署手册
galara保证双主数据库的同步及一致性
1、环境准备
基于新部署、最小化安装centos6.5
1> yum install openssh-clients vim wget
2 > /etc/init.d/iptables stop;chkconfig iptables off
3> setenforce 0;sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
4> 192.168.1.10 mysql1
192.168.1.20 mysql2
192.168.1.30 mysql3
###使用vmware 测试需注意####
克隆机器删除rm -rfv /etc/udev/rules.d/70-persistent-net.rules以及网卡中的mac地址选项不然网卡起不来
2、环境检测
检查iptables状态:/etc/init.d/iptables status;chkconfig --list | grep iptables
检查selinux状态:getenforce
检查openssh-client包是否安装:系统中是否有ssh命令
检查是否系统中含有mysql相关的包:rpm -qa | grep mysql,有的话都需要卸载掉
检查网络是否通畅:ping www.baidu.com
3、配置yum源
[root@mysql1 ~]# cat /etc/yum.repos.d/mariadb.repo
# MariaDB 10.1 CentOS repository list - created 2015-10-20 05:55 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0.20/centos/6.5/x86_64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
mkdir -p /var/lib/mysql
yum clean all
yum makecache
备注:
https://downloads.mariadb.org/mariadb/repositories/ 为提供yum源的路径,但是个别的rpm包不存在,所以需要自己登陆url进行核实,找有对应版本的yum源路径
4、安装服务
yum -y install MariaDB-Galera-server galera MariaDB-client
安装完毕后会自动新建mysql账户和组、安装rsync服务,故无需自己额外建mysql账号
5、部署xtrabackup
cat /etc/yum.repos.d/Percona.repo
[percona]
name =CentOS $releasever - Percona
baseurl=http://repo.percona.com/centos/$releasever/os/$basearch/
enabled = 1
gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-percona
gpgcheck = 1
wget -O/etc/pki/rpm-gpg/RPM-GPG-KEY-percona http://www.percona.com/downloads/RPM-GPG-KEY-percona
yum install xtrabackup
6、配置免key设置(三台机器都需配置)
ssh-keygen -t rsa
ssh-copy-id mysql2
ssh-copy-id mysql3
7、hosts文件设置(三台机器都需配置)
vim /etc/hosts
192.168.1.10 mysql1
192.168.1.20 mysql2
192.168.1.30 mysql3
8、mysql设置开机启动
/etc/init.d/mysql start
chkconfig mysql on
9、mysql初始化设置
/usr/bin/mysql_secure_installation
10、新建mysql 同步账户sst
mysql –uroot -p
grant all privileges on *.* to sst@'%' identified by 'jacky.com';
flush privileges;
11、wsrep设置、创建并配置wsrep.cnf文件
cp /usr/share/mysql/wsrep.cnf /etc/my.cnf.d/
vi /etc/my.cnf.d/wsrep.cnf
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://mysql1,mysql2"
wsrep_sst_auth=sst:atman.com
wsrep_sst_method=xtrabackup
备注:
"gcomm://" 是特殊的地址,仅仅是Galera cluster初始化启动时候使用
如果集群启动以后,我们关闭了第一个节点,那么再次启动的时候必须先修改,"gcomm://"为其他节点的集群地址,例如wsrep_cluster_address="gcomm://mysql1,mysql2,mysql3"