时间:2021-07-01 10:21:17 帮助过:18人阅读
写进/etc/fstab
#Disk for mysql data
/dev/mapper/vg_mysql-lv_mysql /data_mysql xfs defaults 0 0
重新挂载,在分区内建立两个文件夹,mysql和backup
mkdir -pv /data_mysql
mount -a
mkdir -pv /data_mysql/{mysql,backup}
修改/etc/percona-xtradb-cluster.conf.d/mysqld.cnf
datadir=/data_mysql/mysql
起来试试吧
systemctl start mysql
看看密码是个啥
grep ‘temporary password‘ /var/log/mysqld.log
连接数据库并输出刚才看见的密码
mysql -u root -p
为了将来管理方便,添加了远程的访问权限
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘mysql‘;
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "mysql";
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
SST用户也要添加,否则其他结点无法正常连入主节点
mysql> CREATE USER ‘sstuser‘@‘localhost‘ IDENTIFIED BY ‘mysql‘;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO ‘sstuser‘@‘localhost‘;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
服务停掉,准备配置集群吧
systemctl stop mysql
集群的配置文档在这:https://www.percona.com/doc/percona-xtradb-cluster/5.7/configure.html#configure
首先修改/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
# Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
#这里可以写域名或者IP地址
wsrep_cluster_address=gcomm://hctjosmysql01.hccos.cn,hctjosmysql02.hccos.cn,hctjosmysql03.hccos.cn
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB
# Slave thread to use
wsrep_slave_threads= 8
wsrep_log_conflicts
# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2
# Node IP address
# 这个可以写可以不写
wsrep_node_address=hctjoscontroller01.homecredit.cn
# Cluster name
wsrep_cluster_name=pxc-cluster-openstack
#If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=pxc-cluster-openstack-node-1
#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING
# SST method
wsrep_sst_method=xtrabackup-v2
#这项一定要写
#Authentication for SST method
wsrep_sst_auth="sstuser:mysql"
启动主节点
systemctl start mysql@bootstrap.service
在其他节点上修改/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
wsrep_node_name=pxc-cluster-openstack-node-2
wsrep_node_address=hctjoscontroller02.homecredit.cn
wsrep_node_name=pxc-cluster-openstack-node-3
wsrep_node_address=hctjoscontroller03.homecredit.cn
在其他结点上修改/etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
server-id=2
[mysqld]
server-id=3
在其他上启动mysql
systemctl start mysql
随便找一个节点验证
mysql> show status like ‘wsrep_cluster_size‘;
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.00 sec)
注意:如果cluster已经启动,主节点down机想重新加入这个集群,直接启动mysql即可
systemctl start mysql
如果这个集群中最后的节点也down机了,在任何一个节点都可以启动集群,重新启动集群需要执行
systemctl start mysql@bootstrap.service
【Linux】【Services】【IaaS】OpenStack-Pike(2.搭建高可用的MySQL数据库)
标签:libev ges nlog lib64 epo 节点 class share tar