您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL集群搭建详解(三种结点分离)

2024/3/13 9:25:19发布16次查看
本文将搭建一个最简化的mysql cluster系统,配置方法中的所有命令都是以root账户运行。这个mysql cluster包含一个管理结点、两个
本文将搭建一个最简化的mysql cluster系统,配置方法中的所有命令都是以root账户运行。这个mysql cluster包含一个管理结点、两个数据结点、两个sql结点,这五个结点会分别安装在五个虚拟机上,虚拟机的名称和ip如下所示:
管理结点
mysql-mgm
192.168.124.141
数据结点 1
mysql-ndbd-1
192.168.124.142
数据结点 2
mysql-ndbd-2
192.168.124.143
mysql-sql-1
192.168.124.144
mysql-sql-2
192.168.124.145
一、公共配置
请在三个虚拟机上分别配置此处的配置项。
1. 安装虚拟机
虚拟机操作系统安装centos 6.4的x86_64版本,使用nat网络,并且还要安装vmware-tools,具体安装方法此处不详述。
2. 拷贝mysql cluster
下载以下版本的mysql-cluster:
下载得到的压缩包拷贝至虚拟机的/root/downloads目录,然后在shell中运行以下命令:
cd /root/downloads
tar -xvzf mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz
mv mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64 /usr/local/mysql
3. 关闭安全策略
关闭iptables防火墙(或者打开防火墙的1186、3306端口),在shell中运行以下命令:
chkconfig --level 35 iptables off
关闭selinux,在shell中运行以下命令:
gedit /etc/selinux/config
将config文件中的selinux项改为disabled,修改后的config文件的内容如下:
# this file controls the state of selinux on the system.
# selinux= can take one of these three values:
#    enforcing - selinux security policy is enforced.
#    permissive - selinux prints warnings instead of enforcing.
#    disabled - no selinux policy is loaded.
selinux=disabled
# selinuxtype= can take one of these two values:
#    targeted - targeted processes are protected,
#    mls - multi level security protection.
selinuxtype=targeted
最后重启系统
二、配置管理结点(192.168.124.141)
1. 配置config.ini配置文件
在shell中运行以下命令:
mkdir /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
gedit config.ini
配置文件config.ini内容如下:
[ndbd default]
noofreplicas=2
datamemory=80m
indexmemory=18m
[ndb_mgmd]
nodeid=1
hostname=192.168.124.141
datadir=/var/lib/mysql-cluster
[ndbd]
nodeid=2
hostname=192.168.124.142
datadir=/usr/local/mysql/data
[ndbd]
nodeid=3
hostname=192.168.124.143
datadir=/usr/local/mysql/data
[mysqld]
nodeid=4
hostname=192.168.124.144
[mysqld]
nodeid=5
hostname=192.168.124.145
2. 安装管理结点
安装管理节点,,不需要mysqld二进制文件,只需要mysql cluster服务端程序(ndb_mgmd)和监听客户端程序(ndb_mgm)。在shell中运行以下命令:
cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin
cd /usr/local/bin
chmod +x ndb_mgm*
三、配置数据结点(192.168.124.142、192.168.124.143)
1. 添加mysql组和用户
在shell中运行以下命令:
groupadd mysql
useradd -g mysql mysql
2. 配置my.cnf配置文件
在shell中运行以下命令:
gedit /etc/my.cnf
配置文件my.cnf的内容如下:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
user=mysql
# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.124.141
3. 创建系统数据库
在shell中运行以下命令:
cd /usr/local/mysql
mkdir sock
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
4. 设置数据目录
在shell中运行以下命令:
chown -r root .
chown -r mysql.mysql /usr/local/mysql/data
chown -r mysql.mysql /usr/local/mysql/sock
chgrp -r mysql .
5. 配置mysql服务
在shell中运行以下命令:
cp support-files/mysql.server /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/mysql.server
chkconfig --add mysql.server
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product