1. 程式人生 > >Mariadb配置Galera集群

Mariadb配置Galera集群

erro row 登錄權限 with state nec config eat ica

一、增加MariaDB源

cd /etc/yum.repos.d

vi MariaDB.repo

# MariaDB 10.1 CentOS repository list - created 2017-04-20 03:29 UTC

# http://downloads.mariadb.org/mariadb/repositories/

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.1/centos6-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

如果官方源比較慢,可以使用國內阿裏雲的源:

[mariadb]

name = MariaDB

baseurl=http://mirrors.aliyun.com/mariadb/mariadb-10.2.6/yum/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

二、安裝

yum install MariaDB-server MariaDB-client

安裝完成後啟動mysql服務(雖然改名叫mariadb,但服務名還是叫mysql)

service mysql start

三、配置

運行mysql_secure_installation設置數據庫root用戶密碼等。

設置完密碼後,使用root用戶登錄mariadb,設置root用戶權限:

mysql –uroot –p

GRANT ALL ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘Enjoylink$2017‘ with grant option;

FLUSH PRIVILEGES;

quit

如果安裝完成後,遇到無法登錄mysql:

[root@iZwz9d4e4x8w76gubkpk7gZ ~]# mysql_secure_installation

Enter current password for root (enter for none):

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

此時,先關閉mysql服務

service mysql stop

編輯server.cnf文件

vi /etc/my.cnf.d/server.cnf

在[mysqld]中加上

[mysqld]

skip-grant-tables

忽略掉登錄權限,然後無密碼登錄mysql,並修改root賬戶密碼:

update user set password=PASSWORD("123456") where user=‘root‘;

修改成功後退出,把skip-grant-tables去掉,重啟mysql服務即可。

四、設置iptables,開放3306端口讓數據庫可以遠程訪問

vi /etc/sysconfig/iptables

增加:-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

保存,並重啟iptables服務

service iptables restart

五、配置數據庫集群(Galera Cluster)

三個節點都需要做以下工作:

創建同步用戶:

CREATE USER ‘syncUser‘@‘%‘ IDENTIFIED BY ‘sync$2017‘;

授權:

GRANT ALL ON *.* TO ‘syncUser‘@‘%‘ IDENTIFIED BY ‘sync$2017‘ with grant option;

配置HOSTS:

在三臺服務器中添加hosts設置,

vi /etc/hosts

10.243.3.27 dbnode1

10.243.3.17 dbnode2

10.34.2.200 dbnode3

停止所有節點上的mysql服務

service mysql stop

六、配置Mariadb服務

在所有節點服務器中都添加集群配置:

vi /etc/my.cnf.d/server.cnf

[galera]

wsrep_on=ON

wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_cluster_address="gcomm://dbnode1,dbnode2,dbnode3"

binlog_format=row

default_storage_engine=InnoDB

innodb_autoinc_lock_mode=2

七、停止SELinux安全限制

在所有節點上停止SELinux服務:

暫時停止:setenforce 0

永久停止:vi /etc/selinux/config

將SELINUX的值改一下:SELINUX=disabled

八、開放iptables防火墻端口

vi /etc/sysconfig/iptables

添加以下幾個端口:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 4567 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 4444 -j ACCEPT

九、啟動集群主節點

It may not be safe to bootstrap the cluster from this node. It was not the last one to leave the cluster and may not contain all the updates. To force cluster bootstrap with this node, edit the grastate.dat file manually and set safe_to_bootstrap to 1 .

如果在所有集群節點都死光的情況下,兩次啟動集群時,應該在最後一臺死的節點上啟動。

service mysql start --wsrep_new_cluster

  • or

service mysql bootstrap

十、啟動其它節點

service mysql start

十一、 查看集群狀態

在主節點上登錄Mariadb後,可以查看集群狀態:

MariaDB [(none)]> show status like ‘wsrep_%‘;

+------------------------------+----------------------------------------------------+

| Variable_name | Value |

+------------------------------+----------------------------------------------------+

| wsrep_apply_oooe | 0.000000 |

| wsrep_apply_oool | 0.000000 |

| wsrep_apply_window | 1.000000 |

| wsrep_causal_reads | 0 |

| wsrep_cert_deps_distance | 4.133333 |

| wsrep_cert_index_size | 8 |

| wsrep_cert_interval | 0.000000 |

| wsrep_cluster_conf_id | 9 |

| wsrep_cluster_size | 3 |

| wsrep_cluster_state_uuid | 0bdf4eb0-50e1-11e7-a4f3-9bce02f737ae |

| wsrep_cluster_status | Primary |

| wsrep_commit_oooe | 0.000000 |

| wsrep_commit_oool | 0.000000 |

| wsrep_commit_window | 1.000000 |

| wsrep_connected | ON |

| wsrep_desync_count | 0 |

| wsrep_evs_delayed | |

| wsrep_evs_evict_list | |

| wsrep_evs_repl_latency | 0.00394587/0.00611148/0.00826421/0.00192492/4 |

| wsrep_evs_state | OPERATIONAL |

| wsrep_flow_control_paused | 0.000000 |

| wsrep_flow_control_paused_ns | 0 |

| wsrep_flow_control_recv | 0 |

| wsrep_flow_control_sent | 0 |

| wsrep_gcomm_uuid | 0b6d316f-50e3-11e7-addf-a66dba4d326d |

| wsrep_incoming_addresses | 10.34.2.200:3306,10.243.3.27:3306,10.243.3.17:3306 |

| wsrep_last_committed | 15 |

| wsrep_local_bf_aborts | 0 |

| wsrep_local_cached_downto | 1 |

| wsrep_local_cert_failures | 0 |

| wsrep_local_commits | 15 |

| wsrep_local_index | 0 |

| wsrep_local_recv_queue | 0 |

| wsrep_local_recv_queue_avg | 0.000000 |

| wsrep_local_recv_queue_max | 1 |

| wsrep_local_recv_queue_min | 0 |

| wsrep_local_replays | 0 |

| wsrep_local_send_queue | 0 |

| wsrep_local_send_queue_avg | 0.000000 |

| wsrep_local_send_queue_max | 1 |

| wsrep_local_send_queue_min | 0 |

| wsrep_local_state | 4 |

| wsrep_local_state_comment | Synced |

| wsrep_local_state_uuid | 0bdf4eb0-50e1-11e7-a4f3-9bce02f737ae |

| wsrep_protocol_version | 7 |

| wsrep_provider_name | Galera |

| wsrep_provider_vendor | Codership Oy <[email protected]> |

| wsrep_provider_version | 25.3.20(r3703) |

| wsrep_ready | ON |

| wsrep_received | 22 |

| wsrep_received_bytes | 2308 |

| wsrep_repl_data_bytes | 8491 |

| wsrep_repl_keys | 51 |

| wsrep_repl_keys_bytes | 753 |

| wsrep_repl_other_bytes | 0 |

| wsrep_replicated | 15 |

| wsrep_replicated_bytes | 10204 |

| wsrep_thread_count | 2 |

+------------------------------+----------------------------------------------------+

58 rows in set (0.00 sec)

Mariadb配置Galera集群