码迷,mamicode.com
首页 > 数据库 > 详细

MySQL-NDB7.6集群部署

时间:2021-03-10 13:21:06      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:架构   link   pat   初始   one   服务启动   类信息   mkdir   initial   

环境准备

软件部署设计

用途 组件
SQL nodes mysqld binary
Data nodes ndbd or ndbmtd
Management nodes ndb_mgmd and ndb_mgm

IP网络设计

Node IP Address
Management node (mgmd) 192.168.10.200
SQL node (mysqld) 192.168.10.201
Data node "A" (ndbd) 192.168.10.202
Data node "B" (ndbd) 192.168.10.203

架构

技术图片

系统环境配置

创建用户和用户组

groupadd mysql
useradd -g mysql -s /bin/false mysql

配置环境

cat > /etc/profile.d/mysqlEnv.sh <<-‘EOF‘
export NDB_VER="7.6.16"
export SOFT_INSTALL_DIR="/usr/local"
export SOFT_LINK_DIR="/usr/local/mysql"
export SOFT_LOG_DIR="${SOFT_LINK_DIR}/log"
export SOFT_SVC_PORT="3308"
export SOFT_DATA_DIR="/data"
export DATA_DIR="${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}"
SOFT_FILE_NAME="mysql-cluster-gpl-${NDB_VER}-linux-glibc2.12-x86_64"

export MYSQL_HOME=${SOFT_LINK_DIR}
export PATH=${MYSQL_HOME}/bin:${PATH}
EOF

详细实施步骤

软件配置

SQL nodes配置

每个SQL 节点配置

解压文件并创建软链接
. /etc/profile.d/mysqlEnv.sh
if [[ -f "${SOFT_FILE_NAME}.tar.gz" ]]; then
    tar --no-same-owner -xf ${SOFT_FILE_NAME}.tar.gz -C ${SOFT_INSTALL_DIR}
    ln -s ${SOFT_INSTALL_DIR}/${SOFT_FILE_NAME} ${SOFT_LINK_DIR}
else 
	curl -LO https://cdn.mysql.com/archives/mysql-cluster-gpl-7.6/${SOFT_FILE_NAME}.tar.gz
	# https://cdn.mysql.com/archives/mysql-cluster-gpl-7.6/mysql-cluster-gpl-7.6.16-linux-glibc2.12-x86_64.tar.gz
fi
修改软件目录权限
[[ -d "${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}" ]] || mkdir -p ${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}

chown -R mysql:mysql ${SOFT_INSTALL_DIR}/${SOFT_FILE_NAME}
chown -R mysql:mysql ${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}
初始化系统数据集簇
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=${SOFT_LINK_DIR} --datadir=${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}
配置服务启动文件
cp ${SOFT_LINK_DIR}/support-files/mysql.server /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/mysql.server
chkconfig --add mysql.server

Data nodes配置

解压文件及创建软连接
. /etc/profile.d/mysqlEnv.sh
if [[ -f "${SOFT_FILE_NAME}.tar.gz" ]]; then
    tar -xf ${SOFT_FILE_NAME}.tar.gz --strip-components=2 ${SOFT_FILE_NAME}/bin/{ndbd,ndbmtd} -C ${SOFT_INSTALL_DIR}
    ln -s ${SOFT_INSTALL_DIR}/${SOFT_FILE_NAME} ${SOFT_LINK_DIR}
else 
	curl -LO https://cdn.mysql.com/archives/mysql-cluster-gpl-7.6/${SOFT_FILE_NAME}.tar.gz
	# https://cdn.mysql.com/archives/mysql-cluster-gpl-7.6/mysql-cluster-gpl-7.6.16-linux-glibc2.12-x86_64.tar.gz
fi
修改目录权限
chown -R mysql:mysql ${SOFT_INSTALL_DIR}/${SOFT_FILE_NAME}
chmod +x ${SOFT_LINK_DIR}/bin/ndb*

# ndb cluster 初始化需要 DataDir
[[ -d "${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}" ]] || mkdir -p ${SOFT_DATA_DIR}/mysql${SOFT_SVC_PORT}

Management nodes 配置

解压文件及创建软连接
. /etc/profile.d/mysqlEnv.sh
if [[ -f "${SOFT_FILE_NAME}.tar.gz" ]]; then
    tar -xf ${SOFT_FILE_NAME}.tar.gz --strip-components=2 ${SOFT_FILE_NAME}/bin/{ndb_mgm,ndb_mgmd} -C ${SOFT_INSTALL_DIR}
    ln -s ${SOFT_INSTALL_DIR}/${SOFT_FILE_NAME} ${SOFT_LINK_DIR}
