公司英文网站,网站公司缺点,库存管理系统软件,住房和城乡建设部网站防烟排烟1、SSH 工具本身支持多窗口
比如 MobaXterm#xff1a;
2、编写脚本通过 ssh 在多台机器批量执行shell命令
创建 ssh_hosts 配置文件#xff0c;定义需要批量执行的节点#xff08;必须能够通过 ssh 免密登录#xff0c;且存在同名用户#xff09;
vim ssh_hostsbig…1、SSH 工具本身支持多窗口
比如 MobaXterm
2、编写脚本通过 ssh 在多台机器批量执行shell命令
创建 ssh_hosts 配置文件定义需要批量执行的节点必须能够通过 ssh 免密登录且存在同名用户
vim ssh_hostsbigdata0
bigdata1创建 dosshcmd.sh 脚本
vim dosshcmd.sh#! /bin/shdoSshCmd() {hostssed -n /^[^#]/p /home/z/scripts/ssh_hostsfor host in $hostsdo echo \[**************** HOST: $host ****************]ssh $host $echo donereturn 0
}
if [ $# -lt 1 ]
thenecho $0 cmdexit
fi
echo CMD: $
doSshCmd $赋予执行权限
chmod ux dosshcmd.sh3、验证
1) 验证简单命令
[rootbigdata0 scripts]# ./dosshcmd.sh free -g
CMD: free -g
[**************** HOST: bigdata0 ****************]total used free shared buff/cache available
Mem: 93 13 31 0 49 79
Swap: 3 0 3
[**************** HOST: bigdata1 ****************]total used free shared buff/cache available
Mem: 93 15 2 0 75 77
Swap: 3 0 32) 验证脚本执行
编写一个通过 jps 找到 pid然后通过 ps 查看进程信息的简单脚本
vim find_java_resources.sh#! /bin/sh
pidsjps|grep -i $1| cut -d -f 1
echo ----find pids: $pids
for pid in $pids
doecho ----PID: $pid----if [ $# -eq 1 ];then ps -q $pid -aux|awk {print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10}|column -t elseps -q $pid ${:2}|awk {print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10}|column -tfiecho
done赋予执行权限
chmod ux find_java_resources.sh分发
[rootbigdata0 scripts]# scp find_java_resources.sh bigdata1:pwd
find_java_resources.sh 100% 265 0.3KB/s 00:00
[rootbigdata0 scripts]#查看集群每个节点 yarn 任务资源占用
[rootbigdata0 scripts]# ./dosshcmd.sh /home/z/scripts/find_java_resources.sh yarn
CMD: /home/z/scripts/find_java_resources.sh yarn
[**************** HOST: bigdata0 ****************]
----find pids: 31878 31879
----PID: 31878----
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
root 31878 24.7 1.2 26774340 1204428 ? Sl 11:10 2:49 ----PID: 31879----
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
root 31879 25.9 1.2 26743664 1210208 ? Sl 11:10 2:57
[**************** HOST: bigdata1 ****************]
----find pids: 30703
----PID: 30703----
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
root 30703 24.4 2.9 26776844 2854336 ? Sl 11:14 2:48 也可以用 watch 监控
watch ./dosshcmd.sh /home/z/scripts/find_java_resources.sh yarn