标签:mysql集群配置
Mysql-cluster集群
conf文件参考:
vim /etc/mysql-cluster.ini
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=16M
[ndb_mgmd]
nodeId=32
Hostname=192.168.10.132
Datadir=/usr/local/cluster/ndbdata
[mysqld]
nodeId=28
Hostname=192.168.10.128
[mysqld]
nodeId=29
Hostname=192.168.10.129
[ndbd]
nodeId=30
Hostname=192.168.10.130
Datadir=/usr/local/cluster/ndbdata
[ndbd]
nodeId=31
Hostname=192.168.10.131
Datadir=/usr/local/cluster/ndbdata
-----------------------------------------------------------
------------------------------------my.cnf配置文件
MS
cat >/etc/my.cnf<< EOF
[mysqld]
#datadir=/var/lib/mysql
datadir=/data/mysql/data
#socket=/var/lib/mysql/mysql.sock
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
EOF
vi /var/lib/mysql-cluster/config.ini ---------------------管理节点配置文件
cat >/var/lib/mysql-cluster/config.ini<< EOF
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[ndb_mgmd]
NodeId=1
Hostname=192.168.1.210 #//管理IP
datadir=/usr/local/mysql
[ndbd]
NodeId=2
Hostname=192.168.1.209 #//数据节点1
#datadir=/usr/local/mysql/data/ #//数据文件位置
datadir=/data/mysql/data/ #//数据文件位置
[ndbd]
NodeId=3
Hostname=192.168.1.208 //数据节点2
#datadir=/usr/local/mysql/data/ //数据文件位置
datadir=/data/mysql/data/ //数据文件位置
[MYSQLD]
nodeId=4
Hostname=192.168.1.207
[MYSQLD]
nodeId=5
Hostname=192.168.1.206
EOF
-------------------------------------
MD
cat >/etc/my.cnf<< EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/tmp/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.1.210
EOF
--------------------------------------
MS
cat >/etc/my.cnf<< EOF
[client]
socket=/tmp/mysql.sock
[mysqld]
ndbcluster
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
ndb-connectstring=192.168.1.210
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.1.210
EOF
-------------------------------------------------开始配置
mkdir -p /var/lib/mysql-cluster
mkdir -p /data/mysql
useradd mysql
tar zxvf mysql-cluster-gpl-7.4.6-linux-glibc2.5-x86_64.tar.gz
mv mysql-cluster-gpl-7.4.6-linux-glibc2.5-x86_64.tar.gz /usr/local/mysql
cd /usr/local/
chown mysql.mysql -R mysql/
cd mysql/
scripts/mysql_install_db --user=mysql(初始化)
#scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
(备注:mysql增加环境变量)
cp ../support-files/mysql.server /etc/init.d/mysqld
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
#启动管理节点服务
/usr/local/mysql/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
netstat -lntpu
#看到1186开放说明启动正常
#★必须注意:只是在第一次启动或在备份/恢复或配置变化后重启ndbd时,才加–initial参数!
#备注: 启动此处时,需要为防火墙开启1186,3306端口;数据节点开启2202端口。
#在两台机器上启动服务, 执行相同操作
#★必须注意:只是在第一次启动或在备份/恢复或配置变化后重启ndbd时,才加–initial参数!
#数据库节点运行
/usr/local/mysql/bin/ndbd --initial
#查询结果
#[ndbd] INFO -- Angel connected to ‘192.168.1.210:1186‘
#[ndbd] INFO -- Angel allocated nodeid: 3
-------------------------------------------------------------------
1. 启动管理结点
在shell中运行以下命令:
ndb_mgmd -f /var/lib/mysql-cluster/config.ini
还可以使用ndb_mgm来监听客户端,如下:
ndb_mgm
2. 启动数据结点
首次启动,则需要添加--initial参数,以便进行NDB节点的初始化工作。在以后的启动过程中,则是不能添加该参数的,否则ndbd程序会清除在之前建立的所有用于恢复的数据文件和日志文件。
/usr/local/mysql/bin/ndbd --initial
如果不是首次启动,则执行下面的命令。
/usr/local/mysql/bin/ndbd
3. 启动SQL结点
若MySQL服务没有运行,则在shell中运行以下命令:
/usr/local/mysql/bin/mysqld_safe --user=mysql &
--------------------------------------------------------------------
本文出自 “SQL” 博客,谢绝转载!
标签:mysql集群配置
原文地址:http://7476463.blog.51cto.com/7466463/1685593