January 2014 Archives

5 Hosts MySQL Cluster

user-pic
Vote 0 Votes

1 Management Server (MGM) 192.168.1.1
2 SQL Nodes (mysqld API) VIP 192.168.1.2, SQL1 IP 192.168.1.3, SQL2 IP 192.168.1.4
2 Data Nodes (NDB) NDB1 IP 192.168.1.5, NDB2 IP 192.168.1.6

共同作業, 所有主機都需裝 MySQL-Cluster-server 及 MySQL-Cluster-client (非必要, 但建議安裝)
wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-Cluster-7.3/MySQL-Cluster-client-gpl-7.3.3-1.el6.x86_64.rpm
wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-Cluster-7.3/MySQL-Cluster-server-gpl-7.3.3-1.el6.x86_64.rpm
rpm -ivh MySQL*.rpm

MGM 設定
mkdir /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
vi config.ini (參考 Initial Configuration of MySQL Cluster)

[ndbd default]
NoOfReplicas=2
DataMemory=1G
IndexMemory=1G

[ndb_mgmd]
hostname=192.168.1.1
datadir=/var/lib/mysql-cluster

[ndbd]
hostname=192.168.1.5
datadir=/usr/local/mysql/data

[ndbd]
hostname=192.168.1.6
datadir=/usr/local/mysql/data

[mysqld]
hostname=192.168.1.3

[mysqld]
hostname=192.168.1.4

設定初始化, config.ini 有異動時執行
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial

啟動 MGM
ndb_mgmd -f /var/lib/mysql-cluster/config.ini

加到 /etc/rc.local 下次開機啟動
echo ndb_mgmd -f /var/lib/mysql-cluster/config.ini >> /etc/rc.local

Data Nodes 及 SQL Nodes 設定
Data Nodes 及 SQL Nodes 的設定均相同, 設定 MGM 的 IP
vi /etc/my.cnf

[mysqld]
ndbcluster

[mysql_cluster]
ndb-connectstring=192.168.1.1

Data Notes 要 mkdir -p /usr/local/mysql/data

啟動 Data Nodes
ndbd

加到 /etc/rc.local 下次開機啟動
echo ndbd >> /etc/rc.local

啟動 SQL Nodes
service mysql start (與一般 MySQL 啟動一樣)

在 MGM 查看狀態
# ndb_mgm -e show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.3 (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3 @192.168.1.4 (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.1 (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)] 2 node(s)
id=4 @192.168.1.5 (mysql-5.6.14 ndb-7.3.3)
id=5 @192.168.1.6 (mysql-5.6.14 ndb-7.3.3)

以上是 MySQL cluster 的部份, 但是這樣有一個問題, 若程式平常是連第1台 SQL Node,
若第一台掛掉了, 就要改程式指向第2台 SQL Node,
若在兩台 SQL Node 跑 keepalived, 起一個 VIP 192.168.1.2, 程式是連 VIP 即可解決此問題
設定可參考 Linux下keepalived+mysql實現高可用

如此任何一台主機掛點都不會影響服務, MGM 是仲裁角色, 避免 Split Brain 狀況,
MGM 雖然只有一台, 但是它掛點並不會影響服務.

任何一台主機都可以關機維護, 若要全部關機重開, 啟動順序是 MGM, Data Nodes (NDB), SQL Nodes (API)

把現有資料轉存到 Data Node
ALTER TABLE tbl_name ENGINE=NDBCLUSTER;

以 ENGINE=NDBCLUSTER 建立 Table 資料才會存到 Data Node
CREATE TABLE tbl_name (col_name column_definitions) ENGINE=NDBCLUSTER;

Symptom:
Drop table shows "Unknown table"
Create table only create tblname.idb, but not tblname.frm, select the tblname shows doesn't exist

Fix procedure:
1. Stop MySQL
  service mysql stop
2. Remove ib_logfile0 and ib_logfile1
  cd /var/lib/mysql
  rm ib_logfile0 ib_logfile1
3. Remove tblname files
  cd /var/lib/mysql/dbname
  rm tblname*
4. Start MySQL
  service mysql start

CSV Tips for Excel

user-pic
Vote 0 Votes

輸出 UTF-8 格式 CSV, 讓 Excel 能正常讀取, 需加 BOM 檔頭
PHP: echo "\xEF\xBB\xBF"
BASH: echo -n $'\xEF\xBB\xBF'
這種方式只有 Excel 2007 會亂碼, 應該是 Exel 2007 本身的問題, 需用這種方式開啟

有換行的資料用 "" 包起來
例:
ABC,"123
456
789"

第一碼為 0 的一串數字, 讓 0 正常顯示
="0123",="0456"

資料中間有 ", 需用 "" 包起來, 兩個 "" 代表一個 ", 若 " 在文字中間, 可以不用包起來, 一個 " 代表一個 "
例:
"""","ABC""123",ABC"123

可以使用 Excel 函式及儲存格代碼
例:
1.61803398,=INT(A1),"=ROUND(A1,2)"

XONE for Android

user-pic
Vote 0 Votes

XONE 每月免費 100 分鐘撥打台灣、中國、香港、美國、加拿大,
手機市話皆可通, 而且帶出去的 Caller ID 是自己的號碼
此 APP 是用手機號碼驗證, 而且會檢查 SIM 卡, 沒有 SIM 卡的設備是不能用的

2014-01-22 Update: 這 App 頗耗電, 還是把它移除了

若 NFS 在 Copy 大檔時常遇到 hang 住, Server 端 /etc/exports 可試試 async 參數
async This option allows the NFS server to violate the NFS protocol and reply to requests before any changes
   made by that request have been committed to stable storage (e.g. disc drive).
   Using this option usually improves performance, but at the cost that an unclean server restart (i.e. a crash)
   can cause data to be lost or corrupted.
Copy 檔案不再卡卡, 且可提升效能, 風險就是 Server 若忽然斷電, 可能會遺失資料

例如:
/nfs 192.168.x.x/24(rw,nohide,insecure,async,no_subtree_check)

ref. [SOLVED] large NFS copy locks up/hang client with large files (again) (lucid) - Page 3

About this Archive

This page is an archive of entries from January 2014 listed from newest to oldest.

November 2013 is the previous archive.

February 2014 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives