VnLamp

Go Back   VnLamp > Khu vực Training > Linux Advance > Mysql Server/Cilent

Trả lời
 
LinkBack Ðiều Chỉnh Xếp Bài
Load Balanced MySQL Cluster
Old
  (#1 (permalink))
 
Status: Offline
Posts: 78
Tham gia: Dec 2007
Open mind Open lives
 
petern's Avatar
Default Load Balanced MySQL Cluster - 21-01-2008, 10:21 21-01-2008

Server:
sql1.com – 10.199.3.36 - MySQL cluster node 1
sql2.com – 10.199.3.37 - MySQL cluster node 2
loaddb1.com – 10.199.3.38 - Load Balancer 1 & MySQL cluster management server
loaddb2.com – 10.199.3.39 - Load Balancer 2
sql.com – 10.199.3.35 - MySQL cluster with Vitural IP

Recommended:
2 MySQL cluster nodes + 1 cluster management server + 2 Load Balancers = 5 servers.

Requirements:
OS: CentOS
Packages: gcc g++ gcc-g++ gdbm gdbm-devel openssl openssl-devel stunnel krb5-devel bzip2 bzip2-devel.

Download gói MySQL mysql-max-5.0.27-linux-i686.tar.gz (42MB)
$ mkdir /var/src/tar
$ wget http://mysql.cdpa.nsysu.edu.tw/Downl...ux-i686.tar.gz

Giải nén.
$ cd /var/src
$ tar -xzf ./tar/mysql-max-5.0.27-linux-i686.tar.gz

Server: loaddb1.com: 10.199.3.38 Load Balancer 1 / MySQL cluster management server
Trước tiên, chúng ta cần cài đặt cluster management server (ndb_mgmd) và cluster management client (ndb_mgm - dùng để theo dõi những gì diễn ra trên hệ thống cluster).

$ cd mysql-max-5.0.27-linux-i686/
$ mv bin/ndb_mgm /usr/bin
$ mv bin/ndb_mgmd /usr/bin
$ chmod 755 /usr/bin/ndb_mg*

Tiếp theo, chúng ta tạo file cấu hình cho hệ thống cluster /var/lib/mysql-cluster/config.ini
$ mkdir /var/lib/mysql-cluster
$ cd /var/lib/mysql-cluster
$ vi config.ini
HTML Code:
[NDBD DEFAULT]
NoOfReplicas=2

[MYSQLD DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

# Section for the cluster management node
[NDB_MGMD]
# IP address of the management node (this system)
HostName=10.199.3.38 #Va IP la 10.199.3.39 voi loaddb2.com

# Section for the storage nodes
[NDBD]
# IP address of the first storage node
HostName=10.199.3.35
DataDir= /var/lib/mysql-cluster

[NDBD]
# IP address of the second storage node
HostName=10.199.3.36
DataDir=/var/lib/mysql-cluster

# one [MYSQLD] per storage node
[MYSQLD]
[MYSQLD]
Sau đó thêm script này vào phần bootup
$ echo 'ndb_mgmd -f /var/lib/mysql-cluster/config.ini' > /etc/init.d/ndb_mgmd
$ chmod 755 /etc/init.d/ndb_mgmd
$ ndb_mgmd -f /var/lib/mysql-cluster/config.ini

Server: sql1.vng.com: 10.199.3.36 MySQL cluster node 1 & sql2.com: 10.199.3.37 MySQL cluster node 2

$ groupadd mysql
$ useradd -g mysql mysql
$ cp -Rf /var/src/mysql-max-5.0.27-linux-i686 /usr/local/mysql
$ cd /usr/local/mysql
$ scripts/mysql_install_db --user=mysql
$ chown -R root:mysql .
$ chown -R mysql data
$ cp support-files/mysql.server /etc/init.d/
$ chmod 755 /etc/init.d/mysql.server
$ chkconfig mysql.server on
$ cd /usr/local/mysql/bin
$ mv * /usr/bin
$ cd ../
$ rm -fr /usr/local/mysql/bin
$ ln -s /usr/bin /usr/local/mysql/bin

Tạo file config cho MySQL:
$ vi /etc/my.cnf
HTML Code:
[mysqld]
ndbcluster
# IP address of the cluster management node
ndb-connectstring=10.199.3.38

[mysql_cluster]
# IP address of the cluster management node
ndb-connectstring=10.199.3.38
$ mkdir /var/lib/mysql-cluster
$ cd /var/lib/mysql-cluster
$ ndbd --initial
$ /etc/init.d/mysql.server start

$ echo 'ndbd' > /etc/init.d/ndbd
$ chmod 755 /etc/init.d/ndbd
$ mysqladmin -u root password passwordroot
$ ndbd

Load Balancers with Ultra Monkey

Lưu ý là cả 2 server loaddb1.com và db2.com phải hỗ trợ PVS (IP Virtual Server) trong kernels. IPVS implements transport-layer load balancing inside the Linux kernel.

Chúng ta bắt đầu bằng việc kích họat IPVS
$ modprobe ip_vs_dh ;\
modprobe ip_vs_ftp ;\
modprobe ip_vs ;\
modprobe ip_vs_lblc ;\
modprobe ip_vs_lblcr ;\
modprobe ip_vs_lc ;\
modprobe ip_vs_nq ;\
modprobe ip_vs_rr ;\
modprobe ip_vs_sed ;\
modprobe ip_vs_sh ;\
modprobe ip_vs_wlc ;\
modprobe ip_vs_wrr

Để kích họat trong lúc bootup ta phải sửa và thêm trong /etc/modules

$ vi /etc/modules
ip_vs_dh
ip_vs_ftp
ip_vs
ip_vs_lblc
ip_vs_lblcr
ip_vs_lc
ip_vs_nq
ip_vs_rr
ip_vs_sed
ip_vs_sh
ip_vs_wlc
ip_vs_wrr

Tiếp đến chúng ta cài đặt một số gói phần mềm cần cho việc cài đặt.
$yum install libdbi-dbd-mysql.i386 libdbi.i386 libdbi-devel.i386 mysqlclient10 curl libidn perl-Crypt-SSLeay.i386 perl-Digest-HMAC.i386 perl-HTML-Parser.i386 perl-Net-DNS.i386 perl-XML-Parser.i386 perl-libwww-perl.i386 perl-DBI.i386 perl-DBI.i386 perl-CGI.i386 perl-DBD-MySQL.i386 heartbeat mysqlclient10-devel.i386 heartbeat-ldirectord.i386 heartbeat-ldirectord-1.2.3.cvs.20050927-1.centos4.i386 ipvsadm.i386

Kiểm trả các gói sau, nếu chưa có thì download:

$ cd /var/src
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/....um.1.i386.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm

Cài đặt:

$ rpm –Uvh /var/src/*.rpm
The libdbd-mysql-perl package we've just installed does not work with MySQL 5 (we use MySQL 5 on our MySQL cluster...), so we install the newest DBD::mysql Perl package:
$ cd /tmp
$ wget http://www.archive.hk/cpan/authors/i...-3.0002.tar.gz
$ tar xvfz DBD-mysql-3.0002.tar.gz
$ cd DBD-mysql-3.0002
$ perl Makefile.PL
$ make
$ make install

We must enable packet forwarding:

$vi /etc/sysctl.conf

# Enables packet forwarding
net.ipv4.ip_forward = 1

$ sysctl -p
Configure heartbeat

$ vi /etc/ha.d/ha.cf

logfacility local0
bcast eth0
mcast eth0 225.0.0.1 694 1 0
auto_failback off
node loaddb1
node loaddb2
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster

$ vi /etc/ha.d/haresources

loaddb1 \ #or loaddb2
ldirectord::ldirectord.cf \
LVSSyncDaemonSwap::master \
IPaddr2::10.199.3.35/24/eth0/10.199.3.255

$ vi /etc/ha.d/authkeys

auth 3
3 md5 shitkuku

$ chmod 600 /etc/ha.d/authkeys


Configure ldirectord

$ vi /etc/ha.d/ldirectord.cf

# Global Directives
checktimeout=10
checkinterval=2
autoreload=no
logfile="local0"
quiescent=yes

virtual = 10.199.3.35:3306
service = mysql
real = 10.199.3.36:3306 gate
real = 10.199.3.37:3306 gate
checktype = negotiate
login = "ldirector"
passwd = "ldirectorpassword"
database = "ldirectordb"
request = "SELECT * FROM connectioncheck"
scheduler = wrr

$ chkconfig heartbeat on
$ chkconfig ldirectord off
$ chmod 755 /etc/init.d/heartbeat

Create A Database Called ldirector

Chúng ta tạo user với quyền đây đủ cho ldirectord trên sql1.com:
$ mysql -u root -p
mysql> GRANT ALL ON ldirectordb.* TO 'ldirector'@'%' IDENTIFIED BY 'ldirectorpassword';
mysql> FLUSH PRIVILEGES;
mysql> CREATE DATABASE ldirectordb;
mysql> USE ldirectordb;
mysql> CREATE TABLE connectioncheck (i INT) ENGINE=NDBCLUSTER;
mysql> INSERT INTO connectioncheck () VALUES (1);
quit;

Và trên sql2.com
mysql -u root -p
mysql> GRANT ALL ON ldirectordb.* TO 'ldirector'@'%' IDENTIFIED BY 'ldirectorpassword';
mysql> FLUSH PRIVILEGES;
mysql> CREATE DATABASE ldirectordb;
mysql> quit;

$ /etc/init.d/ldirectord stop
$ /etc/init.d/heartbeat start

Cài đặt LVS cho sql1.com và sql2.com

$ vi /etc/sysctl.conf

# When an arp request is received on eth0, only respond if that address is
# configured on eth0. In particular, do not respond if the address is
# configured on lo
net.ipv4.conf.eth0.arp_ignore = 1

# Ditto for eth1, add for all ARPing interfaces
#net.ipv4.conf.eth1.arp_ignore = 1


# Enable configuration of arp_announce option
net.ipv4.conf.all.arp_announce = 2

# When making an ARP request sent through eth0 Always use an address that
# is configured on eth0 as the source address of the ARP request. If this
# is not set, and packets are being sent out eth0 for an address that is on
# lo, and an arp request is required, then the address on lo will be used.
# As the source IP address of arp requests is entered into the ARP cache on
# the destination, it has the effect of announcing this address. This is
# not desirable in this case as adresses on lo on the real-servers should
# be announced only by the linux-director.
net.ipv4.conf.eth0.arp_announce = 2

# Ditto for eth1, add for all ARPing interfaces
#net.ipv4.conf.eth1.arp_announce = 2

$ cd /var/src
$ wget http://www.ultramonkey.org/download/...m.1.noarch.rpm
$ rpm -Uvh arptables-noarp-addr-0.99.2-1.rh.el.um.1.noarch.rpm

$ arptables-noarp-addr 10.199.3.35 start
$ /etc/init.d/arptables_jf save
$ chkconfig --level 2345 arptables_jf on
$ /etc/init.d/arptables_jf start

$ vi /etc/sysconfig/network-scripts/ifcfg-lo:0

DEVICE=lo:0
IPADDR=10.199.3.35
NETMASK=255.255.255.255
NETWORK=10.199.3.0
BROADCAST=10.199.3.255
ONBOOT=yes
NAME=loopback
$ ifup lo:0


All done. Good luck! ^^
   
Trả Lời Với Trích Dẫn
Old
  (#2 (permalink))
 
Status: Offline
Posts: 29
Tham gia: Dec 2007
Member
Default 14-04-2008, 17:14 14-04-2008

Anh ơi, cho em xin cai sơ đồ của hệ thống này đi. Nhìn sơ đồ là phần nào hiểu mô hình rùi.
   
Trả Lời Với Trích Dẫn
Old
  (#3 (permalink))
 
Status: Offline
Posts: 78
Tham gia: Dec 2007
Open mind Open lives
 
petern's Avatar
Default 15-04-2008, 08:15 15-04-2008

Xem tạm cái mô hình này nhé, có gì không hiểu sẽ giải thích thêm



Microsoft just gives you a windows
Linux gives you the whole house
   
Trả Lời Với Trích Dẫn
Old
  (#4 (permalink))
 
Status: Offline
Posts: 5
Tham gia: Jan 2008
Học viên VNLAMP
Default 30-07-2008, 17:30 30-07-2008

Sao lúc này kiếm cái bản Max không ra vậy bác. Nó có thay bằng tên khác không?
   
Trả Lời Với Trích Dẫn
Old
  (#5 (permalink))
 
Status: Offline
Posts: 368
Tham gia: Dec 2007
Member
 
atula's Avatar
Default 30-07-2008, 18:30 30-07-2008

Hi bạn.
Có thể phiên bản mới đã đổi tên.Bạn có thể vào đây để tham khảo:
http://dev.mysql.com/downloads/cluster/index.html


Imagination is more important than knowledge…
MY BLOG http://atuladn.spaces.live.com/default.aspx
  Send a message via Yahoo to atula  
Trả Lời Với Trích Dẫn
Old
  (#6 (permalink))
 
Status: Offline
Posts: 368
Tham gia: Dec 2007
Member
 
atula's Avatar
Default 30-07-2008, 19:30 30-07-2008

Beginning with MySQL 5.1.24, standard MySQL server binaries built by MySQL no longer provide support for the NDBCLUSTER storage engine. Instead, MySQL Cluster users should upgrade to MySQL Cluster NDB 6.2.15 (or a later MySQL Cluster release) which includes binary releases for supported platforms, including RPMs that should work with most Linux distributions. MySQL Cluster users who build from source should be aware that, also beginning with MySQL 5.1.24, NDBCLUSTER sources in the standard MySQL 5.1 tree are no longer maintained; these users should upgrade using the MySQL Cluster NDB 6.2.15 (or later) source release.


Imagination is more important than knowledge…
MY BLOG http://atuladn.spaces.live.com/default.aspx
  Send a message via Yahoo to atula  
Trả Lời Với Trích Dẫn
Old
  (#7 (permalink))
 
Status: Offline
Posts: 43
Tham gia: Jun 2008
Học viên VNLAMP
Default 31-07-2008, 13:31 31-07-2008

petern viết bài hay lắm
   
Trả Lời Với Trích Dẫn
Old
  (#8 (permalink))
 
Status: Offline
Posts: 23
Tham gia: Aug 2008
Học viên VNLAMP
Default 27-08-2008, 12:27 27-08-2008

Trích:
Nguyên văn bởi atula View Post
Beginning with MySQL 5.1.24, standard MySQL server binaries built by MySQL no longer provide support for the NDBCLUSTER storage engine. Instead, MySQL Cluster users should upgrade to MySQL Cluster NDB 6.2.15 (or a later MySQL Cluster release) which includes binary releases for supported platforms, including RPMs that should work with most Linux distributions. MySQL Cluster users who build from source should be aware that, also beginning with MySQL 5.1.24, NDBCLUSTER sources in the standard MySQL 5.1 tree are no longer maintained; these users should upgrade using the MySQL Cluster NDB 6.2.15 (or later) source release.
Anh em có ai đã cài Mysql Cluster 6 chưa vậy? Chia sẻ kinh nghiệm với nhau hen!
   
Trả Lời Với Trích Dẫn
Old
  (#9 (permalink))
 
Status: Offline
Posts: 23
Tham gia: Aug 2008
Học viên VNLAMP
Default 07-09-2008, 20:7 07-09-2008

Trích:
Nguyên văn bởi chaudn View Post
Anh em có ai đã cài Mysql Cluster 6 chưa vậy? Chia sẻ kinh nghiệm với nhau hen!
Bản 6 cài tương tự như bản trên.

Có link này cho bản trên cho anh em tham khảo:
http://www.severalnines.com.space2u.com/config/

Lưu ý: đừng dùng cấu hình của site trên,chỉ coi script tham khảo thôi.
   
Trả Lời Với Trích Dẫn
Old
  (#10 (permalink))
 
Status: Offline
Posts: 23
Tham gia: Aug 2008
Học viên VNLAMP
Default 13-09-2008, 14:13 13-09-2008

Hiện tại database chạy từ mysql server stand alone thì có thể đổ qua mysql cluster chạy được không anh em? Hay cần chỉnh thêm thông số gì?
   
Trả Lời Với Trích Dẫn
Trả lời


Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt
Trackbacks are Mở
Pingbacks are Mở
Refbacks are Mở


Múi giờ GMT. Hiện tại là 02:23 23-05-2012.