Mariadb配置Galera集群

2018-08-02 05:57:32来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

一、增加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 <info@codership.com>                  |

| 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)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:PostgreSQL的表空间

下一篇:mssql sqlserver 视图如何加密,让第三方用户查看不到其中的SQL