CentOS release 6.9 Percona-XtraDB-Cluster-5.7.19-29.22.tar.gz boost_1_59_0.tar.gz percona-xtrabackup-24-2.4.7-1.el6.x86_64.rpm
節點 | mysql服務端口 | gmcast.listen端口 |
---|---|---|
node01:192.168.1.210:6600 | 6600 | 6630 |
node02:192.168.1.210:6602 | 6602 | 6632 |
node03:gardb | 無 | 5567 |
yum install -y git scons gcc gcc-c++ openssl check cmake bison \ boost-devel asio-devel libaio-devel ncurses-devel readline-devel pam-devel yum -y install libtool ncurses-devel libgcrypt-devel libev-devel \ git scons gcc gcc-c++ openssl check cmake bison boost-devel \ asio-devel libaio-devel ncurses-devel readline-devel pam-devel socat \ libaio automake autoconf vim redhat-lsb check-devel yum -y install libnl-devel openssl-devel libnfnetlink-devel ipvsadm \ popt-devel libnfnetlink kernel-devel popt-static iptraf yum install numactl libev socat perl-DBD-mysql perl-Time-HiRes 配置epel庫 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
cd /usr/local/percona-xtrabackup-2.4.5/ cmake ./ -DBUILD_CONFIG=xtrabackup_release \ -DWITH_MAN_PAGES=OFF \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST="/usr/local/boost" make -j 4 && make install
編譯安裝前最好要卸載掉本地的mysql數據庫node
rpm-qa | grep mysql (注意大小寫,若是mysql不行就換MySQL) yum -y remove mysql的包名
卸載後/var/lib/mysql中的數據及/etc/my.cnf不會刪除,若是肯定沒用後就手工刪除mysql
rm -f /etc/my.cnf rm -rf /var/lib/mysql
建立mysql用戶名及文件夾c++
mkdir /data/6600 -p mkdir /data/6602 -p mkdir /data/{6600,6602}/{binlog,slow} -p useradd mysql chown -R mysql:mysql /data/
編譯garbd,libgalera_smm.sogit
cd /usr/local/mysql cd "percona-xtradb-cluster-galera"
獲取revno值sql
cat GALERA-REVISION #revno="GALERA-REVISION" scons -j4 psi=1 --config=force revno="8678538" boost_pool=0 libgalera_smm.so scons -j4 --config=force revno="8678538" garb/garbd
建立pxc安裝目錄數據庫
mkdir -p /usr/local/mysql/{bin,lib} chown -R mysql:mysql /usr/local/mysql
拷貝編譯結果文件到pxc安裝目錄vim
cp garb/garbd /usr/local/mysql/bin cp libgalera_smm.so /usr/local/mysql/lib
檢查複製的文件是否正常api
ls -l /usr/local/mysql/bin/garbd ls -l /usr/local/mysql/lib/libgalera_smm.so
-DMYSQL_SERVER_SUFFIX 值獲取curl
cd /usr/local/Percona-XtraDB-Cluster-5.7.19-29.22 WSREP_VERSION="$(grep WSREP_INTERFACE_VERSION wsrep/wsrep_api.h | cut -d '"' -f2).$(grep 'SET(WSREP_PATCH_VERSION' "cmake/wsrep.cmake" | cut -d '"' -f2)" echo $WSREP_VERSION
-DCOMPILATION_COMMENT 值獲取socket
cd /usr/local/Percona-XtraDB-Cluster-5.7.19-29.22 source VERSION MYSQL_VERSION="$MYSQL_VERSION_MAJOR.$MYSQL_VERSION_MINOR.$MYSQL_VERSION_PATCH" echo $MYSQL_VERSION REVISION="$(cd "$SOURCEDIR"; grep '^short: ' Docs/INFO_SRC |sed -e 's/short: //')" echo "Percona XtraDB Cluster binary (GPL) $MYSQL_VERSION-$WSREP_VERSION Revision $REVISION"
編譯Percona-XtraDB-Cluster-5.7.16-27.19
cd /usr/local/mysql cmake ./ -DBUILD_CONFIG=mysql_release \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DWITH_EMBEDDED_SERVER=OFF \ -DFEATURE_SET=community \ -DENABLE_DTRACE=OFF \ -DWITH_SSL=system -DWITH_ZLIB=system \ -DCMAKE_INSTALL_PREFIX="/usr/local/mysql" \ -DMYSQL_DATADIR="/usr/local/mysql/data" \ -DMYSQL_SERVER_SUFFIX="29.22" \ -DWITH_INNODB_DISALLOW_WRITES=ON \ -DWITH_WSREP=ON \ -DWITH_UNIT_TESTS=0 \ -DWITH_READLINE=system \ -DWITHOUT_TOKUDB=ON \ -DWITHOUT_ROCKSDB=ON \ -DCOMPILATION_COMMENT="Percona XtraDB Cluster binary (GPL) 5.7.19-29.22 Revision c10027a" \ -DWITH_PAM=ON \ -DWITH_INNODB_MEMCACHED=ON \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST="/usr/local/boost" \ -DWITH_SCALABILITY_METRICS=ON make && make install
#!/bin/sh Home_Dir=/home/admin/tools Intall_Dir=/usr/local/mysql DATA_DIR=/usr/local/mysql/data export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin yum -y install libtool ncurses-devel libgcrypt-devel libev-devel \ git scons gcc gcc-c++ openssl check cmake bison boost-devel \ asio-devel libaio-devel ncurses-devel readline-devel pam-devel socat \ libaio automake autoconf redhat-lsb check-devel curl curl-devel xinetd yum -y install libnl-devel openssl-devel libnfnetlink-devel ipvsadm \ popt-devel libnfnetlink kernel-devel popt-static iptraf yum -y install numactl libev perl-DBD-mysql perl-Time-HiRes mkdir -p /usr/local/boost tar xf ${Home_Dir}/boost_1_59_0.tar.gz -C /usr/local/boost ####安裝xtrabackup我用的RPM包 rpm -ivh ${Home_Dir}/percona-xtrabackup-24-2.4.7-1.el6.x86_64.rpm tar xf ${Home_Dir}/Percona-XtraDB-Cluster-5.7.19-29.22.tar.gz mkdir -p ${Intall_Dir}/{binlog,slow} mkdir -p ${Intall_Dir}/{bin,lib} useradd mysql chown -R mysql:mysql ${Intall_Dir} cd ${Home_Dir}/Percona-XtraDB-Cluster-5.7.19-29.22 cd "percona-xtradb-cluster-galera" Revno=`cat GALERA-REVISION` scons -j4 psi=1 --config=force revno="$Revno" boost_pool=0 libgalera_smm.so scons -j4 --config=force revno="$Revno" garb/garbd cp garb/garbd ${Intall_Dir}/bin cp libgalera_smm.so ${Intall_Dir}/lib cd ${Home_Dir}/Percona-XtraDB-Cluster-5.7.19-29.22 WSREP_VERSION="$(grep WSREP_INTERFACE_VERSION wsrep/wsrep_api.h | cut -d '"' -f2).$(grep 'SET(WSREP_PATCH_VERSION' "cmake/wsrep.cmake" | cut -d '"' -f2)" source ./VERSION MYSQL_VERSION="$MYSQL_VERSION_MAJOR.$MYSQL_VERSION_MINOR.$MYSQL_VERSION_PATCH" REVISION="$(cd "$SOURCEDIR"; grep '^short: ' Docs/INFO_SRC |sed -e 's/short: //')" DCT=`echo "Percona XtraDB Cluster binary (GPL) $MYSQL_VERSION-$WSREP_VERSION Revision $REVISION"` cd ${Home_Dir}/Percona-XtraDB-Cluster-5.7.19-29.22 cmake ./ -DBUILD_CONFIG=mysql_release \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DWITH_EMBEDDED_SERVER=OFF \ -DFEATURE_SET=community \ -DENABLE_DTRACE=OFF \ -DWITH_SSL=system -DWITH_ZLIB=system \ -DCMAKE_INSTALL_PREFIX="$Intall_Dir" \ -DMYSQL_DATADIR="$DATA_DIR" \ -DMYSQL_SERVER_SUFFIX="$WSREP_VERSION" \ -DWITH_INNODB_DISALLOW_WRITES=ON \ -DWITH_WSREP=ON \ -DWITH_UNIT_TESTS=0 \ -DWITH_READLINE=system \ -DWITHOUT_TOKUDB=ON \ -DWITHOUT_ROCKSDB=ON \ -DCOMPILATION_COMMENT="$DCT" \ -DWITH_PAM=ON \ -DWITH_INNODB_MEMCACHED=ON \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST="/usr/local/boost" \ -DWITH_SCALABILITY_METRICS=ON make && make install
有關參數的詳解能夠看我上篇博客
4.1 編譯配置文件
第一個實例:6600
vim /data/6600/my.cnf [client] socket=/data/6600/mysql.sock port = 6600 default-character-set = utf8 [mysqld] socket=/data/6600/mysql.sock basedir = /data datadir = /data/6600/data port = 6600 server_id = 16600 pid-file = /data/6600/mysql_6600.pid key_buffer_size =128M max_allowed_packet = 16M table_open_cache = 512 max_connections = 200 sort_buffer_size = 20M read_buffer_size = 20M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 32M character-set-server=utf8 innodb_buffer_pool_size = 256M innodb_log_file_size = 48M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table=1 lower_case_table_names=1 innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5120M explicit_defaults_for_timestamp=TRUE sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,only_full_group_by skip-name-resolve log-bin = /data/6600/binlog/mysql-bin expire_logs_days = 7 #binlog-do-db=plateform_stable,finance_stable,location_log_stable #binlog-ignore-db=mysql,information_schema,test binlog_format=ROW log_slave_updates symbolic-links=0 default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 log-error=/data/6600/mysqld_6600-error.log wsrep_cluster_name = pxc wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_cluster_address='gcomm://192.168.1.210:6630,192.168.1.210:6632' wsrep_sst_receive_address=192.168.1.210:6620 wsrep_node_incoming_address=192.168.1.210:6600 wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.210:6030;ist.recv_addr=192.168.1.210:6631;" wsrep_slave_threads= 4 wsrep_log_conflicts wsrep_node_address=192.168.1.210:6600 #wsrep_node_name=pxc-cluster-node- wsrep_sst_method=xtrabackup-v2 #wsrep_sst_method=mysqldump wsrep_sst_auth=sstuser:sstpasswd #pxc_strict_mode=ENFORCING wsrep_log_conflicts wsrep_retry_autocommit=8 secure_file_priv="" innodb_page_cleaners=8 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash port = 6600 default-character-set = utf8 socket=/data/6600/mysql.sock [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
第二個實例:6602
[client] socket=/data/6602/mysql.sock port = 6602 default-character-set = utf8 [mysqld] socket=/data/6602/mysql.sock basedir = /data datadir = /data/6602/data port = 6602 server_id = 6602 pid-file = /data/6602/mysql_6602.pid key_buffer_size =128M max_allowed_packet = 16M table_open_cache = 512 max_connections = 200 sort_buffer_size = 20M read_buffer_size = 20M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 32M character-set-server=utf8 innodb_buffer_pool_size = 256M innodb_log_file_size = 48M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table=1 lower_case_table_names=1 innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5120M explicit_defaults_for_timestamp=TRUE sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,only_full_group_by skip-name-resolve log-bin = /data/6602/binlog/mysql-bin expire_logs_days = 7 #binlog-do-db=plateform_stable,finance_stable,location_log_stable #binlog-ignore-db=mysql,information_schema,test binlog_format=ROW log_slave_updates symbolic-links=0 default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 log-error=/data/6602/mysqld_6602-error.log wsrep_cluster_name = pxc wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_cluster_address='gcomm://192.168.1.210:6630,192.168.1.210:6632' wsrep_sst_receive_address=192.168.1.210:6622 wsrep_node_incoming_address=192.168.1.210:6602 wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.210:6632;ist.recv_addr=192.168.1.210:6633;" wsrep_slave_threads= 4 wsrep_log_conflicts wsrep_node_address=192.168.1.210:6602 #wsrep_node_name=pxc-cluster-node- wsrep_sst_method=xtrabackup-v2 #wsrep_sst_method=mysqldump wsrep_sst_auth=sstuser:sstpasswd #pxc_strict_mode=ENFORCING wsrep_log_conflicts wsrep_retry_autocommit=8 secure_file_priv="" innodb_page_cleaners=8 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash port = 6602 default-character-set = utf8 socket=/data/6602/mysql.sock [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
5.1 初始化pxc
初始化6600
chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /data/6600{,6602} /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/6600/data --user=mysql --initialize
初始化6602
/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/6602/data --user=mysql --initialize
初始化錯誤能夠清空msyql/data/目錄下的文件
注意記錄初始化密碼
5.2 啓動mysql
啓動6600實例
/usr/local/mysql/bin/mysqld --defaults-file=/data/6602/my.cnf --wsrep-new-cluster &
注意主節點啓動要加上--wsrep-new-cluster,其餘節點不用。
啓動6600實例
/usr/local/mysql/bin/mysqld --defaults-file=/data/6602/my.cnf &
5.3 更改密碼
echo "export .:/usr/local/mysql/bin:$PATH" >>/etc/profile source /etc/profile
用剛剛初始化的密碼進去MySQL實例6600
mysql -uroot -p${mypasswd} -S /data/6600/mysql.sock
第一次進去會提示改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
用剛剛初始化的密碼進去MySQL實例6602
mysql -uroot -p${mypasswd} -S /data/6602/mysql.sock
第一次進去會提示改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
5.4 爲wsrep_sst_auth傳輸建立用戶
隨便選擇一個節點建立
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstpassword'; mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost'; mysql> FLUSH PRIVILEGES;
pxc集羣最少是要3臺,仲裁者garbd,用來解決
cd /usr/local/mysql/bin/ ./garbd --group=pxc-cluster --address=gcomm://192.168.1.210:6630,192.168.1.210:6632 --option=gmcast.listen_addr=tcp://192.168.1.210:5567 -d -l /tmp/garbd.log #所有起完了以後就能夠看到節點數和集羣
#查看MySQL 節點數 mysql> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec)
是三個表示pxc集羣搭建成功,能夠在一個節點上建立一張表,其餘節點能夠查詢的到說明集羣運行正常。
查看進程數
ps -ef|grep mysql mysql 14316 1 0 Jun28 ? 00:06:18 /usr/local/mysql/bin/mysqld --defaultsfile=/data/6600/my.cnf --wsrep-new-cluster mysql 15611 1 0 Jun28 ? 00:03:37 /usr/local/mysql/bin/garbd --group=pxc --address=gcomm://192.168.1.210:6630,192.168.1.210:6632 --option=gmcast.listen_addr=tcp://192.168.1.210:5567 -d -l /tmp/garbd.log mysql 23001 1 0 Jun29 ? 00:04:55 /usr/local/mysql/bin/mysqld --defaults-file=/data/6602/my.cnf