【发布时间】:2014-07-18 14:40:42
【问题描述】:
我对此真的很陌生 - 我主要是为了练习。我正在尝试创建一个脚本,该脚本将允许跨多个服务器部署 LEMP,并允许根据服务器 IP 等进行“NFS”配置。基本上,只是一个允许向上扩展并尽可能自动化的脚本。对不起,如果我听起来很无知 - 我很新!
到目前为止,我自动安装 LEMP 对我来说非常简单易行。 SSHkeys 肯定有点乱。一旦我弄清楚我在变量部分做错了什么,我会尽可能多地清理它。本质上,除了 IP 变量之外,所有内容都被添加到 /etc/exports 的新行中。我相信这是因为它是一个局部变量,而我是远程执行的?谢谢!
这是我遇到问题的部分:
for NFS in $(cat nfs.txt)
do
for hostname in $(cat hostname.txt)
do
ssh-keygen -t rsa
ssh root@$NFS mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh root@$NFS 'cat >> .ssh/authorized_keys'
ssh root@$hostname mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh root@$hostname 'cat >> .ssh/authorized_keys'
ssh root@$hostname "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
ssh root@$NFS "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
IP=`ssh root@$hostname ifconfig | grep Bcast | cut -d: -f2 | cut -d" " -f1`
echo $IP > ip.txt
scp ip.txt root@$hostname:ip.txt
IPLOCAL=`cat ip.txt`
ssh root@$NFS 'echo -e "/var/www/html $IPLOCAL(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports'
done
done
这就是我原来的样子
for NFS in $(cat nfs.txt)
do
for hostname in $(cat hostname.txt)
do
ssh-keygen -t rsa
ssh root@$NFS mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh root@$NFS 'cat >> .ssh/authorized_keys'
ssh root@$hostname mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh root@$hostname 'cat >> .ssh/authorized_keys'
ssh root@$hostname "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
ssh root@$NFS "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
IP=`ssh root@$hostname ifconfig | grep Bcast | cut -d: -f2 | cut -d" " -f1`
ssh root@$NFS 'echo -e "/var/www/html $IP(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports'
done
done
【问题讨论】: