您好,登錄后才能下訂單哦!
環境:
操作系統centos7.4,mysql 安裝在/data/mysql下,mysql屬于mysql用戶,pxc-5.7.19
1.1 下載pxc-5.7.19
mkdir -p /home/sunx/tools
wget -P /home/sunx/tools
https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/Percona-XtraDB-Cluster-5.7.19-29.22/source/tarball/Percona-XtraDB-Cluster-5.7.19-29.22.tar.gz
1. 2 下載boost
mkdir -p /usr/local/boost
wget -P /usr/local/boost https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download
1.3 下載percona-xtrabackup-2.4.5
wget -P /home/sunx/tools https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.5/source/tarball/percona-xtrabackup-2.4.5.tar.gz
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-develyum -y install libnl-devel openssl-devel libnfnetlink-devel ipvsadm \
popt-devel libnfnetlink kernel-devel popt-static iptrafyum -y install numactl libev perl-DBD-mysql perl-Time-HiRes
配置epel庫
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.1 編譯安裝percona-xtrabackup
cd /usr/local/src/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
3.2 編譯安裝Percona-XtraDB-Cluster-5.7.19-29.22
編譯安裝前最好要卸載掉本地的mysql數據庫
rpm-qa | grep mysql (注意大小寫,如果mysql不行就換MySQL)
yum -y remove mysql的包名
卸載后/var/lib/mysql中的數據及/etc/my.cnf不會刪除,如果確定沒用后就手工刪除
rm -f /etc/my.cnf
rm -rf /var/lib/mysql
創建mysql用戶名及文件夾
mkdir /data/mysql
ln -s /data/mysql /usr/local/mysql
mkdir /usr/local/mysql/{binlog,slow} -p
useradd mysql
chown -R mysql:mysql /usr/local/mysql
編譯garbd,libgalera_smm.so
cd /usr/local/mysql
cd "percona-xtradb-cluster-galera"
獲取revno值
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}
拷貝編譯結果文件到pxc安裝目錄
cp garb/garbd /usr/local/mysql/bin
cp libgalera_smm.so /usr/local/mysql/lib
檢查復制的文件是否正常
ls -l /usr/local/mysql/bin/garbd
ls -l /usr/local/mysql/lib/libgalera_smm.so
-DMYSQL_SERVER_SUFFIX 值獲取
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 值獲取
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
4.1 編譯配置文件
vim /usr/local/mysql/my.cnf
[client]
socket=/tmp/mysql.sock
port = 3306
default-character-set = utf8
[mysqld]
socket=/tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
server_id = 10215
pid-file = /usr/local/mysql/mysql.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 = /usr/local/mysql/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=/usr/local/mysql/data/mysqld-error.log
wsrep_cluster_name = ycpxc ###指定您的群集的邏輯名稱。 它必須對群集中的所有節點都相同。
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_address='gcomm://192.168.10.215,192.168.10.214,192.168.10.213'###指定群集中節點的IP地址,節點加入群集至少需要一個,但建議列出所有節點的地址。
wsrep_sst_receive_address=192.168.10.215###用于SST傳送的端口
wsrep_node_incoming_address=192.168.10.215###定義節點期望客戶端連接的IP地址和端口。
wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.10.215;ist.recv_addr=192.168.10.215;"
###gmcast.listen
###來自其他節點的地址Galera偵聽連接。可以用來覆蓋默認端口傾聽,這是獲得從連接地址。
###ist.recv_addr
###地址監聽增量狀態傳輸。
wsrep_slave_threads= 4
wsrep_log_conflicts
wsrep_node_address=192.168.10.215###集群節點地址
wsrep_sst_method=xtrabackup-v2###默認情況下,Percona XtraDB群集使用Percona XtraBackup進行狀態快照傳輸(SST)。
wsrep_sst_auth=sstuser:passw0rd ###將SST的身份驗證憑據指定為<sst_user>:<sst_pass>。 您必須創建此用戶
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 = 3306
default-character-set = utf8
socket=/tmp/mysql.sock
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
注意:在[client]、[mysqld]、[mysql]最好都要指定sock的位置,避免初始化和啟動時報錯去找默認的配置文件。
4.2pxc環境所涉及的端口
#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:4567; "#用于SST傳送的端口:4444
Port for State Transfer, default 4444. It can be changed by the option:
wsrep_sst_receive_address=10.11.12.205:4444#用于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:4568; "
4.1 為wsrep_sst_auth傳輸創建用戶
當引導第一個節點并為其提供必要的權限時:
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd';
mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON . TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;
5.1 初始化pxc
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --initialize
初始化錯誤可以清空msyql/data/目錄下的文件
注意記錄密碼
5.2 啟動mysql
/usr/local/mysql/bin/mysqld --defaults-file=./my.cnf --wsrep-new-cluster &
注意主節點啟動要加上--wsrep-new-cluster,其他節點不用。
用剛剛初始化的密碼進去MySQL
/usr/local/mysql/bin/mysql -uroot -p${mypasswd}
5.3 更改密碼
第一次進去會提示改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
6.1 節點配置文件
192.168.10.214
安裝方式都是和主節點是一樣的,注意要卸載掉原來的mysql,更改配置文件的集群信息和server_id 即可。
只列出差異部分:
server_id = 10214
wsrep_sst_receive_address=192.168.10.214:6615###用于SST傳送的端口
wsrep_node_incoming_address=192.168.10.214###定義節點期望客戶端連接的IP地址和端口。
wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.10.214;ist.recv_addr=192.168.10.214:6618;"
wsrep_node_address=192.168.10.214###集群節點地址
192.168.10.213
server_id = 10213
wsrep_sst_receive_address=192.168.10.213###用于SST傳送的端口
wsrep_node_incoming_address=192.168.10.213###定義節點期望客戶端連接的IP地址和端口。
wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.10.213;ist.recv_addr=192.168.10.213;"
wsrep_node_address=192.168.10.213###集群節點地址
6.2 啟動其他節點
#其它節點直接啟動不用加--wsrep-new-cluster
/usr/local/mysql/bin/mysqld --defaults-file=../my.cnf
pxc集群最少是要3臺,如果沒有,可以使用仲裁者garbd,用來解決
可以找在一個網段的服務器上。也可以就在已有的節點上但是注意默認的端口不要沖突
7.1 #啟用garbd
cd /usr/local/mysql/bin/
./garbd --group=pxc-cluster --address=gcomm://192.168.10.215,192.168.10.214 --option=gmcast.listen_addr=tcp://192.168.10.213 -d -l /tmp/garbd.log
#全部起完了之后就可以看到節點數和集群
7.2如果要在一臺裝有pxc 的服務器上起garbd就要更改默認的pxc集群的通信端口
cd /usr/local/mysql/bin/
./garbd --group=pxc-cluster --address=gcomm://192.168.10.215,192.168.10.214 --option=gmcast.listen_addr=tcp://192.168.10.214: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集群搭建成功,可以在一個節點上創建一張表,其他節點可以查詢的到說明集群運行正常。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。