码迷,mamicode.com
首页 > 数据库 > 详细

Percona-XtraDB-Cluster的编译安装

时间:2018-06-05 18:38:37      阅读:865      评论:0      收藏:0      [点我收藏+]

标签:centos7   PXC   linux   mysql   

操作系统centos7.4,mysql 安装在/data/mysql下,mysql属于mysql用户
1.下载源码包
下载pxc-5.7.19
mkdir -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

下载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

下载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

2.安装依赖:
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 -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.编译安装

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数据库
创建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

编译 Percona-XtraDB-Cluster-5.7.19-29.22

-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: //‘)"

-DCOMPILATION_COMMENT 值
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.编译配置文件
vim /usr/local/mysql/my.cnf
[client]
socket=/tmp/mysql.sock
port = 6612
default-character-set = utf8

[mysqld]
socket=/tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 6612
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‘###指定群集中节点的IP地址,节点加入群集至少需要一个,但建议列出所有节点的地址。
wsrep_sst_receive_address=192.168.10.215:6615###用于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:6618;"
###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 = 6612
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.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.初始化启动pxc主节点
chmod +x /usr/local/mysql/my.cnf
chown -R mysql:mysql /usr/local/mysql
su - mysql
/usr/local/mysql/bin/mysqld --defaults-file=./my.cnf --initialize --wsrep-new-cluster &
#要指定配置文件来初始化
#初始化有问题可以清空msyql/data/目录下的文件
#记录密码
#注意主节点启动要加上--wsrep-new-cluster,其他节点不用。

###用刚刚初始化的密码进去MySQL
/usr/local/mysql/bin/mysql -uroot -p${mypasswd}
###第一次进去会提示改密码
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;

6.配置其他节点
安装方式都是和主节点是一样的,注意要卸载掉原来的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.215###集群节点地址

6.1启动其他节点
#其它节点直接启动不用再创建用户和密码
/usr/local/mysql/bin/mysqld --defaults-file=../my.cnf

7.使用garbd
pxc集群最少是要3台,如果没有,可以使用仲裁者garbd,用来解决
可以找在一个网段的服务器上。也可以就在已有的节点上但是注意默认的端口不要冲突
#启用garbd
cd /usr/local/mysql/bin/
./garbd -a gcomm://192.168.10.214,192.168.10.215 -g ycpxc -l /usr/local/mysql/data/garbd.log -d
#全部起完了之后就可以看到节点数和集群

8.检查
#查看MySQL 节点数
mysql> show global status like ‘wsrep_cluster_size‘;
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.00 sec)
是三个表示pxc集群搭建成功,可以在一个节点上创建一张表,启动节点可以查询的到说明集群运行正常。

Percona-XtraDB-Cluster的编译安装

标签:centos7   PXC   linux   mysql   

原文地址:http://blog.51cto.com/12915075/2125188

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!