MySQL集群PXC的搭建
MySQL集群PXC的搭建
最近公司某客户要求我们的数据库搭建PXC集群以保证他们的系统高性能和搞稳定性
以后花费了一些时间去搭建和测试,也踩过一些坑,准备分享出来
系统:centos6.6
PXC:5.6.26
建议关闭iptables, 4个端口 3306,4444,4567,4568
pxc环境所涉及的端口:
#mysql实例端口:3306.
#pxc cluster相互通讯的端口:4567
Port for group communication, default 4567. It can be changed by the option:
wsrep_provider_options ="gmcast.listen_addr=tcp://0.0.0.0:4010; "
#用于SST传送的端口:4444
Port for State Transfer, default 4444. It can be changed by the option:
wsrep_sst_receive_address=10.11.12.205:5555
#用于IST传送的端口:4568
Port for Incremental State Transfer, default port for group communication + 1 (4568). It can be changed by the option:
wsrep_provider_options = "ist.recv_addr=10.11.12.206:7777; "
node1 192.168.3.130
node2 192.168.3.129
node3 192.168.3.128
1.安装软件依赖包(添加repl源,再安装依赖,3台server操作一样。)
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes socat nc -y
2.安装xtrabackup(PXC同步数据需要用到)
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
3.下载安装Percona-XtraDB-Cluster
#安装开发包
yum install -y libaio* yum groupinstall -y 'Development tools' /usr/lib64/libssl.so. /usr/lib64/libcrypto.so. wget https://www.percona.com/downloads/Percona-XtraDB-Cluster-56/Percona-XtraDB-Cluster-5.6.26-25.12/binary/tarball/Percona-XtraDB-Cluster-5.6.26-rel74.0-25.12.1.Linux.x86_64.tar.gz -rel74.-.Linux.x86_64.tar.gz useradd -M -s /sbin/nologin mysql mkdir -p /usr/local/pxc mkdir -p /data/pxc/mysql3306/{data,tmp,logs} -rel74.-.Linux.x86_64/* /usr/local/pxc/ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile source /etc/profile chown -R mysql:mysql /data/pxc/mysql3306/ chown -R mysql:mysql /usr/local/pxc
修改my.cnf配置文件,注意在[mysqld]段落添加PXC的参数:
vi /etc/my.cnf
130
[client] port = socket = /data/mysql/mysql3306/tmp/mysql.sock # The MySQL server [mysqld] #########Basic################## explicit_defaults_for_timestamp=true port = user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3306/data tmpdir = /data/mysql/mysql3306/tmp pid-file = /data/mysql/mysql3306/tmp/mysql.pid socket = /data/mysql/mysql3306/tmp/mysql.sock #skip-grant-tables #character set character_set_server = utf8 open_files_limit = back_log = #event_scheduler = ON #lower_case_table_names= skip-external-locking skip_name_resolve = default-storage-engine = InnoDB #timeout wait_timeout= interactive_timeout= connect_timeout = server- #ip最后一位+端口号= #percona 的--recursion-method slavehost模式 #report_host = 10.105.9.115 #report_port = #plugin plugin-load="semisync_master.so;semisync_slave.so" #########error log############# log-error = /data/mysql/mysql3306/logs/error.log log-warnings = #########general log############# #general_log= #general_log_file=/data/mysql/mysql3306/logs/mysql.log #########slow log############# slow_query_log = long_query_time= slow_query_log_file = /data/mysql/mysql3306/logs/mysql.slow ############# for replication################### log-bin = /data/mysql/mysql3306/logs/mysql-bin binlog_format = row max_binlog_size = 500M binlog_cache_size = 2M max_binlog_cache_size = 2M expire-logs-days = slave-net-timeout= log_bin_trust_function_creators = log-slave-updates = skip-slave-start = #read_only = #从上设置,.7是super_read_only #GTID gtid-mode = on binlog_gtid_simple_recovery= enforce_gtid_consistency= #relay log relay-log = /data/mysql/mysql3306/logs/mysql-relay relay-log-index=/data/mysql/mysql3306/logs/relay-bin.index max-relay-log-size = 500M #replication crash safe sync_master_info = sync_relay_log_info = sync_relay_log = relay_log_recovery = master_info_repository = TABLE relay_log_info_repository = TABLE #semisync 动态开启 主从切换的时候用 #rpl_semi_sync_master_enabled = #rpl_semi_sync_master_wait_no_slave = #rpl_semi_sync_master_timeout = #rpl_semi_sync_slave_enabled = #rpl_semi_sync_master_timeout = #不要超时,防止切异步,保证主从数据的完全一致性,默认是10000 #rpl_semi_sync_master_wait_point = .7新增参数 after_sync .7增强半同步 after_commit5.6普通半同步 #rpl_semi_sync_master_wait_for_slave_count = #.7新增参数 等待多少个从库接收到binlog #ignore #replicate-ignore-db = 'school','school2' #replicate-do-db = 'school','school2' #Multi-threaded Slave #slave_parallel_workers= #slave-parallel-type=LOGICAL_CLOCK #slave-parallel-type=DATABASE #replication error #slave-skip-errors=,, #######per_thread_buffers##################### max_connections= max_user_connections= max_connect_errors= #myisam_recover key_buffer_size = 64M max_allowed_packet = 16M #table_cache = table_open_cache = table_definition_cache = read_buffer_size = 1M join_buffer_size = 128K read_rnd_buffer_size = 1M #myisam sort_buffer_size = 128K myisam_max_sort_file_size = 10G myisam_repair_threads = myisam_sort_buffer_size = 32M tmp_table_size = 32M max_heap_table_size = 64M query_cache_type= query_cache_size = bulk_insert_buffer_size = 32M thread_cache_size = #thread_concurrency = thread_stack = 192K ###############InnoDB########################### innodb_data_home_dir = /data/mysql/mysql3306/data innodb_log_group_home_dir = /data/mysql/mysql3306/logs innodb_data_file_path = ibdata1:1000M:autoextend innodb_buffer_pool_size = 1G #根据内存大小设置 innodb_buffer_pool_instances = #innodb_additional_mem_pool_size = 16M innodb_log_file_size = 500M innodb_log_buffer_size = 16M innodb_log_files_in_group = innodb_flush_log_at_trx_commit = sync_binlog = innodb_lock_wait_timeout = innodb_sync_spin_loops = innodb_max_dirty_pages_pct = innodb_support_xa = innodb_thread_concurrency = innodb_thread_sleep_delay = innodb_concurrency_tickets = innodb_flush_method = O_DIRECT innodb_file_per_table = innodb_read_io_threads = innodb_write_io_threads = innodb_io_capacity = #机械盘800 ssd innodb_flush_neighbors = innodb_file_format = Barracuda innodb_purge_threads= #.6只能有一个,.7可以设置多个 innodb_purge_batch_size = innodb_old_blocks_pct= innodb_change_buffering=all innodb_stats_on_metadata=OFF innodb_print_all_deadlocks = #innodb_status_output= #innodb_status_output_locks= performance_schema= #是否打开P_S库进行性能收集 transaction_isolation = READ-COMMITTED #innodb_force_recovery= #innodb_fast_shutdown= #innodb_status_file = #实时输出show engine innodb status到innodb_status文件 ############# PXC ##################### innodb_autoinc_lock_mode= #自增锁的优化 wsrep_cluster_name=pxc-dongzheng #集群名字 wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so #库文件位置 wsrep_cluster_address=gcomm://192.168.3.130,192.168.3.128,192.168.3.129 #节点中所有ip wsrep_node_address=192.168.3.130 #本节点的ip wsrep_slave_threads= # 开启的复制线程数,建议cpu核数* ,解决apply_cb跟不上问题 wsrep_sst_auth=sst:dongzheng #sst模式需要的用户名和密码 wsrep_sst_method=xtrabackup-v2 #采用什么方式复制数据。还支持mysqldump,rsync #wsrep_provider_options="debug=1;gcache.size=2G;pc.ignore_quorum=true;pc.ignore_sb=true" #打开调试模式 wsrep_provider_options="debug=1;gcache.size=2G;" wsrep_max_ws_rows= wsrep_max_ws_size= [mysqldump] quick max_allowed_packet = 128M [mysql] no-auto-rehash max_allowed_packet = 128M prompt = '(product)\u@\h:\p [\d]> ' default_character_set = utf8 [myisamchk] key_buffer_size = 64M sort_buffer_size = 512k read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [mysqld_safe] #malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so
129
[client] port = socket = /data/mysql/mysql3306/tmp/mysql.sock # The MySQL server [mysqld] #########Basic################## explicit_defaults_for_timestamp=true port = user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3306/data tmpdir = /data/mysql/mysql3306/tmp pid-file = /data/mysql/mysql3306/tmp/mysql.pid socket = /data/mysql/mysql3306/tmp/mysql.sock #skip-grant-tables #character set character_set_server = utf8 open_files_limit = back_log = #event_scheduler = ON #lower_case_table_names= skip-external-locking skip_name_resolve = default-storage-engine = InnoDB #timeout wait_timeout= interactive_timeout= connect_timeout = server- #ip最后一位+端口号= #percona 的--recursion-method slavehost模式 #report_host = 10.105.9.115 #report_port = #plugin plugin-load="semisync_master.so;semisync_slave.so" #########error log############# log-error = /data/mysql/mysql3306/logs/error.log log-warnings = #########general log############# #general_log= #general_log_file=/data/mysql/mysql3306/logs/mysql.log #########slow log############# slow_query_log = long_query_time= slow_query_log_file = /data/mysql/mysql3306/logs/mysql.slow ############# for replication################### log-bin = /data/mysql/mysql3306/logs/mysql-bin binlog_format = row max_binlog_size = 500M binlog_cache_size = 2M max_binlog_cache_size = 2M expire-logs-days = slave-net-timeout= log_bin_trust_function_creators = log-slave-updates = skip-slave-start = #read_only = #从上设置,.7是super_read_only #GTID gtid-mode = on binlog_gtid_simple_recovery= enforce_gtid_consistency= #relay log relay-log = /data/mysql/mysql3306/logs/mysql-relay relay-log-index=/data/mysql/mysql3306/logs/relay-bin.index max-relay-log-size = 500M #replication crash safe sync_master_info = sync_relay_log_info = sync_relay_log = relay_log_recovery = master_info_repository = TABLE relay_log_info_repository = TABLE #semisync 动态开启 主从切换的时候用 #rpl_semi_sync_master_enabled = #rpl_semi_sync_master_wait_no_slave = #rpl_semi_sync_master_timeout = #rpl_semi_sync_slave_enabled = #rpl_semi_sync_master_timeout = #不要超时,防止切异步,保证主从数据的完全一致性,默认是10000 #rpl_semi_sync_master_wait_point = .7新增参数 after_sync .7增强半同步 after_commit5.6普通半同步 #rpl_semi_sync_master_wait_for_slave_count = #.7新增参数 等待多少个从库接收到binlog #ignore #replicate-ignore-db = 'school','school2' #replicate-do-db = 'school','school2' #Multi-threaded Slave #slave_parallel_workers= #slave-parallel-type=LOGICAL_CLOCK #slave-parallel-type=DATABASE #replication error #slave-skip-errors=,, #######per_thread_buffers##################### max_connections= max_user_connections= max_connect_errors= #myisam_recover key_buffer_size = 64M max_allowed_packet = 16M #table_cache = table_open_cache = table_definition_cache = read_buffer_size = 1M join_buffer_size = 128K read_rnd_buffer_size = 1M #myisam sort_buffer_size = 128K myisam_max_sort_file_size = 10G myisam_repair_threads = myisam_sort_buffer_size = 32M tmp_table_size = 32M max_heap_table_size = 64M query_cache_type= query_cache_size = bulk_insert_buffer_size = 32M thread_cache_size = #thread_concurrency = thread_stack = 192K ###############InnoDB########################### innodb_data_home_dir = /data/mysql/mysql3306/data innodb_log_group_home_dir = /data/mysql/mysql3306/logs innodb_data_file_path = ibdata1:1000M:autoextend innodb_buffer_pool_size = 1G #根据内存大小设置 innodb_buffer_pool_instances = #innodb_additional_mem_pool_size = 16M innodb_log_file_size = 500M innodb_log_buffer_size = 16M innodb_log_files_in_group = innodb_flush_log_at_trx_commit = sync_binlog = innodb_lock_wait_timeout = innodb_sync_spin_loops = innodb_max_dirty_pages_pct = innodb_support_xa = innodb_thread_concurrency = innodb_thread_sleep_delay = innodb_concurrency_tickets = innodb_flush_method = O_DIRECT innodb_file_per_table = innodb_read_io_threads = innodb_write_io_threads = innodb_io_capacity = #机械盘800 ssd innodb_flush_neighbors = innodb_file_format = Barracuda innodb_purge_threads= #.6只能有一个,.7可以设置多个 innodb_purge_batch_size = innodb_old_blocks_pct= innodb_change_buffering=all innodb_stats_on_metadata=OFF innodb_print_all_deadlocks = #innodb_status_output= #innodb_status_output_locks= performance_schema= #是否打开P_S库进行性能收集 transaction_isolation = READ-COMMITTED #innodb_force_recovery= #innodb_fast_shutdown= #innodb_status_file = #实时输出show engine innodb status到innodb_status文件 ############# PXC ##################### innodb_autoinc_lock_mode= wsrep_cluster_name=pxc-dongzheng wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_cluster_address=gcomm://192.168.3.130,192.168.3.128,192.168.3.129 wsrep_node_address=192.168.3.129 wsrep_slave_threads= wsrep_sst_auth=sst:dongzheng wsrep_sst_method=xtrabackup-v2 #wsrep_provider_options="debug=1;gcache.size=2G;pc.ignore_quorum=true;pc.ignore_sb=true" #打开调试模式 wsrep_provider_options="debug=1;gcache.size=2G;" wsrep_max_ws_rows= wsrep_max_ws_size= [mysqldump] quick max_allowed_packet = 128M [mysql] no-auto-rehash max_allowed_packet = 128M prompt = '(product)\u@\h:\p [\d]> ' default_character_set = utf8 [myisamchk] key_buffer_size = 64M sort_buffer_size = 512k read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [mysqld_safe] #malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so
128
[client] port = socket = /data/mysql/mysql3306/tmp/mysql.sock # The MySQL server [mysqld] #########Basic################## explicit_defaults_for_timestamp=true port = user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3306/data tmpdir = /data/mysql/mysql3306/tmp pid-file = /data/mysql/mysql3306/tmp/mysql.pid socket = /data/mysql/mysql3306/tmp/mysql.sock #skip-grant-tables #character set character_set_server = utf8 open_files_limit = back_log = #event_scheduler = ON #lower_case_table_names= skip-external-locking skip_name_resolve = default-storage-engine = InnoDB #timeout wait_timeout= interactive_timeout= connect_timeout = server- #ip最后一位+端口号= #percona 的--recursion-method slavehost模式 #report_host = 10.105.9.115 #report_port = #plugin plugin-load="semisync_master.so;semisync_slave.so" #########error log############# log-error = /data/mysql/mysql3306/logs/error.log log-warnings = #########general log############# #general_log= #general_log_file=/data/mysql/mysql3306/logs/mysql.log #########slow log############# slow_query_log = long_query_time= slow_query_log_file = /data/mysql/mysql3306/logs/mysql.slow ############# for replication################### log-bin = /data/mysql/mysql3306/logs/mysql-bin binlog_format = row max_binlog_size = 500M binlog_cache_size = 2M max_binlog_cache_size = 2M expire-logs-days = slave-net-timeout= log_bin_trust_function_creators = log-slave-updates = skip-slave-start = #read_only = #从上设置,.7是super_read_only #GTID gtid-mode = on binlog_gtid_simple_recovery= enforce_gtid_consistency= #relay log relay-log = /data/mysql/mysql3306/logs/mysql-relay relay-log-index=/data/mysql/mysql3306/logs/relay-bin.index max-relay-log-size = 500M #replication crash safe sync_master_info = sync_relay_log_info = sync_relay_log = relay_log_recovery = master_info_repository = TABLE relay_log_info_repository = TABLE #semisync 动态开启 主从切换的时候用 #rpl_semi_sync_master_enabled = #rpl_semi_sync_master_wait_no_slave = #rpl_semi_sync_master_timeout = #rpl_semi_sync_slave_enabled = #rpl_semi_sync_master_timeout = #不要超时,防止切异步,保证主从数据的完全一致性,默认是10000 #rpl_semi_sync_master_wait_point = .7新增参数 after_sync .7增强半同步 after_commit5.6普通半同步 #rpl_semi_sync_master_wait_for_slave_count = #.7新增参数 等待多少个从库接收到binlog #ignore #replicate-ignore-db = 'school','school2' #replicate-do-db = 'school','school2' #Multi-threaded Slave #slave_parallel_workers= #slave-parallel-type=LOGICAL_CLOCK #slave-parallel-type=DATABASE #replication error #slave-skip-errors=,, #######per_thread_buffers##################### max_connections= max_user_connections= max_connect_errors= #myisam_recover key_buffer_size = 64M max_allowed_packet = 16M #table_cache = table_open_cache = table_definition_cache = read_buffer_size = 1M join_buffer_size = 128K read_rnd_buffer_size = 1M #myisam sort_buffer_size = 128K myisam_max_sort_file_size = 10G myisam_repair_threads = myisam_sort_buffer_size = 32M tmp_table_size = 32M max_heap_table_size = 64M query_cache_type= query_cache_size = bulk_insert_buffer_size = 32M thread_cache_size = #thread_concurrency = thread_stack = 192K ###############InnoDB########################### innodb_data_home_dir = /data/mysql/mysql3306/data innodb_log_group_home_dir = /data/mysql/mysql3306/logs innodb_data_file_path = ibdata1:1000M:autoextend innodb_buffer_pool_size = 1G #根据内存大小设置 innodb_buffer_pool_instances = #innodb_additional_mem_pool_size = 16M innodb_log_file_size = 500M innodb_log_buffer_size = 16M innodb_log_files_in_group = innodb_flush_log_at_trx_commit = sync_binlog = innodb_lock_wait_timeout = innodb_sync_spin_loops = innodb_max_dirty_pages_pct = innodb_support_xa = innodb_thread_concurrency = innodb_thread_sleep_delay = innodb_concurrency_tickets = innodb_flush_method = O_DIRECT innodb_file_per_table = innodb_read_io_threads = innodb_write_io_threads = innodb_io_capacity = #机械盘800 ssd innodb_flush_neighbors = innodb_file_format = Barracuda innodb_purge_threads= #.6只能有一个,.7可以设置多个 innodb_purge_batch_size = innodb_old_blocks_pct= innodb_change_buffering=all innodb_stats_on_metadata=OFF innodb_print_all_deadlocks = #innodb_status_output= #innodb_status_output_locks= performance_schema= #是否打开P_S库进行性能收集 transaction_isolation = READ-COMMITTED #innodb_force_recovery= #innodb_fast_shutdown= #innodb_status_file = #实时输出show engine innodb status到innodb_status文件 ############# PXC ##################### innodb_autoinc_lock_mode= wsrep_cluster_name=pxc-dongzheng wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_cluster_address=gcomm://192.168.3.130,192.168.3.128,192.168.3.129 wsrep_node_address=192.168.3.128 wsrep_slave_threads= wsrep_sst_auth=sst:dongzheng wsrep_sst_method=xtrabackup-v2 #wsrep_provider_options="debug=1;gcache.size=2G;pc.ignore_quorum=true;pc.ignore_sb=true" #打开调试模式 wsrep_provider_options="debug=1;gcache.size=2G;" wsrep_max_ws_rows= wsrep_max_ws_size= [mysqldump] quick max_allowed_packet = 128M [mysql] no-auto-rehash max_allowed_packet = 128M prompt = '(product)\u@\h:\p [\d]> ' default_character_set = utf8 [myisamchk] key_buffer_size = 64M sort_buffer_size = 512k read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [mysqld_safe] #malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so
cd /usr/local/pxc/ ./scripts/mysql_install_db --defaults-file=/etc/my.cnf
看到两次ok
#修改启动脚本
vi /etc/init.d/mysql
basedir=/usr/local/pxc datadir=/data/pxc/mysql3306/data
4.启动,进行授权操作,对于第一个节点必须以特殊方式启动,如下:
/etc/init.d/mysql --help Usage: mysql {start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc} [ MySQL (Percona XtraDB Cluster) options ]
第一个节点启动
/etc/init.d/mysql bootstrap-pxc
5.安全加固
连接mysql:mysql -uroot -p -S /data/mysql/mysql3306/tmp/mysql.sock
delete from mysql.user where user!='root' or host!='localhost';
truncate table mysql.db;
drop database test;
进行授权,这里用户名密码是my.cnf里定义的用户名sst 密码dongzheng
GRANT ALL PRIVILEGES ON *.* TO 'sst'@'%' identified by 'dongzheng';
use mysql;
UPDATE user SET password=PASSWORD('123456') WHERE user='root';
flush privileges;
PXC状态确认
show global status like 'wsrep%';
6.netstat进行查看,可以发现启动两个端口
netstat -lntp | grep mysql
tcp 0 0 0.0.0.0:4567 0.0.0.0:* LISTEN 2964/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2964/mysqld
另外两个节点的启动和配置
node2 my.cnf的PXC 配置节:
############# PXC #####################
innodb_autoinc_lock_mode=2 #自增锁的优化
wsrep_cluster_name=pxc-dongzheng #集群名字
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so #库文件
wsrep_cluster_address=gcomm://192.168.2.130,192.168.3.128,192.168.0.129 #节点中所有ip
wsrep_node_address=192.168.0.129 #节点的ip
wsrep_slave_threads=2 #开启的复制线程数,cpu核数*2
wsrep_sst_auth=sst:dongzheng #sst模式需要的用户名和密码
wsrep_sst_method=xtrabackup-v2 #采用什么方式复制数据。还支持mysqldump,rsync
wsrep_provider_options="debug=1;socket.checksum=1" #打开调试模式
node3 my.cnf的PXC 配置节:
############# PXC #####################
innodb_autoinc_lock_mode=2 #自增锁的优化
wsrep_cluster_name=pxc-dongzheng #集群名字
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so #库文件
wsrep_cluster_address=gcomm://192.168.2.130,192.168.3.128,192.168.0.129 #节点中所有ip
wsrep_node_address=192.168.0.128 #节点的ip
wsrep_slave_threads=2 #开启的复制线程数,cpu核数*2
wsrep_sst_auth=sst:dongzheng #sst模式需要的用户名和密码
wsrep_sst_method=xtrabackup-v2 #采用什么方式复制数据。还支持mysqldump,rsync
wsrep_provider_options="debug=1;socket.checksum=1" #打开调试模式
启动
/etc/init.d/mysql start
启动的时候会把主节点的所有数据传送过从节点包括所有数据库和日志,简单来讲从节点在启动的时候会做SST同步
从节点不需要做安全加固,因为从节点跟主节点的数据库和数据都一样
PXC状态确认
show global status like 'wsrep%';
netstat进行查看,可以发现启动两个端口
netstat -lntp | grep mysql
tcp 0 0 0.0.0.0:4567 0.0.0.0:* LISTEN 2964/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2964/mysqld
###############################################################
集群关闭
所有节点都用
/etc/init.d/mysql stop
节点重启
第一个节点用:/etc/init.d/mysql restart-bootstrap
其他节点用:/etc/init.d/mysql restart
集群关闭之后,再启动,谁做第一个节点谁就执行/etc/init.d/mysql bootstrap-pxc
如果不是所有节点都关闭,那么当启动集群节点的时候不需要执行/etc/init.d/mysql bootstrap-pxc
/etc/init.d/mysql --help
Usage: mysql {start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc} [ MySQL (Percona XtraDB Cluster) options ]
到这里搭建就基本结束了。3个节点同时支持read/write操作。
新加入节点
只需要安装好Percona-XtraDB-Cluster,并且在 my.cnf 添加PXC 配置节即可
报错处理
(1)加载 so 文件加不到
如:
Installing MySQL system tables... /usr/local/mysql/bin/mysqld: error : cannot open shared object file: No such file or directory
可能的问题:
openssl 没装:
yum install –y openssl openssl-devel
如果提示已经安装,可以使用
updatedb locate libssl.so
然后用
ldd /usr/local/mysql/bin/mysqld
查看还有那些依赖需安装
确认一下:
看样子都是存在的,但版本不对。做一个软链就可以修复了。
#cd /usr/lib64/
最后在用ldd /usr/local/mysql/bin/mysqld 去确认是否有没加载的so, 如果存在同样的方法修复。
(2)安装中 socat 找不到
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my3307.cnf --ledir=/usr/local/pxc_56/bin/ & 有可能启动会提示: WSREP_SST: [ERROR] socat not found in path: /usr/sbin:/sbin:/usr/local/pxc_56//bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/lamp/mysql/bin:/root/bi n ( ::04.404) -- :: [ERROR] WSREP: Failed to read 'ready <addr>' from: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.1.238' --datadir '/home/mysql/I3307/ '' '' Read: '(null)' -- :: [ERROR] WSREP: Process completed with error: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.1.238' --datadir '/home/mysql/I3307/' --de faults- (No such file or directory) -- :: [ERROR] WSREP: Failed to prepare for 'xtrabackup-v2' SST. Unrecoverable. -- :: [ERROR] Aborting
socat 包没装上,可以把epel 的源加入就可以安装。
yum install -y socat
因为在my.cnf里写错ip,导致出现下面错误,改正my.cnf就可以了
wsrep_cluster_address=gcomm://192.168.2.130,192.168.3.128,192.168.0.129
wsrep_node_address=192.168.1.130
-- :: [ERROR] WSREP: failed to open gcomm backend connection: : failed to reach primary view: (Connection timed out) at gcomm/src/pc. -- :: [ERROR] WSREP: gcs/src/gcs_core.: Failed to open backend connection: - (Connection timed out) -- :: [ERROR] WSREP: gcs/src/gcs.: Failed to open channel (Connection timed out) -- :: [ERROR] WSREP: gcs connect failed: Connection timed out -- :: [ERROR] WSREP: wsrep::connect(gcomm://192.168.2.130,192.168.3.128,192.168.0.129) failed: 7 -- :: [ERROR] Aborting
关于PXC版本
如果是安装5.6.24版本或以上的需要下载openssl
centos6和centos7需要openssl版本1.0
https://www.percona.com/doc/percona-server/5.6/installation.html#installing-percona-server-from-a-binary-tarball
In Percona Server 5.6.24-72.2 and newer, the single binary tarball was replaced with multiple tarballs depending on the OpenSSL library available in the distribution:
ssl100 - for all Debian/Ubuntu versions except Debian Squeeze (libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f2e389a5000));
ssl098 - only for Debian Squeeze (libssl.so.0.9.8 => /usr/lib/libssl.so.0.9.8 (0x00007f9b30db6000));
ssl101 - for CentOS 6 and CentOS 7 (libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007facbe8c4000));
ssl098e - to be used only for CentOS 5 (libssl.so.6 => /lib64/libssl.so.6 (0x00002aed5b64d000)).
下载地址
https://www.percona.com/downloads/Percona-XtraDB-Cluster-56/LATEST/binary/tarball/
运维注意
(1)不能同时关闭所有节点,原则要保持Group里最少一个成员活着,否则全部传SST不能同时关闭所有节点,原则要保持Group里最少一个成员活着,否则全部传SST,gcache丢失
(2)node1 是整个集群的老大
其它节点加进来发现数据不一致,以老大为准
会有丢数据风险
(3)其中一个节点死掉了,还有2个节点
发现整个集群还能活,要设置忽略脑裂
忽略脑裂的命令
SET GLOBAL wsrep_provider_options="pc.ignore_sb=true;pc.ignore_quorum=true";
(4)最好单节点写入,不然更新同一行记录会出问题
(5)尽量用pt-online-schema-change 做表结构变更
(6)mysql库全是MyISAM引擎不能复制
MyISAM引擎不能被复制,PXC只支持Innodb
DCL语句可以复制: create user, drop user, grant ,revoke
(7)整个集群节点数最好为3,最多是8个
(8)pxc结构里面每个表必须有主键
(9)writeSet的大小
下面两个参数控制写入集大小
wsrep_max_ws_rows 没有默认值,默认没有限制
wsrep_max_ws_size 默认单位字节,建议不要超过16KB,16000
my.cnf
wsrep_max_ws_rows=131072
wsrep_max_ws_size=16000
允许最大的事务大小由wsrep_max_ws_rows和wsrep_max_ws_size定义,超过这个大小事务会被抛弃
LOAD DATA INFILE ...每1万行提交一次.对于LOAD DATA中的大事务会被分割成多个小事务来执行.
参考文章:
http://www.cnblogs.com/zejin2008/p/5475285.html
https://www.percona.com/doc/percona-xtradb-cluster/5.6/wsrep-provider-index.html
https://www.percona.com/doc/percona-xtradb-cluster/5.6/wsrep-system-index.html
http://galeracluster.com/documentation-webpages/monitoringthecluster.html
如有不对的地方,欢迎大家拍砖o(∩_∩)o
本文版权归作者所有,未经作者同意不得转载。
MySQL集群PXC的搭建的更多相关文章
- MySQL集群-PXC搭建以及使用innobackupex工具进行全局备份和增量备份
环境:centos7 vm1:10.154.47.236 vm2:10.154.52.189 vm3:10.105.12.50 目的:pxc使用三个节点构建mysql集群,使用innobackupex ...
- MySQL集群---②Windows平台搭建MySQL CLUSTER集群
原文:http://blog.csdn.net/mazhaojuan/article/details/42211857 本文将通过两台电脑来简单介绍一下Windows平台如何搭建MySQL集群. My ...
- 关于mysql集群主从服务器搭建
在高并发流量下,数据库往往是服务端的瓶颈,由于数据库数据需要确保落地,同时保证数据同步,数据即时性,有效性的问题,导致数据库不能像平常后端程序一样负载均衡. 那么在大并发下,该如何缓解数据库的压力呢? ...
- MySQL集群(PXC)入门
一.学习动机 伴随互联网行业的兴起,越来越多的领域需要相应的技术方案,比如:打出软件.电商平台.直播平台.电子支付.媒体社交. 身边常见的,校园出成绩那一年,我们会感觉网站异常的卡顿,因为访问人数太多 ...
- 搭建MySQL集群-注意版本
系统环境采样(来自其他机器,直接copy过来的,在安装的机器上,按照步骤查看即可,当然这些还不够实际,后续补充) 检查系统内是否有其他mysql rpm -qa | grep mysql 是否存在my ...
- mysql集群安装配置
看网上很多人说mysql集群不是很稳定,因此这2天做了下mysql的集群,打算配置没有什么问题了,过2天做下相关的性能测试,我的配置环境如下: 操作系统: Centos5.2 软件 ...
- MySQL集群搭建方案(PXC)
服务器快过期了,清一点库存,把运维这块的知识复习下 为什么要搭MySQL集群 技术层面上,传统的单节点数据库,万一宕机了,就凉凉了.容灾性能差.抗并发能力有限,数据量大的时候查询有瓶颈.学习层面上,作 ...
- 超详细干货!Docker+PXC+Haproxy搭建高可用强一致性的MySQL集群
前言 干货又来了,全程无废话,可先看目录了解. MySQL搭建集群最常见的是binlog方式,但还有一种方式是强一致性的,能保证集群节点的数据一定能够同步成功,这种方式就是pxc,本篇就使用图文方式一 ...
- Docker环境下的前后端分离项目部署与运维(六)搭建MySQL集群
单节点数据库的弊病 大型互联网程序用户群体庞大,所以架构必须要特殊设计 单节点的数据库无法满足性能上的要求 单节点的数据库没有冗余设计,无法满足高可用 单节点MySQL的性能瓶领颈 2016年春节微信 ...
随机推荐
- TCP/IP协议栈 -----链路层
这节说一下链路层和ARP RARP协议 链路层: 在协议栈中链路层的目的有三个:1. 为IP模块发送或接受数据包 2.为ARP模块发送或接受ARP请求 3. 为RARP模块发送或接受RARP请求. 让 ...
- Vue单页面骨架屏实践
github 地址: VV-UI/VV-UI 演示地址: vv-ui 文档地址:skeleton 关于骨架屏介绍 骨架屏的作用主要是在网络请求较慢时,提供基础占位,当数据加载完成,恢复数据展示.这样给 ...
- docker、oci、runc以及kubernetes梳理
容器无疑是近年来云计算中最火热的关键词.随着docker的大热,docker.oci.runc.containerd等等名词也逐渐传播开来.这么多的名词,也容易让人混淆.本文对相关名词和其之间的联系进 ...
- Gitlab一键端的安装汉化及问题解决(2017/12/14目前版本为10.2.4)
Gitlab的安装汉化及问题解决 一.前言 Gitlab需要安装的包太TM多了,源码安装能愁死个人,一直出错,后来发现几行命令就装的真是遇到的新大陆一样... ... 装完之后感觉太简单,加了汉化补丁 ...
- springmvc对于JSON对象的处理
1.常见的json jar包,及其优缺点(开发中可以一起使用) json-lib 缺点:依赖第三方的包 jackson SpringMVC内置的json装换工具,依赖包较少 GSON ...
- 什么是BSD?
BSD (Berkeley Software Distribution,伯克利软件套件)是Unix的衍生系统,1970年代由加州大学伯克利分校开创.BSD用来代表由此派生出的各种套件集合. BS ...
- Web Api 基于Zookeeper的服务注册与发现
安装与差异 Zookeeper安装请参考我上篇文章 http://www.cnblogs.com/woxpp/p/7700368.html 基于Nginx的服务提供和消费 基于zookeeper的服务 ...
- 家居环境监測系统设计(PC上位机版)(手机APP版待定)
下面是我的毕业设计:家居环境监測系统设计(PC上位机临时版.手机app版待定).本系统採用STC12C5A60S2单片机.结合传感器.分别对空气湿度.空气温度.气压.海拔.进水温度.出水温度.光照强度 ...
- Java并发与同步
Java中并发的形式无非是多线程和多进程两种形式.这两种形式都是能够利用多核来发挥计算能力的. 先说并发: 多进程意味着同一时候执行多个JVM.这个代价通常比多线程高,每一个JVM都有自己的堆栈.都要 ...
- tomcat启动失败的一种可能性
今天搭建一个新的项目,采用spring+hibernate框架,项目框架搭建完成以后,启动tomcat,报错,如下图. 第一反应是tomcat的问题,于是clean了tomcat,没用,再把tomca ...