温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

centos6.9怎么搭建pxc集群

发布时间:2021-08-24 18:33:02 来源:亿速云 阅读:133 作者:chen 栏目:软件技术

这篇文章主要讲解了“centos6.9怎么搭建pxc集群”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“centos6.9怎么搭建pxc集群”吧!

一:环境介绍:

10.1.32.49 

10.1.32.50

10.1.32.36

其中操作系统全部为 :centos 6.9 ,并且49和50是数据库集群的数据节点,36为鉴证节点或者叫选举节点,安装的percona 5.6版本,其中鉴证节点的garb安装的是garbd-3版本

二:正式安装:

2.1.首先安装相关的yum 源:

1-3版本的yum源:

yum installhttp://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm

1-4版本的yum源:(一般选择新版本)

yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

装一些centos源里面没有的软件的源

yum install http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

查看关于percona的yum源存在否:

[root@ory-newcaiwu-mysql-02 ~]# rpm  -qa  | grep  percona

percona-xtrabackup-24-2.4.9-1.el6.x86_64

percona-release-0.1-4.noarch

percona-toolkit-3.0.6-1.el6.x86_64

2.2 关闭防火墙和 Selinux

service iptables stop

chkconfig iptables off

vi /etc/selinux/config

SELINUX=disabled

2.2.查看已经安装的Percona的版本,如果不是自己需要的,那么卸载掉,防止冲突!

[root@ory-newcaiwu-mysql-01 ~]# yum list  Percona*

或者

[root@ory-newcaiwu-mysql-02 ~]# rpm  -qa  | grep  Percona*

卸载系统本身有的Percona

[root@ory-newcaiwu-mysql-01 ~]# yum remove   Percona*

安装pxc具体需要安装下面几个包,真正安装的时候只需要Percona-XtraDB-Cluster-server-56即可,其余的都作为依赖包自动安装上了!

yum -y install Percona-XtraDB-Cluster-server Percona-XtraDB-Cluster-client Percona-Server-shared-compat percona-xtrabackup

查看Percona的各个版本的包的名字,以便于具体选择特定的版本:

[root@ory-newcaiwu-mysql-02 ~]# rpm  -qa  | grep  Percona*

2.3使用yum安装,只需要安装 Percona-XtraDB-Cluster-server即可,别的都是他的依赖包,一并都给自动安装了,如下我们选择的是5.6版本的mysql:

[root@ory-newcaiwu-mysql-02 ~]# yum install   -y  Percona-XtraDB-Cluster-server-56

2.4.然后配置参数/etc/my.cnf,两个数据节点配置参数基本相同,需要改个别参数;

[mysqld]
# GENERAL
datadir                                                                 = /data/mysqldata
tmpdir                                                                  = /tmp
socket                                                                  = /data/mysqldata/mysql.sock
pid_file                                                                = /data/mysqldata/mysql.pid
user                                                                    = mysql
port                                                                    = 3306
character-set-server                                                    = utf8
bind-address                                                            = 0.0.0.0
server-id                                                               = 1013250
skip-name-resolve
lower_case_table_names                                                  = 1
# INNODB
# This changes how |InnoDB| autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode                                                = 2
innodb_buffer_pool_size                                                 = 90G
innodb_buffer_pool_instances                                            = 8
innodb_thread_concurrency                                               = 40
innodb_log_buffer_size                                                  = 32M
innodb_log_file_size                                                    = 1024M
innodb_online_alter_log_max_size                                        = 512M
innodb_open_files                                                       = 65535
innodb_purge_threads                                                    = 8
innodb_data_home_dir                                                    = /data/mysqldata
innodb_data_file_path                                                   = ibdata1:256M:autoextend
innodb_read_io_threads                                                  = 8
innodb_write_io_threads                                                 = 8
innodb_file_per_table                                                   = 1
innodb_flush_method                                                     = O_DIRECT
innodb_flush_log_at_trx_commit                                          = 2
innodb_max_dirty_pages_pct                                              = 90
innodb_file_format                                                      = Barracuda
innodb_file_format_max                                                  = Barracuda
innodb_io_capacity                                                      = 512
innodb_io_capacity_max                                                  = 4096

#event_scheduler                                                        = OFF

# MyISAM
key_buffer_size                                                         = 32M

# LOGS
#general_log                                                            = 1
#general_log_file                                                       = /data/logs/mysql/mysql_general.log
log_warnings                                                            = 2
log_error                                                               = /data/logs/mysql/mysql_error.log
slow_query_log                                                          = ON
slow_query_log_file                                                     = /data/logs/mysql/mysql_slow.log
log_queries_not_using_indexes                                           = 0
long_query_time                                                         = 1
expire_logs_days                                                        = 15
log-bin                                                                 = mysql-bin.log
innodb_print_all_deadlocks                                              = 1
relay-log                                                               = relay-log
relay-log-index                                                         = relay-log
log_bin_trust_function_creators                                         = 1
# BINLOG
# In order for Galera to work correctly binlog format should be ROW
binlog_format                                                           = ROW
binlog_cache_size                                                       = 32M
max_binlog_size                                                         = 512M
log_bin_trust_function_creators                                         = 1

