2021年1月12日 星期二

Linux 查網路通否

 這裏


netcat

yum install nc

nc -zvw3 192.168.1.10 80

Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.1.10:80.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.


nmap

yum install nmap

nmap 192.168.1.10 -p 80

Starting Nmap 6.40 ( http://nmap.org ) at 2019-03-27 15:42 HKT
Nmap scan report for 192.168.1.10
Host is up (0.00042s latency).
PORT STATE SERVICE
80/tcp open http


telnet

yum install telnet

telnet 192.168.1.10 80

Trying 192.168.1.10…
Connected to 192.168.1.10.
Escape character is ‘^]’.

MySQL NDB Cluster Management 管理

管理 Management

Official document

 

ndb_mgm client commands

shell>ndb_mgm -e show   //直接查看

shell>ndb_mgm //進入terminal client

ndb_mdm>help

ndb_mdm>connect connect-string

ndb_mdm>show

node_id/all start //啟動data node(data node須使用外部 ndbd --nostart 參數啟動,非真正啟動,是等 ndb_mgm的這個命令啟動)
//只對all data nodes 生效

node_id/all stop [-a,-f] //關閉指定的 data or mgm node
-f 強迫關閉,不做完整性檢查。(一般如果會造成cluster錯誤,則stop會失敗)
-a 關閉safety check

all stop //關閉全 data node (只對all data nodes生效)

node_id/all restart [-n,-i,-a,-f]
-i 重新初始,會刪除node 檔案系統。
-n 重啟data node,但是先不連線,直到下start指令
-a 放棄這個node目前的transactions。會遺失資料。
-f 強迫關閉,不做完整性檢查。

node_id/all status //顯示data node資料

node_id/all report report-type   //顯示data node 報告

all report memory usage (Data usage is 23%(93873 32K pages of total 393216)

393216 M/1024/32 K=12G

all report backup status 顯示備份狀況

all report eventlog 顯示 event from event log buffer

quit/exit     //terminates management client

shutdown   //關閉整個cluster

create nodegroup node_id[,node_id]    create a new ndb cluster node group and
          caused data node to join it
          //把某幾個node建立group,統一處理 

drop nodegroup nodegroup_id    drops the ndb cluster node group
         //刪除node group

node_id nodelog debug {on|off}    toggle debug loggin

start backup    開始online backup

abort backup    關閉online backup

安裝位置

mgm node /var/lib/mysql-cluster
mgm node backup /var/lib/mysql-cluster/BACKUP
data node /
sql node /

設定檔位置

data node, sql node 都需要 /etc/my.cnf

mgm node /var/lib/mysql-cluster/config.ini
data node  /etc/my.cnf
sql node /etc/my.cnf

log檔位置

mgm node log/data node log

安裝的位置  /var/lib/mysql-cluster/ndb_1_cluster.log
mgm log:            ndb_1_cluster.log
mgm log:            ndb_1_out.log

data node error log:ndb_3_error.log
data node trace log:ndb_3_trace.log.7

mysql node err log

看 my.cnf裡面設定
通常是 log-error=/var/log/mysqld.log

預設port

ndb_mgmd 預設1186
/var/lib/mysql-cluster/config.ini 設定
[ndb_mgmd]
PortNumber=1186

sql node 預設3306
/etc/my.cnf
[mysqld]
port=3306

data node (ndbd/ndbmtd) 預設動態分配。
可在設定檔設。
[ndbd]
ServerPort=11100

查詢使用哪個port

sudo netstat --listening --numeric --programs | grep '\bLISTEN\b' | grep -E '/ndb|/mysqld'

Adding ndb cluster nodes online

1. edit config.ini, add new ndbd sections corresponding to node.
    如果有多個mgm, 則每個config.ini都要加。
2. restart all mgm server with --reload or --initial
3. restart all data nodes.
4. if you using API node with dynamically allocated IDs, you must restart all API nodes.
5. restart any SQL or API nodes.
6. start new data nodes.
7. 執行 alter table... algorithm=inplace,reorganzie partiton ?? 

Backup and restore

backup

document

ndb_mgm command

1. 須先設定backup configuration document
2. start backup [backup_id][wait option][snapshot option]
        wait shell何時返回。nowait就即時返回。

預設備份檔位置 /var/lib/mysql-cluster/BACKUP

restore 

doucment

ndb_restore [-c connection_string] -n node_id -b backup_id [-m] -r --backup-path=/file

還原單表
ndb_restore [...] --include-databases=db1,db2 --include-tables=db3.t1,db3.t2

整庫還原

1. 進入單使用者模式
    ndb_mgm>enter single user mode
2. ndb_restore -c connetion_string -n 1 -m -r --backup_path=/file
    //第一個restore 需要 -m, 其他不需要

MySQL NDBCluster 與 InnoDB storage engine 差異

 Official document




MySQL 大量資料 insert 加速方式

 這裏


Bulk inserts of data(區塊式 insert)

  • Extended inserts
     一次 insert 多筆

  • Transactions
      把 insert 放到 transaction 裡

Avoid indexes

先 drop index, 等 insert 完成再加回去

Skipping the binary log

暫時關閉 binary log
set sql_log_bin=0;

Multiple connections


Truncate table with foreign keys


Index is used for sort 

搜尋覆蓋