【mysql】ubuntu搭建mysql集群 mysql-cluster

文章目录

      • 1. 环境说明:
      • 2. manage 安装和配置Cluster Manager
      • 3. node1 & node2 安装和配置数据节点
      • 4. manage & node1 & node2 配置sql节点(MySQL服务器和客户端)
      • 5. 验证mysql集群安装:登陆到manage

1. 环境说明:

三台ubuntu18.04 ,分别为

  • manage
  • node1
  • node2

2. manage 安装和配置Cluster Manager

  • 二进制安装mysql-cluster-manage
    • cd /usr/local/src
    • wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-8.0/mysql-cluster-community-management-server_8.0.19-1ubuntu18.04_amd64.deb
    • dpkg -i mysql-cluster-community-nodejs_8.0.19-1ubuntu18.04_amd64.deb
  • 创建配置文件
    • mkdir /var/lib/mysql-cluster
    • vim /var/lib/mysql-cluster/config.ini
      [ndbd default] # 配置ndbd节点
      # Options affecting ndbd processes on all data nodes:
      NoOfReplicas=2  # Number of replicas
      [ndb_mgmd] # 配置管理节点
      # Management process options:
      hostname=198.51.100.2 # Hostname of the manager
      datadir=/var/lib/mysql-cluster  # Directory for the log files
      [ndbd] # 配置数据节点
      hostname=198.51.100.0 # Hostname/IP of the first data node
      NodeId=2            # Node ID for this data node
      datadir=/usr/local/mysql/data   # Remote directory for the data files
      [ndbd]
      hostname=198.51.100.1 # Hostname/IP of the second data node
      NodeId=3            # Node ID for this data node
      datadir=/usr/local/mysql/data   # Remote directory for the data files
      [mysqld] # 配置sql节点
      hostname=198.51.100.0# In our case the MySQL server/client is on the same Droplet as the cluster manager
      NodeId=4
      [mysqld]
      # SQL node options:
      hostname=198.51.100.1 # In our case the MySQL server/client is on the same Droplet as the cluster manager
      NodeId=5
      [mysqld]
      # SQL node options:
      hostname=198.51.100.2 # In our case the MySQL server/client is on the same Droplet as the cluster manager
      NodeId=6
      
  • 启动测试:ndb_mgmd -f /var/lib/mysql-cluster/config.ini
  • 设置防火墙允许其它节点传入连接
    • ufw allow from 10.66.1.125
    • ufw allow from 10.66.1.124
  • system管理ndb_mgmd
    • 杀死ndbd进程:pkill -f ndb_mgmd
    • 创建管理文件:vim /etc/systemd/system/ndb_mgmd.service
      [Unit]
      Description=MySQL NDB Cluster Management Server
      After=network.target auditd.service
      [Service]
      Type=forking
      ExecStart=/usr/sbin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
      ExecReload=/bin/kill -HUP $MAINPID
      KillMode=process
      Restart=on-failure
      [Install]
      WantedBy=multi-user.target
      
    • 重载system配置:systemctl daemon-reload
    • 开启自启动:systemctl enable ndb_mgmd
    • 启动:systemctl start ndb_mgmd
    • 查看状态:systemctl status ndb_mgmd

3. node1 & node2 安装和配置数据节点

  • 二进制安装mysql-cluster-data
    • cd /usr/local/src
    • wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-8.0/mysql-cluster-community-data-node_8.0.19-1ubuntu18.04_amd64.deb
    • 安装依赖:apt install libclass-methodmaker-perl
    • dpkg -i mysql-cluster-community-data-node_8.0.19-1ubuntu18.04_amd64.deb
  • 创建配置文件 vim /etc/my.cnf
    • 新增如下代码
      [mysql_cluster]
      # Options for NDB Cluster processes:
      ndb-connectstring=10.66.1.122  # location of cluster manager
      
  • 创建data目录:mkdir -p /usr/local/mysql/data
  • 启动测试:ndbd
  • 设置防火墙允许其它节点传入连接
    • ufw allow from 10.66.1.122
    • ufw allow from 10.66.1.124
  • system管理ndbd
    • 杀死ndbd进程:pkill -f ndbd
    • vim /etc/systemd/system/ndbd.service
      [Unit]
      Description=MySQL NDB Data Node Daemon
      After=network.target auditd.service
      [Service]
      Type=forking
      ExecStart=/usr/sbin/ndbd
      ExecReload=/bin/kill -HUP $MAINPID
      KillMode=process
      Restart=on-failure
      [Install]
      WantedBy=multi-user.target
      
    • systemctl daemon-reload
    • systemctl enable ndbd
    • systemctl start ndbd
    • systemctl status ndbd
  • node2:复制node1 记得改好ip

4. manage & node1 & node2 配置sql节点(MySQL服务器和客户端)

  • 安装
    • wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-8.0/mysql-cluster_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar
    • 解压到文件夹中
      • mkdir install
      • tar -xvf mysql-cluster_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar -C install/
    • 安装
      • cd install
      • apt install libaio1 libmecab2
      • dpkg -i mysql-common_8.0.19-1ubuntu18.04_amd64.deb
      • dpkg -i mysql-cluster-community-client-core_8.0.19-1ubuntu18.04_amd64.deb
      • dpkg -i mysql-cluster-community-client_8.0.19-1ubuntu18.04_amd64.deb
      • dpkg -i mysql-client_8.0.19-1ubuntu18.04_amd64.deb
      • dpkg -i mysql-cluster-community-server-core_8.0.19-1ubuntu18.04_amd64.deb
      • dpkg -i mysql-cluster-community-server_8.0.19-1ubuntu18.04_amd64.deb
    • 修改配置文件 vim /etc/mysql/my.cnf
      • manage
        [mysqld]
        # Options for mysqld process:
        ndbcluster                      # run NDB storage engine
        [mysql_cluster]
        # Options for NDB Cluster processes:
        ndb-connectstring=10.66.1.122  # location of management server
        
      • node
        [mysql_cluster]
        # Options for NDB Cluster processes:
        ndb-connectstring=10.66.1.122  # location of management server
        
      • systemctl enable mysql
      • systemctl restart mysql

5. 验证mysql集群安装:登陆到manage

  • mysql -uroot -p
    • 查看NDB集群引擎信息:show engine NDB status \G
      • number_of_ready_data_nodes:检测节点
        • 可以尝试关闭其中一个数据节点,节点重新
  • ndb_mgm
    • 查看整体:show
    • 查看id所对应的节点状态:id status
    • 退出 quit

你可能感兴趣的:(ubuntu,mysql,mysql,ubuntu)