背景:当我们拥有集群时,需要操作每台服务节点,用到shell脚本自动化去执行某些命令是程序员的第一选择。简单、快捷、方便。
- shell脚本实现,实现去每一台节点去安装python服务依赖的jar包。
cat scp_servicelib.sh
#!/bin/bash
nodes=$(cat ./other_nodes)
for node in $nodes
do
echo $node ":"
ssh username@$node "cd /data/service ; pip install -r requirement.txt -i https://mirrors.aliyun.com/pypi/simple/"
done
exit 0
===============================
cat other_nodes
#服务节点
值得注意的是,当出现cd /../.bashrc:行105: conda: 未找到命令,无需关注,命令其实已经执行了,可以到对应的节点去查看。