时钟同步
在所有节点上同步当前系统时间和日期与NTP(网络时间协议)一致。
yum install ntpntpdate pool.ntp.orgdate
免密登录
配置hosts
配置hosts文件,主要用于确定每个节点的IP地址,方便后续master节点能快速查询到并访问各个节点
vim /etc/hosts
因为节点的hostname不规范,所以定义别名,添加如下:
10.132.221.36 kvmcompute6 node0110.132.221.37 kvmcompute7 node0210.132.221.40 kvmcompute10 node0310.132.221.41 kvmcompute11 node0410.132.221.43 hadoop01 node05
生成密钥
ssh-keygen -t rsa
然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
ansible 拷贝密钥
在五台机器分别手动输入命令太过繁琐,采用ansible的方式更为简单
安装ansible
yum install ansible
关闭公钥验证
vim /etc/ansible/ansible.cfg# ansible.cfghost_key_checking = False
配置inventory
vim hosts# 添加如下[hadoop]#10.132.221.36 ansible_ssh_user="root" ansible_ssh_pass="123456"10.132.221.37 ansible_ssh_user="root" ansible_ssh_pass="123456"10.132.221.40 ansible_ssh_user="root" ansible_ssh_pass="123456"10.132.221.41 ansible_ssh_user="root" ansible_ssh_pass="123456"10.132.221.43 ansible_ssh_user="root" ansible_ssh_pass="123456"
配置脚本
cd /etc/ansiblevim ssh-copy.yml
免密登录yaml文件如下:
# ssh-copy.yml---- hosts: [hadoop]gather_facts: notasks:- name: install ssh keyauthorized_key: user=rootkey="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"state=present
运行脚本
ansible-playbook -i hosts ssh-copy.yml -vvv
拷贝/etc/hosts
在node01执行
cd /etc/ansiblevim copy-hosts.yml
---- hosts: [hadoop]gather_facts: notasks:- name: copy file /et/hostscopy:src: /etc/hostsdest: /etc
运行:
ansible-playbook -i hosts copy-hosts.yml -vvv