else 
	curl -LO https://cdn.mysql.com/archives/mysql-cluster-gpl-7.6/${SOFT_FILE_NAME}.tar.gz
	# https://cdn.mysql.com/archives/mysql-cluster-gpl-7.6/mysql-cluster-gpl-7.6.16-linux-glibc2.12-x86_64.tar.gz
fi
修改目录权限
chown -R mysql:mysql ${SOFT_INSTALL_DIR}/${SOFT_FILE_NAME}
chmod +x ${SOFT_LINK_DIR}/bin/ndb_mgm*

NDB 集群初始化配置

集群配置文件要求

对于4节点 NDB集群中,总共需要4个配置文件

  • 每个 data node or SQL node 需要一个 my.cnf 配置文件,用于提供下面2类信息:

    • 连接信息:告知本地节点如何找到管理节点
    • 通知MySQL server启动NDBCLUSTER存储引擎
  • management node 需要一个 config.ini 配置文件

    • 集群维护的副本数
    • 每个数据节点分配多少内存给数据和索引
    • 如何查找数据节点和SQL节点
    • 如何将数据存储到每个数据节点的磁盘上

创建配置文件

Data nodes(my.cnf)
cat > /etc/my.cnf <<-‘EOF‘

[mysqld]
# Options for mysqld process:
ndbcluster                      # run NDB storage engine

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=192.168.10.200  # location of management server

EOF
SQL nodes(my.cnf)
cat > /etc/my.cnf <<-‘EOF‘

[mysqld]
# Options for mysqld process:
ndbcluster                      # run NDB storage engine

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=192.168.10.200  # location of management server

EOF
Management node(config.ini)
cat > ${SOFT_LINK_DIR}/config.ini <<EOF
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2    # Number of fragment replicas
DataMemory=80M    # How much memory to allocate for data storage
IndexMemory=18M   # How much memory to allocate for index storage
                  # For DataMemory and IndexMemory, we have used the
                  # default values. Since the "world" database takes up
                  # only about 500KB, this should be more than enough for
                  # this example NDB Cluster setup.
                  # NOTE: IndexMemory is deprecated in NDB 7.6 and later; in
                  # these versions, resources for all data and indexes are
                  # allocated by DataMemory and any that are set for IndexMemory
                  # are added to the DataMemory resource pool
ServerPort=2202   # This the default value; however, you can use any
                  # port that is free for all the hosts in the cluster
                  # Note1: It is recommended that you do not specify the port
                  # number at all and simply allow the default value to be used
                  # instead
                  # Note2: The port was formerly specified using the PortNumber
                  # TCP parameter; this parameter is no longer available in NDB
                  # Cluster 7.5.
DataDir=${DATA_DIR}


[ndb_mgmd]
# Management process options:
HostName=192.168.10.200         # Hostname or IP address of management node
DataDir=${SOFT_LOG_DIR}         # Directory for management node log files

[ndbd]
# Options for data node "A":
                                # (one [ndbd] section per data node)
HostName=192.168.10.202         # Hostname or IP address
NodeId=2                        # Node ID for this data node
DataDir=${DATA_DIR}             # Directory for this data node‘s data files

[ndbd]
# Options for data node "B":
HostName=192.168.10.203         # Hostname or IP address
NodeId=3                        # Node ID for this data node
DataDir=${DATA_DIR}             # Directory for this data node‘s data files

[mysqld]
# SQL node options:
HostName=192.168.10.201         # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)
EOF

启动集群

启动服务进程顺序

  • 首先, 在 management node 启动进程

  • 其次,在data nodes 启动进程

  • 最后,在 sql nodes 启动进程

启动命令

Management host
${SOFT_LINK_DIR}/bin/ndb_mgmd -f ${SOFT_LINK_DIR}/config.ini
data node hosts

每个 data node 执行

${SOFT_LINK_DIR}/bin/ndbd
sql node hosts

每个 sql node 启动MySQL server 服务进程

${SOFT_LINK_DIR}/bin/mysqld 

集群管理

安全的关闭集群

在 management node 上执行命令

${SOFT_LINK_DIR}/bin/ndb_mgm -e shutdown

重启集群

  • 在 management node 上执行命令
${SOFT_LINK_DIR}/bin/ndb_mgmd -f ${SOFT_LINK_DIR}/config.ini
  • 在每个 data node hosts 执行命令
${SOFT_LINK_DIR}/bin/ndbd
  • 在每个 sql node hosts 执行命令
${SOFT_LINK_DIR}/bin/mysqld_safe &

检查集群状态

${SOFT_LINK_DIR}/bin/ndb_mgm -e show

MySQL-NDB7.6集群部署

标签:架构   link   pat   初始   one   服务启动   类信息   mkdir   initial   

原文地址:https://www.cnblogs.com/binliubiao/p/14508448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!