天天看点

利用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