zoukankan      html  css  js  c++  java
  • Fedora Server 上配置 MariaDb 集群

    下载与安装 MariaDB Galera Cluster

    10.1之前的版本安装,输入以下命令进行安装:

    sudo dnf install mariadb-galera-server
    

      如果电脑上还没安装Mariadb Server,会顺便安装上,如果已经安装了,则会更新相关的包。

    10.1之后的版本,Mariadb Server把群集功能打包在一起了,所以直接安装数据库,不用单独安装:

    sudo dnf install mariadb-server

    配置

    基本步骤,使用--wsrep-new-cluster创建一个集群(只在第一个节点上使用),用--wsrep_cluster_address=gcomm://192.168.0.1加入节点。

    由于文本使用的是Fedora,服务管理是systemd,所以需要修改mariadb.service,将参数加进去。

      修改后的启动文件:

    [Unit]
    Description=MariaDB 10.1 database server
    After=network.target
    
    [Service]
    Type=notify
    User=mysql
    Group=mysql
    
    ExecStartPre=/usr/libexec/mysql-check-socket
    # '%n' expands to 'Full unit name'; man systemd.unit
    ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n
    # MYSQLD_OPTS here is for users to set in /etc/systemd/system/mariadb@.service.d/MY_SPECIAL.conf
    # Note: we set --basedir to prevent probes that might trigger SELinux alarms,
    # per bug #547485
    ExecStart=/usr/libexec/mysqld --basedir=/usr $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_CLUSTER_ADDRESS
    ExecStartPost=/usr/libexec/mysql-check-upgrade
    ExecStopPost=/usr/libexec/mysql-wait-stop
    
    # Setting this to true can break replication and the Type=notify settings
    # See also bind-address mysqld option.
    PrivateNetwork=false
    
    KillMode=process
    KillSignal=SIGTERM
    
    # Don't want to see an automated SIGKILL ever
    SendSIGKILL=no
    
    # Restart crashed server only, on-failure would also restart, for example, when
    # my.cnf contains unknown option
    Restart=on-abort
    RestartSec=5s
    
    UMask=007
    
    # Give a reasonable amount of time for the server to start up/shut down
    TimeoutSec=300
    
    # Place temp files in a secure directory, not /tmp
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    

      

    第一个节点的环境设置:

    systemctl show-environment
    LANG=en_US.UTF-8
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
    _WSREP_CLUSTER_ADDRESS=--wsrep_cluster_address=gcomm://192.168.30.184
    _WSREP_NEW_CLUSTER=--wsrep-new-cluster
    

    第二个节点的环境配置

    systemctl show-environment
    LANG=en_US.UTF-8
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
    _WSREP_CLUSTER_ADDRESS=--wsrep_cluster_address=gcomm://192.168.30.184
    

      测试

    为测试方便,先将防火墙关闭,还有selinux。先启动第一个节点,再启动第二个节点。在其中一个节点上创建一个数据库,切换到另一个节点上就可以看到这个数据库。

    通过数据命令可以查看集群的状态:

    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     | 1.000000                                |
    | wsrep_cert_index_size        | 2                                       |
    | wsrep_cert_interval          | 0.000000                                |
    | wsrep_cluster_conf_id        | 189                                     |
    | wsrep_cluster_size           | 2                                       |
    | wsrep_cluster_state_uuid     | e5b100e2-7f7e-11e7-9266-de309a905227    |
    | 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/0/0/0/0                               |
    | 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             | f023c418-7f81-11e7-bfbb-86741b99a879    |
    | wsrep_incoming_addresses     | 192.168.30.184:3306,192.168.30.186:3306 |
    | wsrep_last_committed         | 3                                       |
    | wsrep_local_bf_aborts        | 0                                       |
    | wsrep_local_cached_downto    | 1                                       |
    | wsrep_local_cert_failures    | 0                                       |
    | wsrep_local_commits          | 0                                       |
    | wsrep_local_index            | 1                                       |
    | wsrep_local_recv_queue       | 0                                       |
    | wsrep_local_recv_queue_avg   | 0.125000                                |
    | wsrep_local_recv_queue_max   | 2                                       |
    | 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       | e5b100e2-7f7e-11e7-9266-de309a905227    |
    | wsrep_protocol_version       | 7                                       |
    | wsrep_provider_name          | Galera                                  |
    | wsrep_provider_vendor        | Codership Oy <info@codership.com>       |
    | wsrep_provider_version       | 3.16(r5c765eb)                          |
    | wsrep_ready                  | ON                                      |
    | wsrep_received               | 8                                       |
    | wsrep_received_bytes         | 2148                                    |
    | wsrep_repl_data_bytes        | 0                                       |
    | wsrep_repl_keys              | 0                                       |
    | wsrep_repl_keys_bytes        | 0                                       |
    | wsrep_repl_other_bytes       | 0                                       |
    | wsrep_replicated             | 0                                       |
    | wsrep_replicated_bytes       | 0                                       |
    | wsrep_thread_count           | 2                                       |
    +------------------------------+-----------------------------------------+
    

      

  • 相关阅读:
    iOS常用的终端指令
    instancesRespondToSelector与respondsToSelector的区别
    Struts2(一)快速入门
    pl/sql快速输入select * from等语句快捷键设置
    win10系统安装oracle11g时遇到INS-13001环境不满足最低要求
    JSP四大作用域
    J2EE开发模式
    JAVA四大域对象总结
    Apache与Tomcat有什么关系和区别
    Junit测试框架
  • 原文地址:https://www.cnblogs.com/icoolno1/p/7352924.html
Copyright © 2011-2022 走看看