您好,欢迎访问代理记账网站
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

源码部署pxc集群

想了想还是研究一下怎么源码安装pxc吧,毕竟很多组件都是源码安装的。

环境:

yum install -y boost-devel  libodb-boost-devel  check-devel openssl-devel libaio-devel 

安装scons

需要2.7+ 的Python
wget https://nchc.dl.sourceforge.net/project/scons/scons/3.0.1/scons-3.0.1.tar.gz
tar xf scons-3.0.1.tar.gz 
cd scons-3.0.1
python setup.py install  

安装 Percona-XtraDB-Cluster:

tcmalloc 安装忽略,mysql用户创建忽略

wget ftp://ftp.pbone.net/mirror/apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/socat-1.7.2.4-1.el6.rf.x86_64.rpm 
rpm -ivh socat-1.7.2.4-1.el6.rf.x86_64.rpm  

wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/rudi_m:/devel-snap/CentOS_CentOS-6/x86_64/libev4-4.15-7.1.x86_64.rpm 
rpm -ivh libev4-4.15-7.1.x86_64.rpm 

wget ftp://ftp.pbone.net/mirror/ftp.centos.org/6.9/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm 
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm 

wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/viliampucik:/obs/RedHat_RHEL-6/x86_64/compat-readline5-5.2-17.4.x86_64.rpm 
rpm -ivh compat-readline5-5.2-17.4.x86_64.rpm

wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/percona-xtrabackup-24-2.4.12-1.el6.x86_64.rpm
rpm -ivh percona-xtrabackup-24-2.4.12-1.el6.x86_64.rpm

安装libgalera_smm.so

wget https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/Percona-XtraDB-Cluster-5.7.23-31.31-2/source/tarball/Percona-XtraDB-Cluster-5.7.23-31.31.tar.gz
tar xf Percona-XtraDB-Cluster-5.7.23-31.31.tar.gz
cd Percona-XtraDB-Cluster-5.7.23-31.31/percona-xtradb-cluster-galera/
scons -j4 psi=1 --config=force   revno=    libgalera_smm.so

之后,当前目录下就有一个libgalera_smm.so文件

安装pxc

#将boost_1_59_0.tar.gz放到源码包当前目录,cmake过程会自动加压
cd ../
cp /dist/dist/boost_1_59_0.tar.gz .
mkdir build
cd build/
CHOST="x86_64-pc-linux-gnu" CFLAGS="-march=nocona -O2 -pipe" CXXFLAGS="-march=nocona -O2 -pipe" \
 cmake ../  \
 -DMYSQL_USER=mysql \
 -DCMAKE_BUILD_TYPE:STRING=Release \
 -DBUILD_CONFIG=mysql_release \
 -DWITH_EMBEDDED_SERVER=OFF \
 -DFEATURE_SET=community \
 -DENABLE_DTRACE=OFF \
 -DWITH_SSL=system \
 -DWITH_ZLIB=system  \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
 -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 \
 -DWITH_PAM=ON \
 -DWITH_INNODB_MEMCACHED=ON \
 -DDOWNLOAD_BOOST=1 \
 -DWITH_BOOST=..\
 -DWITH_SCALABILITY_METRICS=ON \
 -DCMAKE_EXE_LINKER_FLAGS="-ltcmalloc" \
 -DWITH_SAFEMALLOC=OFF  \
 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
 -DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 \
make -j $CPUcount
make install

#将libgalera_smm.so复制到basedir的lib目录中,或者可以再mysql实例的配置文件中指定文件位置也行
cd ../
cp percona-xtradb-cluster-galera/libgalera_smm.so /usr/local/mysql/lib/

到目前为止,pxc的一个实例就安装好了。剩下的就是按套路配置启动了。

配置

