mysql-cluster 7.3.5安装部署
集群环境
管理节点 10.0.0.19 数据节点 10.0.0.12 10.0.0.17 sql节点 10.0.0.18 10.0.0.22
添加mysql用户
groupadd mysql useradd mysql -g mysql
安装mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz
cd /home/test tar -zxvf mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz -C /usr/local mv mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64/ mysql cd ../ chown -R mysql:mysql mysql/ cd mysql ./scripts/mysql_install_db --user=mysql 这个步骤所有服务器都需要执行(5台)
集群配置
管理节点
vim /usr/local/mysql/config.ini #lizhenghua [ndbd default] noOfReplicas=1 [ndb_mgmd] hostname=192.168.145.138 datadir=/usr/local/mysql/data [ndbd] hostname=192.168.145.140 datadir=/usr/local/mysql/data [MYSQLD] hostname=192.168.145.141 [MYSQLD] [mysqld] #博客园 [NDBD DEFAULT] NoOfReplicas=2 [TCP DEFAULT] portnumber=3306 [NDB_MGMD] #设置管理节点服务器 nodeid=1 HostName=10.0.0.19 DataDir=/var/mysql/data [NDBD] id=2 HostName=10.0.0.12 DataDir=/var/mysql/data [NDBD] id=3 HostName=10.0.0.17 DataDir=/var/mysql/data [MYSQLD] id=4 HostName=10.0.0.18 [MYSQLD] id=5 HostName=10.0.0.22 #必须有空的mysqld节点,不然数据节点断开后启动有报错 [MYSQLD] id=6 [mysqld] id=7
启动管理节点
ndb_mgmd -f /usr/local/mysql/config.ini
关闭管理节点
[root@localhost bin]#ndb_mgm ndb_mgm> shutdowm
备注:命令行中的ndb_mgmd是mysql cluster的管理服务器,后面的-f表示后面的参数是启动的参数配置文件。
如果在启动后过了几天又添加了一个数据节点,这时修改了配置文件启动时就必须加上--initial参数,不然添加的节点不会作用在mysql cluster中。
ndb_mgmd -f /usr/local/mysql/config.ini --initial
管理节点状态
ndb_mgm> show 查看各节点情况。 ndb_mgm> all report memory 查看各数据节点使用情况 ndb_mgm>create nodegroup 3;创建数据节点分组 mysql> alter online table data_house reorganize partition; 调整分区数据
数据节点
vim /etc/my.cnf (添加以下内容)
#lizhenghua [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data ndbcluster ndb-connectstring=192.168.145.138 [mysql_cluster] ndb-connectstring=192.168.145.138 [NDB_MGM] connect-string=192.168.145.138 [mysqld_safe] log-error=/usr/local/mysql/log/mysqld.log pid-file=/usr/local/mysql/mysqld.pid #博客园 [mysqld] datadir=/var/mysql/data socket=/var/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 #运行NDB存储引擎 ndbcluster #指定管理节点 ndb-connectstring=10.0.0.19 [MYSQL_CLUSTER] ndb-connectstring=10.0.0.19 [NDB_MGM] connect-string=10.0.0.19 [mysqld_safe] log-error=/var/mysql/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
备注:安装后第一次启动数据节点时要加上--initial参数,其它时候不要加,除非是在备份、恢复或配置变化后重启时
sql节点
cd /usr/local/mysql/ cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld
vim /etc/my.cnf (添加以下内容)
#lizhenghua [mysqld] ndbcluster ndb-connectstring=192.168.145.138 explicit_defaults_for_timestamp=true lower_case_table_names=1 pid-file = /usr/local/mysql/data/mysql3306.pid log-error = /usr/local/mysql/data/mysql3306.err basedir = /usr/local/mysql datadir = /usr/local/mysql/data skip-host-cache skip-name-resolve max_connections = 512 log-bin=mysql-bin #log = /usr/local/mysql/binlog/binlog.log [mysql_cluster] ndb-connectstring=192.168.145.138 #博客园 [mysqld] server-id=4#每个服务器的id不一样 datadir=/var/mysql/data socket=/var/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-bin = /var/mysql/log/mysql-bin.log max_connections=1000 #以下为mysql 主主模式的配置文件 # 忽略mysql数据库复制 binlog-ignore-db=mysql # 每次增长2 auto-increment-increment = 2 # 设置自动增长的字段的偏移量,即初始值为2 auto-increment-offset = 1 [mysqld_safe] log-error=/var/mysql/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [MYSQLD] ndbcluster ndb-connectstring=10.0.0.19 [MYSQL_CLUSTER] ndb-connectstring=10.0.0.19 [NDB_MGM] connect-string=10.0.0.19
service mysqld start