centos7.2安装mariadb集群:
1、关闭SELinux:
先查看SELinux状态:/usr/sbin/sestatus -v,如果SELinux status: enabled,说明是开启状态,修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可。或者setenforce 0临时关闭。
2、关闭防火墙
systemctl start firewalld.service#启动firewall
systemctl stop firewalld.service#停止firewall搜索
systemctl disable firewalld.service#禁止firewall开机启动
3、安装mariadb cluster
创建文件:
vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
线上安装:
sudo yum install MariaDB-Galera-server MariaDB-client galera MariaDB-server MariaDB-shared
或者是安装已下载的安装包:
好像这个安装有顺序,带个参数--force --nodeps进行安装,这一点很纠结,我当时安装的时候,没有安装成功gelara,所以先sudo yum install galera。然后又安装了以下安装包:
rpm -ivh MariaDB-10.1.18-centos7-x86_64-common.rpm MariaDB-10.1.18-centos7-x86_64-shared.rpm MariaDB-10.1.18-centos7-x86_64-server.rpm MariaDB-10.1.18-centos7-x86_64-client.rpm --force --nodeps
[MysqLd]
# * Galera-related settings
[galera]
wsrep_on=ON
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address = "gcomm://master,slave1,slave2"
wsrep_node_name = master #local hostname
wsrep_node_address=192.168.226.128 #local ip
#bind-address=0.0.0.0
# This group is only read by MariaDB servers,not by MysqL.
# If you use the same .cnf file for MysqL and MariaDB,# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.1 servers.
# If you use the same .cnf file for MariaDB of different versions,# use this group for options that older servers don't understand
[mariadb-10.1]
4、启动集群(启动该命令的节点将成为主节点master):
MysqLd --wsrep-new-cluster --user=root &
5、添加新节点:
在新节点按照1~3步骤安装Mariadb,但是文件/etc/my.cnf.d/server.cnf要改下对应的ip和节点名wsrep_node_name
和wsrep_node_address,改成这个新节点的主机名和ip。
然后在新节点上执行命令启动mariadb服务:
systemctl start mariadb
然后master上执行show status like ‘wsrep_%’,就可以看到wsrep_cluster_size节点数为2了。
6、删除节点:
在待删除节点上执行命令停止mariadb服务systemctl stop mariadb,然后在master节点上执行
show status like 'wsrep_%',
就可以看到wsrep_cluster_size节点数变成1了。
7、删除Mariadb
要删彻底:
找到任何与mariadb相关的,删掉
find / -name "mariadb" -exec rm -rf {} \;
遇到的错误
启动报错:
[ERROR] WSREP:Failed to open gcomm backend connection: 131: invalid UUID:0000000 (FATAL)
[ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():208: Failed to open backend connection:-131(State not recoverable)
解决方案:不知道是不是这个方法,反正莫名其妙的好了,
将/var/lib/MysqL/下的gvwstate.dat 删除,重启服务。
报错:
2016-10-13 14:23:07 140380776994944 [ERROR] WSREP: Failed to open file '/var/lib/MysqL//galera.cache': 13 (Permission denied)
[ERROR] WSREP: Could not open state file for writing: '/var/lib/MysqL//grastate.dat'. Check permissions and/or disk space.: 13 (Permission denied)
解决方案:
chmod MysqL:MysqL /var/lib/MysqL//grastate.dat
chown MysqL:MysqL -R /var/lib/mysq
备注
ps -ef是查看所有的进程 可以查看mariadb服务是否启动: 在第一个启动节点上执行 ps -ef | grep wsrep,如果启动,会有进程: root 21312 19869 0 17:55 pts/1 00:00:02 MysqLd –wsrep-new-cluster –user=root 在其他节点上执行 ps -ef | grep wsrep,如果启动,会有进程: MysqL 4625 1 0 17:55 ? 00:00:01 /usr/sbin/MysqLd –wsrep_start_position=a282f0f5-9171-11e6-88cd-8e886d712351:21