Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2323128
  • 博文数量: 535
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7066
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(535)

文章存档

2024年(4)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-05-13 10:56:35



RPM 包下载点。。



linux下mysql集群的安装

./ndb_mgmd   -f  /var/lib/mysql-cluster/config.ini


1.下载安装文件

操作系统:CentOS release 5.5

Mysql:    mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

2.安装.tar.gz文件

详情参考mysql的官方手册。

 

数据节点和mysql节点的安装

1.检查系统中是否已经存在mysql用户和组。

查看/etc/passwd和/etc/group文件,检查系统是否已存在mysql用户和组。

如果不存在,用以下命令添加:

shell> groupadd mysql

shell> useradd –g mysql mysql

 

2.解压安装。

       2.1进入安装文件所在目录,假设在/var/tmp目录下:

       shell> cd /var/tmp

       shell> tar –C /usr/local –xzvf  mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

       shell> ln –s /usr/local/mysql-cluster-gpl-7.1.10-linux-i686-glibc23  /usr/local/mysql

 

       2.2执行安装脚本:

       shell> cd mysql

       shell> scripts/mysql_install_db –user=mysql

 

       2.3修改权限:

shell> chown –R root .

shell> chown –R mysql data

shell> chgrp –R mysql .

 

2.4复制执行文件,加入系统启动项:

shell> cp support-files/mysql.server /etc/rc.d/init.d/

shell> chmod +x /etc/rc.d/init.d/mysql.server

shell> chkconfig –add mysql.server

 

 

管理节点的安装

1.解压安装

shell> cd /var/tmp

       shell> tar –xzvf  mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

       shell> cd mysql-cluster-gpl-7.1.10-linux-i686-glibc23

       shell> cp bin/ndb_mgm* /usr/local/bin

 

2.修改权限

       shell> cd /usr/local/bin

       shell> chmod +x ndb_mgm*

 

3.配置文件

3.1创建数据节点和mysql节点的my.cnf配置文件

shell> vi /etc/my.cnf

 

my.cnf内容如下:

[mysqld]
# Options for mysqld process:
ndbcluster                          # run NDB storage engine
ndb-connectstring=192.168.0.10  # location of management server
[mysql_cluster]
# Options for ndbd process:
ndb-connectstring=192.168.0.10  # location of management server

 

3.2创建管理节点的config.ini配置文件

shell> mkdir /var/lib/mysql-cluster

shell> cd /var/lib/mysql-cluster

shell> vi config.ini

 

config.ini内容如下:

[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2    # Number of 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 Cluster setup.
[tcp default]
# TCP/IP options:
portnumber=2202   # This the default; however, you can use any
                  # port that is free for all the hosts in the cluster
                  # Note: It is recommended that you do not specify the port 
                  # number at all and simply allow the default value to be used 
                  # instead
[ndb_mgmd]
# Management process options:
hostname=192.168.0.10           # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster  # Directory for MGM node log files
[ndbd]
# Options for data node "A":
                                # (one [ndbd] section per data node)
hostname=192.168.0.30           # Hostname or IP address
datadir=/usr/local/mysql/data   # Directory for this data node's data files
[ndbd]
# Options for data node "B":
hostname=192.168.0.40           # Hostname or IP address
datadir=/usr/local/mysql/data   # Directory for this data node's data files
[mysqld]
# SQL node options:
hostname=192.168.0.20           # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)

 

 

4.启动集群

1.启动管理服务器:(正常情况下,它们位于/usr/local/mysql/bin目录下)。

shell> ndb_mgmd

 

2.启动数据节点。首次为给定的DB节点启动ndbd时,应使用“—initial”选项

shell> cd /usr/local/mysql/bin

shell> ./ndbd --initial

shell> ./ndbd

 

3.启动mysql节点。

shell> cd /usr/local/mysql/bin

shell> mysqld_safe --user=mysql &

如果要进入mysql客户端

shell> ./mysql

 

好了,大功告成。你要对数据进行任何常规操作,建数据库,建表之类的可以在mysql节点进行,和正常的mysql没有什么区别。

如果要查看集群的状态,可以在管理节点启动管理客户端,用show命令:

shell> ndb_mgm

ndb_mgm> show

如果要关闭集群:

shell> ndb_mgm –e shutdown

 

 

集群管理客户端命令
ndb_mgm> show
ndb_mgm> nodeID STOP   //关闭节点
ndb_mgm> ndoeID START   //启动节点
ndb_mgm> nodeID RESTART   //重启节点
ndb_mgm> CREATE NODEGROUP 3,4  //创建组
ndb_mgm> ALL REPORT MEMORY  //查看内存状态
ndb_mgm> START BACKUP NOWAIT  //备份数据

ndb_mgm> ndb_desc -c 192.168.1.10 -d n ips -p


mysql客户端命令
mysql> alter online table 'table_name' reorganize partition 

//增加数据节点后,重新分布数据存储
mysql> source PATH/script.sql     //执行sql脚本
mysql> delimiter //      //定义“//”为分隔符
mysql> show procedure status;     //查看存储过程
mysql> SHOW DATABASES;
mysql> SHOW TABLES;
mysql> DESCRIBE table_name;
mysql> SELECT DATABASE();     //查看当前使用的数据库
mysql> select user();
mysql> select current_user();      





这个是管理节点的配置:

[root@slave mysql-cluster]#
[root@slave mysql-cluster]# cat /var/lib/mysql-cluster/config.ini


[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M

[tcp default]

NoOfReplicas=2
DataMemory=80M
IndexMemory=18M

SendBufferMemory=2M
ReceiveBufferMemory=2M

[NDB_MGMD DEFAULT]
PortNumber=1186
Datadir=/var/lib/mysql-cluster

[ndb_mgmd]
Id=1
HostName= 192.168.100.188
datadir = /var/lib/mysql-cluster


[ndbd]
Id=2
HostName=192.168.100.187
datadir=/var/lib/mysql/data

[ndbd]
Id=3
HostName=192.168.100.154
datadir=/var/lib/mysql/data
[mysqld]
Id=14
HostName=192.168.100.187

[mysqld]
Id=15
HostName=192.168.100.154
[mysqld]
Id=16
HostName=192.168.100.187
[mysqld]
Id=17



SQL 节点和数据节点的配置:

VI  /ETC/MY。CNF


[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

[MYSQLD]


#datadir=/usr/local/mysql/data/
ndbcluster
ndb-connectstring=192.168.100.188


#[ndbd]
#connect-string=192.168.100.188

[mysql_cluster]
ndb-connectstring=192.168.100.188

[ndb_mgm]
connect-string=192.168.100.188


[ndb_mgmd]
config-file=/var/lib/mysql-cluster/config.ini

datadir=/usr/local/mysql/data






阅读(1760) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~