程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql 集群測試

mysql 集群測試

編輯:關於MYSQL數據庫
    今天在虛擬機上測試了mysql 集群服務器的配置;環境mysql1:ubuntu Linux server 9.04,MySQL2:ubuntu Linux 桌面版;在安裝mySQL Server之後,我們就可以進行配置了;無論在什麼Linux系統裡,配置集群,必須先要了解集群的工作結構; ndbd_mgmd:管理節點-----ndbd:數據庫節點,物理數據實際存放位置-------mysqld:MySQL服務器節點。

1.安裝,sudo apt-get install MySQL-server

2:密碼最好一致 update MySQL.user set password=passWord(”新密碼”)where User=”root

3.配置這兩台服務器上配置my.cnf,這兩台服務器都要配置

首先要備份my.cnf,若是下面的操作出現問題要使用備份恢復原有可用的配置文件,語句:cp /etc/mysql/my.cnf /etc/MySQL/my.cnf-backup

然後,編輯my.cnf,使用語句:sudo gedit /etc/MySQL/my.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/MySQL/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/MySQL/en/server-system-variables.Html

# This will be passed to all MySQL clIEnts
# It has been reported that passWords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/MySQL/debian.cnf when changing the socket location.
[clIEnt]
port            = 3306
socket          = /var/run/mysqld/MySQLd.sock

# Here is entrIEs for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_MySQLd]. Both versions are currently parsed.
[MySQLd_safe]
socket          = /var/run/mysqld/MySQLd.sock
nice            = 0

[MySQLd]
#
# * Basic Settings
#

#
# * IMPORTANT
#   If you make changes to these settings and your system uses apparmor, you may
#   also need to also adjust /etc/apparmor.d/usr.sbin.MySQLd.
#

user            = MySQL
pid-file        = /var/run/mysqld/MySQLd.pid
socket          = /var/run/mysqld/MySQLd.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/MySQL
tmpdir          = /tmp
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
#
# * Fine Tuning
#
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 128K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover          = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
#log            = /var/log/mysql/MySQL.log
#
# Error logging goes to syslog. This is a Debian improvement :)
#
# Here you can see querIEs with especially long duration
#log_slow_querIEs       = /var/log/mysql/MySQL-slow.log
#long_query_time = 2
#log-querIEs-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/MySQL/.
# Read the manual for more InnoDB related options. There are many!
# You might want to disable InnoDB to shrink the MySQLd process by circa 100MB.
#skip-innodb
#
# * Federated
#
# The FEDERATED storage engine is disabled since 5.0.67 by default in the .cnf files
# shipped with MySQL distributions (my-huge.cnf, my-medium.cnf, and so forth).
#
skip-federated
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/MySQL/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/MySQL/cacert.pem
# ssl-cert=/etc/MySQL/server-cert.pem
# ssl-key=/etc/MySQL/server-key.pem
ndbcluster
ndb-connectstring=192.168.1.110

[MySQLdump]
quick
quote-names
max_allowed_packet      = 16M

[MySQL]
#no-auto-rehash # faster start of MySQL but no tab completition
[isamchk]
key_buffer              = 16M

#
# * NDB Cluster
#
# See /usr/share/doc/MySQL-server-*/README.Debian for more information.
#
# The following configuration is read by the NDB Data Nodes (ndbd processes)
# not from the NDB Management Nodes (ndb_mgmd processes).
#
# [MySQL_CLUSTER]
# ndb-connectstring=127.0.0.1
[MySQL_CLUSTER]

ndb-connectstring=192.168.1.110

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/MySQL/conf.d/

-----配置ndb_mgmd.cnf--------------------------------------------------------------------------------

[NDBD DEFAULT]

NoOfReplicas=2
DataMemory=10MB
IndexMemory=25MB
MaxNoOfTables=256
MaxNoOfOrderedIndexes=256
MaxNoOfUniqueHashIndexes=128

[MySQLD DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

[NDB_MGMD]
Id=1
HostName=192.168.1.110
DataDir= /var/lib/MySQL-cluster

[NDBD]
Id=2
HostName=192.168.1.110
DataDir= /var/lib/MySQL-cluster

[NDBD]
Id=3
HostName=192.168.1.101
DataDir= /var/lib/MySQL-cluster

[MySQLD]
Id=4
HostName=192.168.1.110
[MySQLD]
Id=5
HostName=192.168.1.101

~
~

sudo /etc/init.d/MySQL-ndb-mgm start然後啟動
sudo /etc/init.d/MySQL-ndb start最後啟動
sudo /etc/init.d/MySQL start

測試:

onmyway@ubuntu:~$ ndb_mgm
-- NDB Cluster -- Management ClIEnt --
ndb_mgm> show
Connected to Management Server at: 192.168.1.110:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.110 (Version: 5.0.75, Nodegroup: 0, Master)
id=3    @192.168.1.101 (Version: 5.0.51, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.110 (Version: 5.0.75)

[MySQLd(API)]   2 node(s)
id=4    @192.168.1.110 (Version: 5.0.75)
id=5    @192.168.1.101 (Version: 5.0.51)

ndb_mgm>

表明成功了!!

測試數據要注意的是在一個服務器上添加了數據庫,在另個一個也要點添加,然後裡面的表就會自動同步了!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved