天天看點

利用dsh批量啟動同網段MySQL

dsh的安裝可以參考網上的文檔 

但是有幾個地方網上的安裝文檔并不是很詳細

1、編譯安裝的時候需要依賴包

glibc-headers gcc-c++

2、安裝完libdshconfig後

如果是32位系統

ln -s /usr/local/lib/libdshconfig.so.1 /lib/

如果是64位系統

ln -s /usr/local/lib/libdshconfig.so.1 /lib64/

3、控制組的編寫 文中會講到

安裝完dsh之後

dsh --help

-v --verbose                   verbose output

-q --quiet                     quiet

-m --show-machine-names        prepend the host name on output

-h --hide-machine-names        do not prepend host name on output

-i --duplicate-input           duplicate input given to dsh

-b --bufsize                   change buffer size used in input duplication

-m --machine [machinename]     execute on machine

-n --num-topology              how to divide the machines

-a --all                       execute on all machines

-g --group [groupname]         execute on group member

-f --file [file]               use the file as list of machines

-r --remoteshell [shellname]   execute using shell (rsh/ssh)

-o --remoteshellopt [option]   option to give to shell 

-h --help                      give out this message

-w --wait-shell                sequentially execute shell

-c --concurrent-shell          execute shell concurrently

-f --forklimit [fork limit]    concurrent with limit on number

-v --version                   give out version information

如何實作同網段mysql一鍵啟動呢?

首先需要編寫控制的主機清單

在新安裝的dsh是沒有/root/.dsh/*這些檔案的

需要在/usr/local/etc/下建立group檔案

然後在group裡面編寫控制組

執行指令後會産生/root/.dsh/*的檔案

如果mysql的啟動方式是service mysql start的話可以直接

dsh -r ssh -g 控制組檔案名 'service mysql start'

但是如果是 mysqld_safe的方式啟動的話就比較麻煩

需要在各個節點建立一個mysql的啟動腳本

然後可以dsh -r ssh -g 控制組檔案名 'bash 啟動腳本'

但是 mysqld_safe &的話需要人工去敲下回車才能跳到shell裡面

這樣就影響到其他的ip去啟動mysql

是以把mysql啟動的過程隐藏 把啟動腳本改為

mysqld_safe &>/dev/null &

這樣就可以以一鍵啟動同網段内的所有mysql執行個體。

随後可以通過監控檢視一下mysql的啟動詳情

如果沒有 可以選擇easydb