# OTHER
default_storage_engine                                                  = InnoDB
tmp_table_size                                                          = 32M
max_heap_table_size                                                     = 128M
query_cache_type                                                        = 0
query_cache_size                                                        = 0M
max_connections                                                         = 1024
thread_cache_size                                                       = 600
open_files_limit                                                        = 65535
innodb_buffer_pool_load_at_startup                                      = ON
innodb_buffer_pool_dump_at_shutdown                                     = ON
auto_increment_offset                                                   = 1
optimizer-switch                                                        = "mrr=on,mrr_cost_based=off,batched_key_access=on"
join_buffer_size                                                        = 16M
expand_fast_index_creation                                              = 1
sort_buffer_size                                                        = 16M
max_allowed_packet                                                      = 16M
sql_mode                                                                = STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
# WSREP
wsrep_auto_increment_control                                            = OFF
# Path to Galera library
wsrep_provider                                                          = /usr/lib64/libgalera_smm.so
# Cluster connection URL
wsrep_cluster_address                                                   = gcomm://10.1.32.49:4567,10.1.32.50:4567
# Node #1 address
wsrep_node_address                                                      = 10.1.32.50 # local IP
# SST method
wsrep_sst_method                                                        = xtrabackup-v2
# Cluster name
wsrep_cluster_name                                                      = XFXJ_CAIWU_CLUSTER
# Authentication for SST method
wsrep_sst_auth                                                          = "sstuser:LLivTGmIWpVohjMD"
wsrep_max_ws_rows                                                       = 500000
wsrep_max_ws_size                                                       = 2147483647
wsrep_slave_threads                                                     = 40
wsrep_provider_options                                                  = "gcache.size=32G; gcache.page_size=512M; gcs.fc_limit = 4096;gcs.fc_master_slave = yes"

#Replication
log_slave_updates                                                       = 1
slave_parallel_worker                                                   = 4
gtid-mode                                                               = on
enforce_gtid_consistency                                                = true
binlog_checksum                                                         = CRC32
slave_allow_batching                                                    = 1
master_verify_checksum                                                  = 1
slave_sql_verify_checksum                                               = 1
master_info_repository                                                  = TABLE
relay_log_info_repository                                               = TABLE

[client]
socket                                                                  = /data/mysqldata/mysql.sock
port                                                                    = 3306
#default_character_set                                                  = utf8
[mysql]
default-character-set                                                   = utf8
prompt                                                                  ="\\u@\\h : \\d \\R:\\m:\\s>"
no-auto-rehash

2.5初始化数据库主节点:其他的不用刻意的初始化,因为等你启动第二个节点的时候他会sst同步给第二个节点

mysql_install_db --defaults-file=/etc/my.cnf --user=mysql

2.6.删除匿名账号

mysql -e "delete from mysql.user where user=' ';delete from mysql.user where user='';flush privileges;"

2.7.给管理员账号设密码

mysqladmin -u root password $password

2.8.每台机器mysql添加SST账户

其实只需要在主节点添加即可,因为等你启动第二个节点的时候他会sst同步给第二个节点,那么用户也会同步过去。注意用户名和密码需要在参数wsrep_sst_auth中对应!

CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'liuwenhe';

GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT,PROCESS ON *.* TO 'sstuser'@'localhost';

2.9.启动主节点(以bootstrap-pxc方式启动):

[root@ory-newcaiwu-mysql-01 ~]# /etc/init.d/mysql   #显示mysql启动全部方式!

Usage: mysql {start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc}  [ MySQL (Percona XtraDB Cluster) options ]

以bootstrap-pxc方式启动:

[root@ory-newcaiwu-mysql-01 ~]# /etc/init.d/mysql   bootstrap-pxc

3.0.启动节点32.50,会自动触发集群主节点32.49给它全量同步数据(也就是sst)

[root@ory-newcaiwu-mysql-02 mysqldata]# /etc/init.d/mysql  start

Starting MySQL (Percona XtraDB Cluster)...State transfer in progress, setting sleep higher

....                                                       [  OK  ]

三:32.36上 鉴证节点相关操作:

3.1.安装garb服务:

[root@ory-fanxiqian-Oracle-01 ~]# yum  install Percona-XtraDB-Cluster-garbd-3

3.2.配置gab参数:

[root@ory-fanxiqian-Oracle-01 ~]# cat /etc/sysconfig/garb

# A comma-separated list of node addresses (address[:port]) in the cluster

GALERA_NODES="10.1.32.36:4567 10.1.32.49:4567 10.1.32.50:4567"

# Galera cluster name, should be the same as on the rest of the nodes.

GALERA_GROUP="XFXJ_CAIWU_CLUSTER"

# Optional Galera internal options string (e.g. SSL settings)

# see http://galeracluster.com/documentation-webpages/galeraparameters.html

# GALERA_OPTIONS=""

# Log file for garbd. Optional, by default logs to syslog

# Deprecated for CentOS7, use journalctl to query the log for garbd

LOG_FILE="/tmp/garbd.log"

3.3.启动gab服务:

root@localhost : (none) 17:57:32>show  status  like   'wsrep_cluster_size';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| wsrep_cluster_size | 2    |

+--------------------+-------+

1 row in set (0.00 sec)

[root@ory-fanxiqian-Oracle-01 ~]# /etc/init.d/garb start

其中时候你会发现集群节点数量增加了1,由2变成了3;

root@localhost : (none) 17:57:32>show  status  like   'wsrep_cluster_size';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| wsrep_cluster_size | 3     |

+--------------------+-------+

1 row in set (0.00 sec)

感谢各位的阅读,以上就是“centos6.9怎么搭建pxc集群”的内容了,经过本文的学习后,相信大家对centos6.9怎么搭建pxc集群这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI