【Linux】【Services】【IaaS】OpenStack-Pike(2.搭建高可用的MySQL資料庫)

來源:互聯網
上載者:User

標籤:libev   ges   nlog   lib64   epo   節點   class   share   tar   

1. 簡介

1.1. 官方文檔:

資料庫結構描述:https://docs.openstack.org/ha-guide/shared-database.html

1.2. 本次使用的的是Percona XtraDB Cluster,5.7版本

https://www.percona.com/doc/percona-xtradb-cluster/5.7/index.html

1.3. 安裝檔案下載:

https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/LATEST/

或者使用yum安裝,本文中使用yum安裝

https://www.percona.com/doc/percona-repo-config/yum-repo.html

這還有Docker的安裝說明,等以後Docker文檔中再詳細說明

https://www.percona.com/doc/percona-xtradb-cluster/5.7/install/docker.html

2. 安裝

 

功能與組件 機器名 服務IP 管理IP Processor Cores RAM Storage 備忘
Mysql PXC HCTJOSMYSQL01 10.30.2.25 172.16.0.25        
Mysql PXC HCTJOSMYSQL02 10.30.2.26 172.16.0.26        
Mysql PXC HCTJOSMYSQL03 10.30.2.27 172.16.0.27        

 

2.1. 安裝yum源

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

在RHEL7.4上雖然已經配置了EPEL源,但是仍然會出現找不到libev.so.4()的錯誤,請使用下面地址直接安裝

https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libev-4.15-3.el7.x86_64.rpm

安裝軟體吧

yum install Percona-XtraDB-Cluster-57

先別著急啟動,配置一個獨立的分區用來儲存資料庫檔案

vgcreate vg_mysql /dev/sdblvcreate -n lv_mysql -l +100%FREE vg_mysqlmkfs.xfs /dev/mapper/vg_mysql-lv_mysql

寫進/etc/fstab

#Disk for mysql data/dev/mapper/vg_mysql-lv_mysql    /data_mysql        xfs    defaults    0 0

重新掛載,在分區內建立兩個檔案夾,mysql和backup

mkdir -pv /data_mysqlmount -amkdir -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 [email protected]"%" 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 librarywsrep_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 ROWbinlog_format=ROW# MyISAM storage engine has only experimental supportdefault_storage_engine=InnoDB# Slave thread to usewsrep_slave_threads= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galerainnodb_autoinc_lock_mode=2# Node IP address
# 這個可以寫可以不寫wsrep_node_address=hctjoscontroller01.homecredit.cn# Cluster namewsrep_cluster_name=pxc-cluster-openstack#If wsrep_node_name is not specified, then system hostname will be usedwsrep_node_name=pxc-cluster-openstack-node-1#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTERpxc_strict_mode=ENFORCING# SST methodwsrep_sst_method=xtrabackup-v2
#這項一定要寫#Authentication for SST methodwsrep_sst_auth="sstuser:mysql"

啟動主節點

systemctl start [email protected]

在其他節點上修改/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 [email protected]

【Linux】【Services】【IaaS】OpenStack-Pike(2.搭建高可用的MySQL資料庫)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.