zoukankan      html  css  js  c++  java
  • 构建 MariaDB Galera Cluster 分布式数据库集群(二)

    MariaDB的安装

    构建 MariaDB Galera Cluster之前,首先安装MariaDB,本文使用的版本是10.1

    1.环境准备

    主机:

    • MariaDB01(192.168.56.102)
    • MariaDB02(192.168.56.103)
    • MariaDB03(192.168.56.104)

    OS: centos6.5
    MariaDB版本:10.1

    yum源设置
    Here is your custom MariaDB YUM repository entry for CentOS. Copy and paste it into a file under /etc/yum.repos.d/ (we suggest naming the file MariaDB.repo or something similar). See "Installing MariaDB with yum" for detailed information.
    #翻译:这是您CentOS的自定义MariaDB YUM存储库条目。 将它复制并粘贴到/etc/yum.repos.d/下的文件(我们建议命名文件MariaDB.repo或类似的东西)。 有关详细信息,请参阅“使用yum安装MariaDB”。

    vim /etc/yum.repos.d/MariaDB.repo 写入如下内容:
    
    # MariaDB 10.1 CentOS repository list - created 2016-09-30 08:23 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

    然后执行下列命令导入证书并更新repo

    # sudo rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    # yum repolist

    如果你对网络质量充满信心,你现在就可以进入第二步的安装maridb了,但是我强烈建议你用下面的这个方法,因为你可能要反复测试重装个几次,毕竟每次都从官网下载不是一件高效的事儿。

    就像上面说的,如果你担心和考虑到网络质量不佳的情况,可下载rpm包后自建yum源
    http://downloads.mariadb.com/MariaDB/mariadb-10.1/yum/rhel/mariadb-10.1.19-rhel-6-x86_64-rpms.tar 自建yum源方法可问下度娘
    或者访问https://mariadb.com/downloads/maxscale下载最新版本的mariadb(它会自动给你选择最新的mariadb的,由于各版本安装配置差异较大,本文只对mariadb10.1版本负责)
    对新版感兴趣的可以测试下maxscale方法:
    #install MariaDB MaxScale like this:
    #https://mariadb.com/downloads/maxscale
    yum install maxscale  或者
    RPM-ivh https://downloads.mariadb.com/MaxScale/2.0.3/rhel/6/x86_64/maxscale-2.0.3-1.rhel.6.x86_64.rpm
    或者依据官方提供的https://downloads.mariadb.com/MaxScale/x.x.x/rhel/6/x86_64/maxscale-x.x.x-.rhel.6.x86_64.rpm最新版本进行安装

    2.安装maridb

    以下安装过程来源于官网 https://mariadb.com/kb/en/mariadb-enterprise/mariadb-enterprise-installation-guide/
    #Install MariaDB Enterprise Server or MariaDB Enterprise Cluster 10.1 like this:

    yum install MariaDB-server MariaDB-client

    官网还提供了MariaDB Enterprise Cluster 5.5的安装方法,不是本文的重点,直接跳过。
    值得注意的是,如果你要安装5.5版本,则后面的cluster集群的安装配置和10.1版本下是完全不一样的,需要高度注意,避免发生混淆和错误。

    3.创建执行用户

    # groupadd mariadb
    # useradd -g mariadb mariadb
    # passwd mariadb
    # echo 'mariadb ALL=(ALL) ALL' >> /etc/sudoers
    # cd /var/lib
    # chown -R mariadb:mariadb mysql

    4.启动maridb服务

    请根据自身系统版本,选择适合的启动方法启动即可。本文安装环境是在centos6.5下,按照4.3进行启动

    4.1:On RHEL and CentOS starting with version 7 using systemd, start MariaDB like this: (通过systemd启动mariadb)
    # systemctl start mariadb.service

    4.2:or on RHEL and CentOS starting with version 7 using systemd, bootstrap the first node of a MariaDB Enterprise Cluster like this:
    # galera_new_cluster

    4.3:or on RHEL and CentOS before version 7, such as centos6.5, start MariaDB like this:(在centos6.5上仍然按照启动mysql的方法启动mariadb)

    # service mysql start

    启动时可能会遇到下列错误:
    Starting MySQL.161222 11:28:27 mysqld_safe Logging to '/var/lib/mysql/MariaDB03.err'.
     ERROR!
    #检查是由于/var/lib/mysql/MariaDB03.err权限的问题,需要执行 su mariadb,在mariadb用户下启动服务

    [root@MariaDB03 ~]# cat /var/lib/mysql/MariaDB03.err
    161222 11:28:27 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    2016-12-22 11:28:27 140570816137248 [Note] /usr/sbin/mysqld (mysqld 10.1.18-MariaDB) starting as process 3650 ...
    2016-12-22 11:28:27 140570816137248 [ERROR] mysqld: File '/var/lib/mysql/aria_log_control' not found (Errcode: 13 "Permission denied")
    2016-12-22 11:28:27 140570816137248 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/var/lib/mysql/aria_log_control'
    2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'Aria' init function returned error.
    2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using mutexes to ref count buffer pool pages
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: The InnoDB memory heap is disabled
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Compressed tables use zlib 1.2.3
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using Linux native AIO
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using SSE crc32 instructions
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Initializing buffer pool, size = 128.0M
    2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Completed initialization of buffer pool
    2016-12-22 11:28:27 140570816137248 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
    2016-12-22 11:28:27 140570816137248 [ERROR] InnoDB: The system tablespace must be writable!
    2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'InnoDB' init function returned error.
    2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    2016-12-22 11:28:27 140570816137248 [Note] Plugin 'FEEDBACK' is disabled.
    2016-12-22 11:28:27 140570816137248 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
    2016-12-22 11:28:27 140570816137248 [ERROR] Unknown/unsupported storage engine: InnoDB
    2016-12-22 11:28:27 140570816137248 [ERROR] Aborting
    161222 11:28:27 mysqld_safe mysqld from pid file /var/lib/mysql/MariaDB03.pid en

    # su mariadb
    $ service mysql start


    4.4:or on RHEL and CentOS before version 7, bootstrap the first node of a MariaDB Enterprise Cluster like this:
    service mysql bootstrap

    5.初始化maridb数据库

    在mariadb@MariaDB01 至 mariadb@MariaDB03上分别初始化msyql

    [mariadb@MariaDB01 root]# su mariadb
    $ sudo mysql_secure_installation

    >根据提示进行操作
    >由于是测试,密码推荐设置为空,便于后面的操作,正式用的时候再修改密码
    >一定要设置不允许root远程访问,这是起码的操守,不要再问为什么了,因为以后也不会再去改它了吧

    5.防火墙设置

    centos6,root下执行

    # iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT
    # iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT

    如果在centos7下,诸如这样执行:

    # firewall-cmd --add-port=3306/tcp #暂时生效,重启后失效
    # firewall-cmd --permanent --add-port=3306/tcp #永久生效

    正式环境务必要配置防火墙的,尤其对于研发的人来说,一定要重视这个问题
    如测试用,可关闭防火墙,忽略此配置即可

    6.mysql管理和监控工具

    MySQL免费性能监控工具-MONyog 分linux和windows版
    SQLyog数据库管理 只有windows版
    上面的工具说实话我没用过,我更习惯用nginx/zabbix进行监控,用navicat进行管理

    7.使用

    安装完了,简单测试下吧

    [mariadb@MariaDB01 my.cnf.d]$ mysql -uroot -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 9
    Server version: 10.1.18-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    #看看集群的状态如何

    MariaDB [(none)]> show status like 'wsrep%';
    +--------------------------+----------------------+
    | Variable_name            | Value                |
    +--------------------------+----------------------+
    | wsrep_cluster_conf_id    | 18446744073709551615 |
    | wsrep_cluster_size       | 0                    |
    | wsrep_cluster_state_uuid |                      |
    | wsrep_cluster_status     | Disconnected         |
    | wsrep_connected          | OFF                  |
    | wsrep_local_bf_aborts    | 0                    |
    | wsrep_local_index        | 18446744073709551615 |
    | wsrep_provider_name      |                      |
    | wsrep_provider_vendor    |                      |
    | wsrep_provider_version   |                      |
    | wsrep_ready              | OFF                  |
    | wsrep_thread_count       | 0                    |
    +----------------------
    
    MariaDB [(none)]> show variables like 'wsrep_cluster_address';
    +-----------------------+------------------------------------------------------+
    | Variable_name         | Value                                                |
    +-----------------------+------------------------------------------------------+
    | wsrep_cluster_address | gcomm://192.168.56.102,192.168.56.103,192.168.56.104 |  #这个展示是已经配置过集群的,初始安装的这里显示的应该是空,不要被误导啊!
    +-----------------------+------------------------------------------------------+
    1 row in set (0.00 sec)

    现在还只是个MariaDB10.1的环境,要完成MariaDB Galera Cluster请继续看下一章内容

    -本章完-

    2017-02-24

    本文系作者原创,转载请注明出处。如您阅读的是转载,请最好再看下原文,原文随时会更新和勘误的。

    @Gordon_chang
    1997年毕业于北京联合大学,先后在中国万网,新媒传信,亚信等公司工作,现在在一家创业型公司担任云计算与大数据运维方面的 PM & Engineer。 专注于以下四个领域: 分布式存储 分布式数据库 云计算 大数据 重点通过技术架构与性能优化(底层)实现基于私有云的大数据平台能力

  • 相关阅读:
    卡特兰数
    hdu 1023 Train Problem II
    hdu 1022 Train Problem
    hdu 1021 Fibonacci Again 找规律
    java大数模板
    gcd
    object dection资源
    Rich feature hierarchies for accurate object detection and semantic segmentation(RCNN)
    softmax sigmoid
    凸优化
  • 原文地址:https://www.cnblogs.com/gordonchang/p/6425713.html
Copyright © 2011-2022 走看看