时钟同步

在所有节点上同步当前系统时间和日期与NTP(网络时间协议)一致。

  1. yum install ntp
  2. ntpdate pool.ntp.org
  3. date

免密登录

配置hosts

配置hosts文件,主要用于确定每个节点的IP地址,方便后续master节点能快速查询到并访问各个节点

  1. vim /etc/hosts

因为节点的hostname不规范,所以定义别名,添加如下:

  1. 10.132.221.36 kvmcompute6 node01
  2. 10.132.221.37 kvmcompute7 node02
  3. 10.132.221.40 kvmcompute10 node03
  4. 10.132.221.41 kvmcompute11 node04
  5. 10.132.221.43 hadoop01 node05

生成密钥

  1. ssh-keygen -t rsa

然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)

ansible 拷贝密钥

在五台机器分别手动输入命令太过繁琐,采用ansible的方式更为简单

安装ansible

  1. yum install ansible

关闭公钥验证

  1. vim /etc/ansible/ansible.cfg
  2. # ansible.cfg
  3. host_key_checking = False

配置inventory

  1. vim hosts
  2. # 添加如下
  3. [hadoop]
  4. #10.132.221.36 ansible_ssh_user="root" ansible_ssh_pass="123456"
  5. 10.132.221.37 ansible_ssh_user="root" ansible_ssh_pass="123456"
  6. 10.132.221.40 ansible_ssh_user="root" ansible_ssh_pass="123456"
  7. 10.132.221.41 ansible_ssh_user="root" ansible_ssh_pass="123456"
  8. 10.132.221.43 ansible_ssh_user="root" ansible_ssh_pass="123456"

配置脚本

  1. cd /etc/ansible
  2. vim ssh-copy.yml

免密登录yaml文件如下:

  1. # ssh-copy.yml
  2. ---
  3. - hosts: [hadoop]
  4. gather_facts: no
  5. tasks:
  6. - name: install ssh key
  7. authorized_key: user=root
  8. key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
  9. state=present

运行脚本

  1. ansible-playbook -i hosts ssh-copy.yml -vvv

拷贝/etc/hosts

在node01执行

  1. cd /etc/ansible
  2. vim copy-hosts.yml
  1. ---
  2. - hosts: [hadoop]
  3. gather_facts: no
  4. tasks:
  5. - name: copy file /et/hosts
  6. copy:
  7. src: /etc/hosts
  8. dest: /etc

运行:

  1. ansible-playbook -i hosts copy-hosts.yml -vvv

参考

  1. https://github.com/heibaiying/BigData-Notes