Centos7 yum 安装 Percona XtraDB Cluster 5.7

原创 Jeff Tang  2018-05-14 15:10  阅读 287 次 次

# 环境介绍

10.0.3.161    feature-01
10.0.3.162    feature-02
10.0.3.163    feature-03

# hostname 需要我这种格式 xxx-xx 不然后面 server_id 拿不到变量

 

# 安装yum 源  [10.0.3.161, 10.0.3.162, 10.0.3.163]

yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

 

# yum 安装Percona XtraDB Cluster 5.7  [10.0.3.161, 10.0.3.162, 10.0.3.163]

yum install -y Percona-XtraDB-Cluster-57 openssl

 

# 创建 数据日志目录 文件 [10.0.3.161, 10.0.3.162, 10.0.3.163]

mkdir -p /data/mysql/xtradb/{data,logs}
touch /data/mysql/xtradb/logs/{error.log,data-slow.log}
chown -R mysql:mysql /data/mysql/xtradb

 

# 配置my.conf [10.0.3.161, 10.0.3.162, 10.0.3.163]

export PEER_NAME=$(hostname)
export PRIVATE_IP=$(ip addr show eth0 | grep -Po 'inet \K[\d.]+')
export server_id=`echo $(hostname) | awk -F '-' '{print $2}'`

cat >/etc/my.cnf <<EOF
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld_safe]
socket=/var/lib/mysql/mysql.sock
nice=0
[mysqld]
server-id=${server_id}
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/lib/mysql/mysql.sock
port=3306
datadir=/data/mysql/xtradb/data/
log_error=/data/mysql/xtradb/logs/error.log
skip-external-locking
character-set-server=utf8
max_connections=2000
log_timestamps=SYSTEM
slow_query_log=1
slow_query_log_file=/data/mysql/xtradb/logs/data-slow.log
long_query_time=5
log_queries_not_using_indexes=1
bind-address=0.0.0.0
interactive_timeout=600
wait_timeout=600
max_allowed_packet=1024M
myisam_recover_options=BACKUP
log-bin-trust-function-creators=1
log-bin=bin-log
innodb_buffer_pool_size = 8G
sync_binlog=1
explicit_defaults_for_timestamp = 1
disable_ssl
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.3.161,110.0.3.162,110.0.3.163 # 这里需要修改为你自己Mysql集群的IP
wsrep_slave_threads=14
wsrep_cluster_name=prod_cluster
wsrep_sst_method=xtrabackup-v2
pxc_strict_mode=PERMISSIVE
wsrep_node_name=${PEER_NAME}
wsrep_node_address=${PRIVATE_IP}
wsrep_sst_auth="sstuser:passw0rd"
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
EOF

 

# 初始化集群中第一台mysql [10.0.3.161]

systemctl start mysql@bootstrap.service
systemctl status mysql@bootstrap.service
mysqladmin -uroot -p`cat /data/mysql/xtradb/logs/error.log | grep 'temporary password' | awk '{print $NF}'` password 'P@ssword'

 

# 创建同步账户 [10.0.3.161]

mysql -uroot -p'P@ssword'
CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd';
GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO'sstuser'@'localhost';
FLUSH PRIVILEGES;

 

# 启动集群中其余mysql  [10.0.3.162, 10.0.3.163]

systemctl start mysql
systemctl status mysql.service

 

# 集群状态检查 [集群中任意一台mysql]
show global status like 'wsrep_cluster_size';    <== 如果这个值跟预期的节点数一致,则所有的集群节点已经连接.
show global status like 'wsrep_cluster_status'; <== 集群组成的状态."Primary"说明出现正常

																								
						
本文地址:https://www.easylinux.cn/archives/189
版权声明:本文为原创文章,版权归 Jeff Tang 所有,欢迎分享本文,转载请保留出处!
NEXT:已经是最新一篇了

发表评论


表情