博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
写几个Hadoop部署用到的小脚本
阅读量:7114 次
发布时间:2019-06-28

本文共 1166 字,大约阅读时间需要 3 分钟。

最近抛弃非ssh连接的hadoop集群部署方式了,还是回到了用ssh key 验证的方式上了。这里面就有些麻烦,每台机器都要上传公钥。恰恰我又是个很懒的人,所以写几个小脚本完成,只要在一台机器上面就可以做公钥的分发了。

首先是生成ssh key脚本

#!/bin/shssh-keygen -t rsa -P '' -f ~/.ssh/id_rsacp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

ssh-keygen一般来说需要输入passphrase,但是一般都是三个回车过去了,我懒的输入,加上-P ''就不用了。

然后是添加公钥到从节点的脚本

#!/bin/shread -p "输入远端服务器IP: " ipssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa.pub root@$ipssh root@$ip 'sed -i "s/^#RSAAuthentication\ yes/RSAAuthentication\ yes/g" /etc/ssh/sshd_config'ssh root@$ip 'sed -i "s/^#PubkeyAuthentication\ yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config'ssh root@$ip 'sed -i "s/^#PermitRootLogin\ yes/PermitRootLogin\ yes/g" /etc/ssh/sshd_config'ssh root@$ip 'service sshd restart'hostname=`ssh root@${ip} 'hostname'`echo "添加主机名和IP到本地/etc/hosts文件中"echo "$ip    $hostname" >> /etc/hostsecho "远端主机主机名称为$hostname, 请查看 /etc/hosts 确保该主机名和IP添加到主机列表文件中"echo "主机公钥复制完成"

然后是第三个脚本读取主机列表然后把/etc/hosts复制到所有主机上

#!/bin/shcat /etc/hosts | while read LINEdo    ip=`echo $LINE | awk '{print $1}' | grep -v "::" | grep -v "127.0.0.1"`    echo "Copying /etc/hosts to ${ip}"    scp -o StrictHostKeyChecking=no /etc/hosts root@${ip}:/etc/done

不解释了

转载地址:http://kwghl.baihongyu.com/

你可能感兴趣的文章
PHP课程总结20161111
查看>>
linux环境下搭建W12Scan:一款功能强大的网络安全资产扫描引擎
查看>>
SylixOS PCI BAR寄存器
查看>>
SharedPreferences.Editor 的apply()与commit()方法的区别
查看>>
php基础语法
查看>>
Synchronized及其实现原理
查看>>
GitLab 使用git push 出现RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
查看>>
计算机编程从入门到精通,如何才能快速入门
查看>>
Rsync小规模备份
查看>>
shell编程
查看>>
Linux 增强
查看>>
Android 字符串使用switch
查看>>
入门一班 20180918 find 文件后缀名
查看>>
Java虚拟机系列之Java内存结构简介
查看>>
MongoDB复制集
查看>>
「数据治理那点事」系列之三:不忘初心方得始终,数据质量管理要稳住!
查看>>
Python2 升级 Python3
查看>>
自己写博客的第一天
查看>>
解锁普惠AI开发,华为云ModelArts一站式AI开发平台
查看>>
How to monitor Linux UDP buffer available space?
查看>>