系统环境:
CentOS7 64位
MariaDB版本:
MariaDB-Galera-server10.0.14
特点:
多主机数据同步复制每个node节点都是主服务器,每个node都有全部数据.
每个节点都可以提供写和读
数据复制只支持InnoDB引擎.
所有node节点同步数据通过wsrep接口
每个节点下线后,自动从集群中下线
主机规划:
192.168.0.233 client233 192.168.0.234 client234 192.168.0.235 client235
三台主机安装之前,必须先设置selinux 、hostname 和 iptables; 如下:
(1)selinux=Disabled (2)systemctl stop iptables systemctl disables iptables iptables -F service iptables save (3)vi /etc/hosts 192.168.0.233 client233 192.168.0.234 client234 192.168.0.235 client235 (4)reboot
开始部署:
1.mariadb的64位yum源
vi /etc/yum.repo.d/mariadb.repo
[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.0.14/centos7-amd64/enabled = 1gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
yum makecache
2. 开始安装
yum install MariaDB-Galera-server MariaDB-client galera
安装完后,查看/etc/my.cnf.d/下的文件是否为如下:
mariadb-client.conf server.conf tokudb.conf
3. 在三台主机上初始化mariadb,并且创建集群账户。
All nodes:
初始化如下: service mysql start mysql_secure_installation #提示创建密码,root是否远程登录,删除test数据库。授权账户如下: mysql -p GRANT ALL PRIVILEGES ON *.* TO 'cp'@'%' IDENTIFIED BY 'xxx123' WITH GRANT OPTION; flush privileges; quit然后停止All Nodes的数据。 service mysql stop vi /etc/my.cnf.d/server.conf 在【mariadb】模块中添加: [mariadb] query_cache_size=0 binlog_format=ROW default_storage_engine=innodb innodb_autoinc_lock_mode=2 wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address=gcomm://192.168.0.234,192.168.0.235 wsrep_cluster_name='cp' wsrep_node_address='192.168.0.233' wsrep_node_name='client233' wsrep_sst_method=rsync wsrep_sst_auth=cp:xxx123 保存退出后,执行 /etc/init.d/mysql bootstrap 结果报如下 [ERROR] WSREP: gcs/src/gcs_core.c:gcs_core_open():202: Failed to open backend connection: -13 (Permission denied) 错误,最后查了半天资料,原来还是防火墙的原因。于是: iptables -F 或者 iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT 最后再重新: /etc/init.d/mysql bootstrap [mariadb] query_cache_size=0 binlog_format=ROW default_storage_engine=innodb innodb_autoinc_lock_mode=2 wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address=gcomm://192.168.0.233,192.168.0.235 wsrep_cluster_name='cp' wsrep_node_address='192.168.0.234' wsrep_node_name='client234' wsrep_sst_method=rsync wsrep_sst_auth=cp:xxx123 然后: iptables -F 或者 iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT 最后, /etc/init.d/mysql start [mariadb] query_cache_size=0 binlog_format=ROW default_storage_engine=innodb innodb_autoinc_lock_mode=2 wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address=gcomm://192.168.0.233,192.168.0.234 wsrep_cluster_name='cp' wsrep_node_address='192.168.0.235' wsrep_node_name='client235' wsrep_sst_method=rsync wsrep_sst_auth=cp:xxx123 然后: iptables -F 或者 iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT 最后, /etc/init.d/mysql start vi /etc/my.cnf.d/server.cnf[mariadb-10.0]添加:port = 3306tmpdir = /tmpskip-external-lockingskip-name-resolvedefault-storage-engine = INNODBmax_connections=3600innodb_flush_log_at_trx_commit=2innodb_log_file_size=100minnodb_log_files_in_group=5thread_concurrency=24innodb_thread_concurrency=24innodb_commit_concurrency=24max_connections=3600innodb_flush_log_at_trx_commit=2innodb_log_file_size=100minnodb_log_files_in_group=5thread_concurrency=24innodb_thread_concurrency=24innodb_commit_concurrency=24 character-set-server = utf8collation-server = utf8_general_cievent_scheduler = ONmax_allowed_packet = 20M
本文出自 “不求最好,只求更好” 博客,请务必保留此出处http://yujianglei.blog.51cto.com/7215578/1580521