#一定要让path变量能找得到pxc实例的二进制文件和相关脚本
ln -sv /usr/local/mysql/bin/* /usr/local/bin/  
mkdir -p /data/database/mysql
chown mysql:mysql -R /data/database/mysql
#让mysqld支持tcmalloc
cd /usr/local/mysql
sed -i '/Initialize script globals/ a export LD_PRELOAD=/usr/local/lib/libtcmalloc.so' bin/mysqld_safe
# 配置文件:
[client]
port=3306
socket = /tmp/mysql.sock

[mysqld]
server-id=132
port=3306
datadir=/data/database/mysql
tmpdir=/data/database/mysql
#basedir=/usr/local/mysql
socket = /tmp/mysql.sock
log-error=/data/database/mysql/thai_pxc_cluster.err
pid-file=/data/database/mysql/thai_pxc_cluster.pid
user=mysql
secure_file_priv = ""
performance_schema_max_table_instances=50000
table_definition_cache=400
table_open_cache=1024

# General
back_log=2000
connect_timeout=15
max_connections=1024
max_allowed_packet = 16M
max_heap_table_size = 128M
sort_buffer_size =  8M
net_buffer_length = 8K
read_buffer_size = 8M
read_rnd_buffer_size = 32M
query_cache_size = 128M
join_buffer_size=8M
bulk_insert_buffer_size=128M
concurrent_insert=2
delay_key_write=ON
delayed_insert_limit=4000
delayed_insert_timeout=600
delayed_queue_size=4000
tmp_table_size = 256M
thread_cache_size=120
character-set-server=utf8
metadata_locks_hash_instances=256
open-files-limit = 10240
skip-name-resolve
core_file
transaction-isolation=READ-COMMITTED
sql_mode = ""

# Innodb
innodb_buffer_pool_size = 4096M
innodb_buffer_pool_instances=8
innodb_log_file_size = 1024M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 20
innodb_autoinc_lock_mode=2
innodb_read_io_threads = 5
innodb_write_io_threads = 5
innodb_thread_concurrency = 8
innodb_doublewrite=1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = 'O_DIRECT'
innodb-page-cleaners=8
innodb_purge_threads=4
innodb_lru_scan_depth=2048
innodb_io_capacity=8000
innodb_io_capacity_max=16000
innodb_adaptive_hash_index=OFF
innodb-change-buffering=none
innodb_flush_neighbors=0
innodb_max_dirty_pages_pct = 90
innodb_max_dirty_pages_pct_lwm = 10


# Binlog
relay-log=relay-1
binlog_format=ROW
enforce-gtid-consistency
gtid-mode=on
master-info-repository=TABLE
relay-log-info-repository=TABLE
binlog-checksum=NONE
log-bin=mysql-bin
max-binlog-size=128M
log_slave_updates
expire_logs_days=3
sync_binlog=1
binlog_cache_size = 4M
log_output=FILE
slow_query_log=1
slow_query_log_file=/data/database/mysql/slowquery.log
max_slowlog_size=1024m
max_slowlog_files=10
long_query_time=1

# Monitoring
innodb_monitor_enable='%'
performance_schema=ON
performance_schema_instrument='%synch%=on'

# Galera
symbolic-links=0
explicit_defaults_for_timestamp=true
#wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_address=gcomm://30.0.0.227,30.0.0.226,30.0.0.225
default_storage_engine=InnoDB
wsrep_slave_threads= 20
wsrep_log_conflicts
wsrep_cluster_name=pxc_cluster
wsrep_node_name=pxc_node_30.0.0.226
wsrep_node_address=30.0.0.226
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cret"
pxc_strict_mode=DISABLED

初始化(第一个节点)

/usr/local/mysql/bin/mysqld  --initialize  --datadir=/data/database/mysql/  --basedir=/usr/local/mysql/  --user=mysql

在初始化过程中会生成root@local的密码,需要用这个密码做第一次登录并修改。类似:

2018-05-08T02:34:50.116777Z 1 [Note] A temporary password is generated for root@localhost: dGpgf>_vj90>

启动(第一个节点)

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --wsrep-new-cluster --lc_messages_dir=/usr/local/mysql/share/  --lc_messages=en_US &

改root密码

mysql> alter user root@localhost identified by '20c0dc7315fe8db65cbab532818e0e7a';

配置SST认证账号

mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 's3cret';
mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;

启动其他节点

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --lc_messages_dir=/usr/local/mysql/share/ --lc_messages=en_US &

分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进