系统环境:Centos6.3 + mysql-cluster-gpl-7.1.15a-linux-x86_64-glibc23.tar .gz
说明:
1) MySQLCluster 的启动:
启动顺序:管理服务器 --> 存储节点 --> SQL 节点
2) 安全关闭 ndb cluster:
关闭顺序:SQL 节点 --> 数据节点 --> 管理节点。
# /usr/local/mysql/bin/mysqladmin-u root shutdown # 关闭 sql 节点
# /usr/local/mysql/ndb_mgm -e shutdown # 关闭管理节点, shutdown, 它会把所有 MGMNode 和所有 Data Node
的 ndb_mgmd 和 ndbd 都停止掉(mysql 还留着)
署操作步骤:
***系统内核调优必做****
一)部署 cluster 软件,所有机器
1) 下载 Cluster 软件
32 位
# wget-c http://downloads.skysql.com/archives/mysql-cluster-gpl-7.1/mysql-cluster-gpl-7.1.15a-linux-i686-glibc23.tar .gz
64 位
#wget-c http://downloads.skysql.com/archives/mysql-cluster-gpl-7.1/mysql-cluster-gpl-7.1.15a-linux-x86_64-glibc23.tar .gz
2) 安装与配置 Cluster
useradd mysql-d/dev/null -s /sbin/nologin
tar-xvf /usr/local/src/mysql-cluster-gpl-7.1.15a-linux-x86_64-glibc23.tar .gz -C /usr/local/src/
yum install rsync
rsync -avl /usr/local/src/mysql-cluster-gpl-7.1.15a-linux-x86_64-glibc23//usr/local/mysql_cluster
chown mysql:mysql/usr/local/mysql_cluster-R
echo "P A TH=\$P A TH:/usr/local/mysql_cluster/bin/" >> /etc/profile
source /etc/profile
which mysql
/usr/local/mysql_cluster/bin/mysql
二) 管理节点
1) 配置管理节点
mkdir /data/mysql/mgmd /data/mysql/ndb_data /data/mysql/ndb_data_backup /data/mysql/etc
/data/mysql/binlog /data/mysql/mysql_data /data/logs -p
chown mysql:mysql /data/mysql -R
cat >/data/mysql/etc/config.ini << EOF
[TCPDEF AUL T]
SendBufferMemory=4M
ReceiveBufferMemory=4M
[NDB_MGMD DEF AUL T]
PortNumber=1186
Datadir=/data/mysql/mgmd
[NDB_MGMD]
NodeId=1
Hostname=管理节点 IP 地址
LogDestination=FILE:filename=ndb_1_cluster .log,maxsize=10000000,maxfiles=6
ArbitrationRank=1
[NDBDDEF AUL T]
NoOfReplicas=2
ServerPort=2200
Datadir=/data/mysql/ndb_data
FileSystemPath=/data/mysql/ndb_data
BackupDataDir=/data/mysql/ndb_data_backup
DataMemory=9728M
IndexMemory=1216M
LockPagesInMainMemory=1
MaxNoOfConcurrentOperations=100000
MaxNoOfConcurrentT ransactions=16384
StringMemory=25
MaxNoOfT ables=4096
MaxNoOfOrderedIndexes=4096
MaxNoOfUniqueHashIndexes=512
MaxNoOfAttributes=24576
MaxNoOfT riggers=14336
### Params for REDO LOG
FragmentLogFileSize=512M
InitFragmentLogFiles=SP ARSE
NoOfFragmentLogFiles=38
RedoBuffer=48M
T ransactionBufferMemory=8M
TimeBetweenGlobalCheckpoints=1000
TimeBetweenEpochs=100
TimeBetweenEpochsTimeout=0
### Params forLCP
DiskCheckpointSpeedInRestart=100M
DiskCheckpointSpeed=10M
TimeBetweenLocalCheckpoints=20
### Heartbeating
HeartbeatIntervalDbDb=15000
HeartbeatIntervalDbApi=15000
### Params for setting logging
MemReportFrequency=30
BackupReportFrequency=10
LogLevelStartup=15
LogLevelShutdown=15
LogLevelCheckpoint=8
LogLevelNodeRestart=15
### Params forBACKUP
BackupMaxWriteSize=1M
BackupDataBufferSize=24M
BackupLogBufferSize=16M
BackupMemory=40M
### Params for ODIRECT
#Reports indicates that odirect=1 can cause io errors (os err code 5) on some systems. Y ou must test.
#ODirect=1
### Watchdog
TimeBetweenWatchdogCheckInitial=60000
### T ransactionInactiveTimeout - should be enabled in Production
T ransactionInactiveTimeout=60000
###New 7.1.10 redo logging parameters
RedoOverCommitCounter=3
RedoOverCommitLimit=20
### REAL TIME EXTENSIONS
#RealTimeScheduler=1
### REAL TIME EXTENSIONS FOR 6.3 ONL Y
#SchedulerExecutionTimer=80
#SchedulerSpinTimer=40
### DISK DAT A
SharedGlobalMemory=20M
DiskPageBufferMemory=64M
### Multithreading
MaxNoOfExecutionThreads=8
### Increasing theLongMessageBuffer b/c of a bug (20090903)
LongMessageBuffer=32M
BatchSizePerLocalScan=512
[NDBD]
NodeId=2
Hostname= 数据节点 IP
[NDBD]
NodeId=3
Hostname=数据节点 IP
[NDBD]
NodeId=4
Hostname=数据节点 IP
[NDBD]
NodeId=5
Hostname=数据节点 IP
[NDBD]
NodeId=6
Hostname=数据节点 IP
[NDBD]
NodeId=7
Hostname=数据节点 IP
[NDBD]
NodeId=8
Hostname=数据节点 IP
[MYSQLD DEF AUL T]
DefaultOperationRedoProblemAction=QUEUE
BatchSize=512
[MYSQLD]
NodeId=10
[MYSQLD]
NodeId=11
[MYSQLD]
NodeId=12
[MYSQLD]
NodeId=13
[MYSQLD]
NodeId=14
[MYSQLD]
NodeId=15
[MYSQLD]
NodeId=16
[MYSQLD]
NodeId=17
[MYSQLD]
NodeId=18
[MYSQLD]
NodeId=19
[MYSQLD]
NodeId=20
EOF
2) 第一次启动管理节点【或者添加新节点了】:
ndb_mgmd -f /data/mysql/etc/config.ini--configdir=/data/mysql/etc/ 参数注意--initial
修改配置文件后启动方法:
ndb_mgmd -f /data/mysql/etc/config.ini--configdir=/data/mysql/etc/ --reload
三) 配置数据节点
cat >/data/mysql/etc/my .cnf << EOF
[MYSQL_CLUSTER]
ndb-connectstring="管理节点 IP"
EOF
第一次启动数据节点【以后启动禁止加入 initial 参数】:
ndbd--defaults-file=/data/mysql/etc/my .cnf 注意参数 --initial
四)配置启动 sql 节点
cat >/data/mysql/etc/my .cnf << EOF
[MYSQLD]
user=mysql
basedir=/usr/local/mysql_cluster
datadir=/data/mysql/mysql_data
pid-file=/tmp/mysqld.pid
socket=/tmp/mysql.sock
port=3306
skip_name_resolve
#ndb-cluster-connection-pool=4
ndbcluster=1
ndb-connectstring="管理节点 IP"
ndb-force-send=1
ndb-use-exact-count=0
ndb-extra-logging=1
ndb-batch-size=24M
ndb-autoincrement-prefetch-sz=1024
engine-condition-pushdown=1
default-storage-engine=ndbcluster
#REPLICA TION SPECIFIC - GENERAL
#server-id must be unique acrossall mysql servers participating in replication.
#server-id=3
#REPLICA TION SPECIFIC - MASTER
#log-bin=binlog
#binlog-format=ROW
#expire-logs-days=5
#LOGS
log-error=/data/logs/error .log
#log
#log-slow-queries
#OTHERTHINGS, BUFFERS ETC
key_buffer_size = 256M
max_allowed_packet = 16M
#thread_cache_size=1024
myisam_sort_buffer_size = 8M
memlock=0
sysdate_is_now=1
max-connections=3000
thread-cache-size=128
###QUERY CACHE ISDISABLED
###THE QUERY CACHE IN MYSQL CLUSTER CAN HAMPER PERFORMANCEA LOT . HENCE IT ISDISABLED
###BECAUSE INVALIDA TION OF IT T AKESTIME (REMEMBER, IT ISA DISTRIBUTED ENVIRONMENT)
###ONL Y ENABLE ITAND USE SQL_CACHE TOCACHE ONL Y CERT AIN QUERIES ON READONL Y T ABLES
query_cache_type = 0
query_cache_size = 0
table_open_cache=1024
lower-case-table-names=0
[MYSQL]
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
[MYSQLD_SAFE]
pid-file=mysqld.pid
log-error=/data/logs/mysqld_safe_error .log
basedir=/usr/local/mysql_cluster
datadir=/data/mysql/mysql_data
EOF
初始化数据库:
/usr/local/mysql_cluster/scripts/mysql_install_db --basedir=/usr/local/mysql_cluster --datadir=/data/mysql/mysql_data
--user=mysql
启动 sql 节点
mysqld --defaults-file=/data/mysql/etc/my .cnf --user=mysql &
五)数据验证
在 sql 节点一操作:
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.11 sec)
mysql> create table t1(a int) engine=ndb; ##<--需指定 ndb 引擎
Query OK, 0 rows affected (0.74 sec)
mysql> insert into t1values(100);
Query OK, 1 row affected (0.32 sec)
节点 sql2 上验证,用 root 查看效果
mysql> use test
mysql> select *from t1 #<--发现有 100 这个记录为 OK。
转载于:https://blog.51cto.com/linuxpython/1643784